[pve-devel] [PATCH zfsonlinux 07/15] zfsutils-linux: persist hostid in postinst script
Stoiko Ivanov
s.ivanov at proxmox.com
Thu May 23 23:11:34 CEST 2019
/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 at proxmox.com>
---
zfs/debian/zfsutils-linux.postinst | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
create mode 100644 zfs/debian/zfsutils-linux.postinst
diff --git a/zfs/debian/zfsutils-linux.postinst b/zfs/debian/zfsutils-linux.postinst
new file mode 100644
index 0000000..df78321
--- /dev/null
+++ b/zfs/debian/zfsutils-linux.postinst
@@ -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#
+
--
2.11.0
More information about the pve-devel
mailing list