Re: What exactly is hostid used for?

From: Graham Perrin <grahamperrin_at_freebsd.org>
Date: Sun, 20 Nov 2022 12:31:59 UTC
On 20/11/2022 02:20, iio7@tutanota.com wrote:
> I have been trying to get some clear information about
> what hostid is used for.
>
> In /etc/default/rc.conf it says:
>
> hostid_enable="YES"             # Set host UUID.
>
> But the man page doesn't document this, and the information
> found around the net is rather sparse.
>
> 1. What is it used for?
> 2. Can you safely disable it?
> 3. What relation does it have to ZFS?
>
> Kind regards.

<https://github.com/freebsd/freebsd-src/commit/d5ec19ea683cd13c5ff97c0c4b428cc4dd7529c6> 
(2007-04-09):

> Add rc.d/hostid script (turned on by default) which on first boot 
> generates UUID and stores it in /etc/hostid ($hostid_file) as well as 
> sets kern.hostuuid and kern.hostid sysctls on every boot. …

So, for example:

% grep hostid /etc/rc.conf
% sysrc hostid_enable
hostid_enable: YES
% sysctl kern.hostid
kern.hostid: ⋯not disclosed here⋯
%

– it's enabled, without being specified in rc.conf(5).

Related code:

<https://github.com/freebsd/freebsd-src/blob/main/libexec/rc/rc.d/hostid>

If there's not a special reason to disable, I should leave it enabled.

For example, mount_nfs(8) 
<https://www.freebsd.org/cgi/man.cgi?query=mount_nfs&sektion=8&manpath=FreeBSD+14.0-current> 
for FreeBSD 14.0-CURRENT includes the following caution:

> … Make sure that all your NFS Version 4 clients have unique values in 
> /etc/hostid. …
>

You /might/ find hostid in contexts such as this:

zdb -CU /boot/zfs/zpool.cache | grep hostid

However: looking at the date of this cache file, on my (14.0-CURRENT) 
system, and its contents, I suspect that it's redundant. It contains the 
name of a boot pool that's long gone, and not the name of my current 
boot pool.

strings /boot/zfs/zpool.cache

Maybe related:

<https://github.com/openzfs/zfs/commit/c93d9dff36470434a3677225b820c14986075706>