zfs
zfs copied to clipboard
Initramfs zfs script error when pool previously imported
Describe the problem you're observing
When you run zfs with initramfs and have a previous script import the pool, in my case to unlock it with a custom method to get the key, initramfs will drop you in a shell as the the zfs mountscripts doens't doesnt update POOL_IMPORTED
Describe how to reproduce the problem
Have a scripts in initramfs that call import on the root pool, before or during local.premount
zpool import -N rpool
Problem seem to happen here: https://github.com/openzfs/zfs/blob/04bae5ec95f7273105237159a882d5b72ec2b998/contrib/initramfs/scripts/zfs#L197C1-L198C1
"${ZPOOL}" get -H -o value name,guid 2>/dev/null | grep -Fxq "$pool" && return 0
Where it knows pool is imported but return without setting POOL_IMPORTED and then it goes to find the find_rootfs and errors out.
Would suggest something along the lines of:
if "${ZPOOL}" get -H -o value name,guid 2>/dev/null | grep -Fxq "$pool"; then
POOL_IMPORTED=1
return 0
fi