#1033321 initramfs-tools-core: fsck.zfs missing from initrd when root filesystem on ZFS

#1033321#5
Date:
2023-03-22 13:57:20 UTC
From:
To:
With a root filesystem on ZFS then mkinitramfs builds an initrd that
lacks fsck.zfs:

	testaroli# mkinitramfs -o /boot/initrd.img-$(uname -r)
	W: Couldn't identify type of root file system for fsck hook
	testaroli# zstdcat /boot/initrd.img-$(uname -r) | cpio -itv | grep fsck
	381518 blocks
	testaroli#

I'm sure this patch will break more than it fixes, but at least it
worked for me and writing it here may help others in the short-term:

I edited /usr/share/initramfs-tools/hooks/fsck, located the code block:

	...
	if [ "${MNT_DIR}" = "/" ] || [ "${MNT_TYPE}" = "auto" ]; then
	    MNT_FSNAME="$(resolve_device "${MNT_FSNAME}")"
	    fstype() { "/usr/lib/klibc/bin/fstype" "$@"; }
	    if ! get_fstype "${MNT_FSNAME}"; then
	        echo "W: Couldn't identify type of $2 file system for fsck hook" >&2
	    fi
	    unset -f fstype
	else
	    ...

and replaced it with:

	...
	if [ "${MNT_DIR}" = "/" ] || [ "${MNT_TYPE}" = "auto" ]; then
	    mount | sed -rn "s@.* on $MNT_DIR type ([^ ]+) \\(.*@\\1@p"
	else
	    ...

(I.e. the body of the 'then' clause is replaced.)

After which rerunning the above test produced:

	testaroli# mkinitramfs -o /boot/initrd.img-$(uname -r)
	testaroli# zstdcat /boot/initrd.img-$(uname -r) | cpio -itv | grep fsck
	-rwxr-xr-x   1 root     root        55664 Feb 13 03:48 usr/sbin/fsck
	-rwxr-xr-x   1 root     root          762 Feb 25 23:32 usr/sbin/fsck.zfs
	381657 blocks
	testaroli#

This might actually be *two* bugs in
two different packages (initramfs-tools-core because
/usr/share/initramfs-tools/hooks/fsck produces an ugly warning when
root filesysem is on ZFS; zfs-initramfs because it doesn't drop a
hook into /usr/share/initramfs-tools/hooks to get fsck.zfs included)
but certainly you know what is most appropriate better than I do.