From 5b9cd1ad57f50957efbdcc7b5af19430f4230016 Mon Sep 17 00:00:00 2001 From: Stoiko Ivanov Date: Thu, 23 May 2019 23:11:34 +0200 Subject: [PATCH] zfsutils-linux: persist hostid in postinst script /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 --- 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# +