diff --git a/cmd/zgenhostid/zgenhostid.c b/cmd/zgenhostid/zgenhostid.c index 562262928c77..50fcf05e420c 100644 --- a/cmd/zgenhostid/zgenhostid.c +++ b/cmd/zgenhostid/zgenhostid.c @@ -47,10 +47,10 @@ usage(void) " -h\t\t print this usage and exit\n" " -o \t write hostid to this file\n\n" "If hostid file is not present, store a hostid in it.\n" - "The optional value must be an 8-digit hex number between" - "1 and 2^32-1.\n" - "If no value is provided, a random one will" - "be generated.\n" + "The optional value should be an 8-digit hex number between" + " 1 and 2^32-1.\n" + "If the value is 0 or no value is provided, a random one" + " will be generated.\n" "The value must be unique among your systems.\n"); exit(EXIT_FAILURE); /* NOTREACHED */ @@ -108,7 +108,7 @@ main(int argc, char **argv) exit(EXIT_FAILURE); } - if (input_i < 0x1 || input_i > UINT32_MAX) { + if (input_i > UINT32_MAX) { fprintf(stderr, "%s\n", strerror(ERANGE)); usage(); } diff --git a/contrib/dracut/90zfs/module-setup.sh.in b/contrib/dracut/90zfs/module-setup.sh.in index db5670cd5253..42afda60278c 100755 --- a/contrib/dracut/90zfs/module-setup.sh.in +++ b/contrib/dracut/90zfs/module-setup.sh.in @@ -85,7 +85,13 @@ install() { fi # Synchronize initramfs and system hostid - zgenhostid -o "${initdir}/etc/hostid" "$(hostid)" + if [ -f @sysconfdir@/hostid ]; then + inst @sysconfdir@/hostid + type mark_hostonly >/dev/null 2>&1 && mark_hostonly @sysconfdir@/hostid + elif HOSTID="$(hostid 2>/dev/null)" && [ "${HOSTID}" != "00000000" ]; then + zgenhostid -o "${initdir}@sysconfdir@/hostid" "${HOSTID}" + type mark_hostonly >/dev/null 2>&1 && mark_hostonly @sysconfdir@/hostid + fi if dracut_module_included "systemd"; then mkdir -p "${initdir}/$systemdsystemunitdir/zfs-import.target.wants" diff --git a/man/man8/zgenhostid.8 b/man/man8/zgenhostid.8 index ff198443dd2a..14264cb8cdc3 100644 --- a/man/man8/zgenhostid.8 +++ b/man/man8/zgenhostid.8 @@ -54,7 +54,8 @@ instead of default .It Ar hostid Specifies the value to be placed in .Pa /etc/hostid . -It must be a number with a value between 1 and 2^32-1. +It should be a number with a value between 1 and 2^32-1. +If it is 0, zgenhostid will generate a random hostid. This value .Sy must be unique among your systems.