]> git.proxmox.com Git - zfsonlinux.git/commitdiff
zfsutils-linux: persist hostid in postinst script
authorStoiko Ivanov <s.ivanov@proxmox.com>
Thu, 23 May 2019 21:11:34 +0000 (23:11 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Fri, 24 May 2019 09:44:34 +0000 (11:44 +0200)
/etc/hostid does not exist on a minimal debian system.
ZFS reads its contents for MMP (zpool property multihost set to on), and needs
the value to be stable.
Before the SPL->ZFS merge the spl userspace package wrote the file (by parsing/
mangling the output of hostid (1)) Since ZFS provides the zgenhostid script,
which creates a random 4 byte hostid and writes it to /etc/hostid, we use that
instead. (hostid (1) default to mangling a configured ip of the system, which
can be the same across multiple installs (install happens with the same ip)

Signed-off-by: Stoiko Ivanov <s.ivanov@proxmox.com>
zfs/debian/zfsutils-linux.postinst [new file with mode: 0644]

diff --git a/zfs/debian/zfsutils-linux.postinst b/zfs/debian/zfsutils-linux.postinst
new file mode 100644 (file)
index 0000000..df78321
--- /dev/null
@@ -0,0 +1,19 @@
+#!/bin/sh
+set -e
+# The hostname and hostid of the last system to access a ZFS pool are stored in
+# the ZFS pool itself. A pool is foreign if, during `zpool import`, the
+# current hostname and hostid are different than the stored values thereof.
+#
+# The only way of having a stable hostid is to define it in /etc/hostid.
+# This postinst helper will check if we already have the hostid stabilized by
+# checking the existence of the file /etc/hostid to be 4 bytes at least.
+# If this file don't already exists on our system or has less than 4 bytes, then
+# a new (random) value is generated with zgenhostid (8) and stored in
+# /etc/hostid
+
+if [ ! -f /etc/hostid ] || [ "$(stat -c %s /etc/hostid)" -lt 4 ] ; then
+       zgenhostid
+fi
+
+#DEBHELPER#
+