Skip to content
This repository has been archived by the owner on Feb 26, 2020. It is now read-only.

Commit

Permalink
Stabilize the hostid for RPM installations.
Browse files Browse the repository at this point in the history
ZFS requires a stable hostid to recognize foreign pool imports,
but the hostid of a Linux system can change if the /etc/hostid
file is missing, particularly during DHCP lease updates.

Ensure that the system hostid is stable by creating the
/etc/hostid file from the output of the /usr/bin/hostid utility.
The /sbin/genhostid utility that is provided by the initscripts
package is not used because it creates a random hostid, which
breaks upgrades on systems that already have the SPL module
installed.

The external `printf` is used because the dash builtin lacks
the byte format.  Conveniences like a ${HOSTID:$ii:2} substring
range or a `sed` one-liner are similarly avoided.
  • Loading branch information
dajhorn authored and behlendorf committed Jun 24, 2011
1 parent 0d54dcb commit 79593b0
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions spl-modules.spec.in
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,17 @@ rm -rf $RPM_BUILD_ROOT
%{_prefix}/src/*

%post
# The /sbin/genhostid utility writes a random value to the /etc/hostid
# file, which means that using it here will break upgrades on systems
# that already have spl installed.
if [ ! -f /etc/hostid ]; then
HOSTID=$(hostid)
AA=$(echo $HOSTID | cut -b 1,2)
BB=$(echo $HOSTID | cut -b 3,4)
CC=$(echo $HOSTID | cut -b 5,6)
DD=$(echo $HOSTID | cut -b 7,8)
"$(which printf)" "\x$DD\x$CC\x$BB\x$AA" >"/etc/hostid"
fi
if [ -f /boot/System.map-%{kver} ]; then
depmod -ae -F /boot/System.map-%{kver} %{kver} || exit 0
else
Expand Down

0 comments on commit 79593b0

Please sign in to comment.