Skip to content

Conversation

@zdykstra
Copy link
Member

@zdykstra zdykstra commented Feb 23, 2021

A persistent problem with ZFS and now with ZFSBootMenu is getting spl.spl_hostid lined up on all pool imports. The contents of an initramfs and the kernel command line can influence this value, making it difficult to determine exactly where and how to change it to get a system to boot.

To help combat this recurring issue, ZBM now accepts the following options to control importing behavior.

  • zbm.import_policy=strict: If no pools can be imported with the hostid embedded in the initramfs, or set via spl_hostid on the ZBM command line, drop to a recovery shell.
  • zbm.import_policy=hostid: If no pools can be imported with the hostid embedded in the initramfs, or set via spl_hostid on the ZBM command line, attempt to scrape the hostid used to import the pool defined in root=zfsbootmenu:POOL=<value> and import the pool. If that pool is missing or can't be imported, any other available pool is scraped for a hostid and attempted to be imported.
  • zbm.import_policy=force: YOLO mode, just force import a pool. Replaces `zbm.force_import'.

Right now, when undefined, zbm.import_policy is set to strict.

With this option available, ZBM can now in most cases import any pool - regardless of the hostid of the system that built the initramfs or the EFI executable.

Next is to ensure that the boot environment imports the pool correctly. Some ZFS initramfs modules can use spl_hostid to write out /etc/hostid in the initramfs before loading SPL/ZFS modules. Others ... like Arch ... not only do not by default include /etc/hostid in the initramfs, they do not have any methods to line up spl_hostid on the kernel command line with /etc/hostid. However, spl.spl_hostid takes precedence over /etc/hostid, so we can simply set this on the kernel command line. To this end, we now:

  • Suppress spl_hostid if it's part of the discovered command line for a boot environment
  • Suppress spl.spl_hostid if it's part of the discovered command line for a boot environment
  • Insert spl.spl_hostid=0x<hostid> on the command line for each boot environment.

Since we know the hostid used to import a pool - either discovered in zfsbootmenu-parse-commandline.sh, or discovered when zbm.import_policy=hostid is set. Suppression / rewriting can be disabled via zbm.set_hostid=0 when booting ZBM.

I'm unsure if we should default this behavior to on, or make it opt-in initially for people installing ZBM from master or Void packages. When building binary releases, zbm.import_policy=hostid and zbm.set_hostid=1 should be set, to be maximally usable for people randomly downloading it to test.

zdykstra and others added 28 commits February 22, 2021 13:31
Copy link
Member

@ahesford ahesford left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good solution to a long-standing problem. When we distribute a UEFI bundle, it should set zbm.import_policy=hostid and not disable zbm.set_hostid. We can advise people who use prebuilt initramfs/kernel combinations to set these by whatever means they use.

@zdykstra zdykstra merged commit 951111e into master Feb 26, 2021
@zdykstra zdykstra deleted the align-hostid.sh branch February 26, 2021 16:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants