grub-mkrelpath returns invalid zfs dataset -> initramfs: mount /root fails

Bug #1688424 reported by Jens Elkner
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
grub2 (Ubuntu)
New
Undecided
Unassigned

Bug Description

If zfs is used for boot, boot will fail because of bogus information returned by
/usr/bin/grub-mkrelpath. E.g. if the zfs dataset for / is rpool/ROOT/linux:

# /usr/bin/grub-mkrelpath /
/ROOT/linux@

This leads to a bogus /boot/grub/grub.cfg because /etc/grub.d/10_linux generates a boot entry like this:
linux /ROOT/linux@/boot/vmlinuz-4.4.0-77-generic root=ZFS=/ROOT/linux ro crashkernel=384M-2G:64M,2G-:128M bootdegraded=true debug=y console=ttyS1,115200 crashkernel=384M-:128M

This in turn causes that initramfs to fail on boot:
...
+ wait_for_udev
+ command -v udevadm
+ udevadm settle
+ modprobe zfs zfs_autoimport_disable=1
+ ZFS_BOOTFS=/ROOT/linux
+ echo /ROOT/linux
+ sed -e s,/.*,,
+ ZFS_RPOOL=
+ delay=0
+ [ 0 -gt 0 ]
+ unset delay
+ zpool import -N
[ 10.922149] SPL: The /etc/hostid file is not found.
[ 10.927031] SPL: using hostid 0x00000000
+ ZFS_STDERR=cannot import '': no such pool available
+ ZFS_ERROR=1
+ [ 1 -ne 0 ]
+ panic Command: zpool import -N
Message: cannot import '': no such pool available
Error: 1

Manually import the root pool at the command prompt and then exit.
Hint: Try: zpool import -f -R / -N

Wrong hint BTW, but at least a hint: "zpool import; zpool import ${poolID}|rpool" fixes it.
Anyway, when continuing after an 'exit' it fails with:

...
+ zpool status -L
+ [ n != y ]
+ log_begin_msg Setting mountpoint=/ on ZFS filesystem /ROOT/linux
+ _log_msg Begin: Setting mountpoint=/ on ZFS filesystem /ROOT/linux ...
+ [ n = y ]
+ printf Begin: Setting mountpoint=/ on ZFS filesystem /ROOT/linux ...
Begin: Setting mountpoint=/ on ZFS filesystem /ROOT/linux ... + zfs set mountpoint=/ /ROOT/linux
+ ZFS_STDERR=cannot open '/ROOT/linux': invalid dataset name
+ [ n != y ]
+ log_end_msg
+ _log_msg done.\n
+ [ n = y ]
+ printf done.\n
done.
+ [ n != y ]
+ log_begin_msg Mounting ZFS filesystem /ROOT/linux
+ _log_msg Begin: Mounting ZFS filesystem /ROOT/linux ...
+ [ n = y ]
+ printf Begin: Mounting ZFS filesystem /ROOT/linux ...
Begin: Mounting ZFS filesystem /ROOT/linux ... + mount -t zfs -o zfsutil /ROOT/linux /root
+ ZFS_STDERR=filesystem 'ROOT/linux' cannot be mounted, unable to open the dataset
mount: mounting /ROOT/linux on /root failed: No such file or directory
+ ZFS_ERROR=1
+ [ n != y ]
+ log_end_msg
+ _log_msg done.\n
+ [ n = y ]
+ printf done.\n
done.
+ [ 1 -ne 0 ]
+ panic Command: mount -t zfs -o zfsutil /ROOT/linux /root
Message: filesystem 'ROOT/linux' cannot be mounted, unable to open the dataset
mount: mounting /ROOT/linux on /root failed: No such file or directory
Error: 1

Manually mount the root filesystem on /root and then exit.

A 'mount -t zfs -o zfsutil rpool/ROOT/linux /root' fixis it and after an 'exit' the system finally starts.

Tags: patch
Jens Elkner (jelmd)
affects: dmidecode (Ubuntu) → grub2 (Ubuntu)
Revision history for this message
Jens Elkner (jelmd) wrote :

# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 16.04.2 LTS
Release: 16.04
Codename: xenial

Not sure, why it is made that complicated. IMHO the only thing to know is the name or ID of the pool, that contains the / dataset. Then initramfs can import it w/o any problems and related scripts incl. grub-mkconfig & friends do not need to mangle anything: Via 'zpool get -H bootfs ${pool}' or with more recent zfs-utils via 'zpool get -H -o value bootfs ${pool}' one may obtain directly the name of the dataset to mount on /root - no need to mangle anything as well.

Revision history for this message
Jens Elkner (jelmd) wrote :

Studied /etc/grub.d/10_linux a little bit deeper and found out, that the 'grub-mkrelpath /' is probably expected, but the way, how $rpool gets determined is buggy (and in this case it results into an empty string). Attaching a patch, which resolves the problem for me (just deduces it from whatever is mounted on / right now).

Revision history for this message
Jens Elkner (jelmd) wrote :
Revision history for this message
Ubuntu Foundations Team Bug Bot (crichton) wrote :

The attachment "grub-cfg.patch" seems to be a patch. If it isn't, please remove the "patch" flag from the attachment, remove the "patch" tag, and if you are a member of the ~ubuntu-reviewers, unsubscribe the team.

[This is an automated message performed by a Launchpad user owned by ~brian-murray, for any issues please contact him.]

tags: added: patch
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.