Skip to content

Commit

Permalink
Set a hostname in ZBM, check if spl.spl_hostid matches /etc/hostid
Browse files Browse the repository at this point in the history
Set a hostname in ZFSBootMenu so that read-write pool imports reflect that we were the last host to import the pool.

If spl.spl_hostid is non-zero, compare the value to what is recorded in /etc/hostid. If they're different generate-zbm will print a warning but take no action.
  • Loading branch information
zdykstra committed Apr 10, 2021
1 parent 98f3164 commit 64bd359
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
3 changes: 3 additions & 0 deletions 90zfsbootmenu/zfsbootmenu-exec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ EOF

getcmdline > "${BASE}/zbm.cmdline"

# Set a non-empty hostname so we show up in zpool history correctly
echo "ZFSBootMenu" > /proc/sys/kernel/hostname

modprobe zfs 2>/dev/null
udevadm settle

Expand Down
26 changes: 26 additions & 0 deletions bin/generate-zbm
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,32 @@ unless ( nonempty $runConf{kernel_prefix} and nonempty $runConf{kernel_version}

printf "Creating ZFSBootMenu %s from kernel %s\n", $runConf{version}, $runConf{kernel};

my $spl_hostid = "/sys/module/spl/parameters/spl_hostid";
if ( -f $spl_hostid ) {
open PROC, $spl_hostid;
$runConf{hostid}{module} = sprintf("%08x", <PROC>);
close PROC;
}

my $etc_hostid = "/etc/hostid";
if ( $runConf{hostid}{module} ne 0 and -f $etc_hostid ) {
open SPL, '<:raw', $etc_hostid;
read SPL, my $hostid, 4;
close SPL;

if ( unpack( 'c', pack( 's', 1 ) ) eq 1 ) {
# little endian
$runConf{hostid}{etc} = sprintf("%08x", unpack('L<4', $hostid));
} else {
# big endian
$runConf{hostid}{etc} = sprintf("%08x", unpack('L>4', $hostid));
}

if ($runConf{hostid}{module} ne $runConf{hostid}{etc}) {
print "SPL ($runConf{hostid}{module}) and system ($runConf{hostid}{etc}) hostids do not match!\n";
}
}

# Create a unified kernel/initramfs/command line EFI file
if ( enabled $config{EFI} ) {
my $unified_efi = createInitramfs( $tempdir, $runConf{kernel_version}, $runConf{kernel} );
Expand Down

0 comments on commit 64bd359

Please sign in to comment.