Package: grub-common Version: 1.99-21 Severity: normal Tags: upstream patch
'update-grub' may fail to determine the UUID for a BTRFS filesystem that is part of a multi-device BTRFS filesystem. The patch for '/etc/grub.d/10_linux' gets the UUID from 'btrfs filesystem show' instead. Background: The root cause is that BTRFS breaks the assumption that device-to-uuid is a 1:1 mapping. Under BTRFS, it can happen that the mount point for '/' in mtab and the UUID of the BTRFS filesystem point to different devices. On my system, one disk is connected to the SATA port on the mainboard and found first during boot. Under the booted system (from which update-grub is run), the disks connected to the PCIe SAS/SATA come first, resulting in the following mtab (excerpt, please note that '/' maps to 'sdE1' instead of 'sdb1'): /dev/sde1 on / type btrfs (rw,relatime,nospace_cache) /dev/sdb1 on /home type btrfs (rw,relatime,nospace_cache) /dev/sdb1 on /srv type btrfs (rw,relatime,nospace_cache) /dev/sdb1 on /.btrfs type btrfs (rw,relatime,nospace_cache) and in the following UUID-device mapping: $ ls -l /dev/disk/by-uuid/ lrwxrwxrwx 1 root root 10 Jun 8 11:49 04e9d27d-4274-4ab0-8b58-03acdeb1505a -> ../../sdc1 lrwxrwxrwx 1 root root 10 Jun 8 11:49 0ea28750-415a-477f-aad4-8329a3c09bd8 -> ../../sdb1 lrwxrwxrwx 1 root root 10 Jun 8 11:49 9be5e3d9-7e99-4c38-95d3-cad6f7c4981d -> ../../sda1 lrwxrwxrwx 1 root root 10 Jun 8 11:49 e799dfed-2423-4fbb-984c-15393ea14549 -> ../../sdc2 -- System Information: Debian Release: wheezy/sid APT prefers testing-proposed-updates APT policy: (500, 'testing-proposed-updates'), (500, 'testing'), (1, 'experimental') Architecture: amd64 (x86_64) Kernel: Linux 3.4.0 (SMP w/4 CPU cores) Locale: LANG=de_DE.UTF-8, LC_CTYPE=de_DE.UTF-8 (charmap=UTF-8) Shell: /bin/sh linked to /bin/dash Versions of packages grub-common depends on: ii gettext-base 0.18.1.1-8 ii libc6 2.13-32 ii libdevmapper1.02.1 2:1.02.67-2 ii libfreetype6 2.4.9-1 ii libfuse2 2.8.7-2 ii zlib1g 1:1.2.7.dfsg-11 Versions of packages grub-common recommends: ii os-prober 1.53 Versions of packages grub-common suggests: pn desktop-base <none> pn grub-emu <none> pn multiboot-doc <none> pn xorriso <none>
--- 10_linux.orig 2012-06-08 13:37:30.653665218 +0200 +++ /etc/grub.d/10_linux 2012-06-08 15:02:05.934930643 +0200 @@ -48,14 +48,6 @@ ;; esac -if [ "x${GRUB_DEVICE_UUID}" = "x" ] || [ "x${GRUB_DISABLE_LINUX_UUID}" = "xtrue" ] \ - || ! test -e "/dev/disk/by-uuid/${GRUB_DEVICE_UUID}" \ - || uses_abstraction "${GRUB_DEVICE}" lvm; then - LINUX_ROOT_DEVICE=${GRUB_DEVICE} -else - LINUX_ROOT_DEVICE=UUID=${GRUB_DEVICE_UUID} -fi - if [ "x`${grub_probe} --device ${GRUB_DEVICE} --target=fs 2>/dev/null || true`" = xbtrfs ] \ || [ "x`stat -f --printf=%T /`" = xbtrfs ]; then rootsubvol="`make_system_path_relative_to_its_root /`" @@ -63,6 +55,21 @@ if [ "x${rootsubvol}" != x ]; then GRUB_CMDLINE_LINUX="rootflags=subvol=${rootsubvol} ${GRUB_CMDLINE_LINUX}" fi + + ## under multi-device setups, grub-probe may have trouble finding the UUID for + ## the BTRFS volume + ## + if [ "x${GRUB_DEVICE_UUID}" = "x" ] ; then + GRUB_DEVICE_UUID=`btrfs filesystem show $GRUB_DEVICE 2>/dev/null | sed -ne 's,.*uuid: *\([0-9a-f]\{8\}\(-[0-9a-f]\{4\}\)\{3\}-[0-9a-f]\{12\}\).*,\1,pi'` + fi +fi + +if [ "x${GRUB_DEVICE_UUID}" = "x" ] || [ "x${GRUB_DISABLE_LINUX_UUID}" = "xtrue" ] \ + || ! test -e "/dev/disk/by-uuid/${GRUB_DEVICE_UUID}" \ + || uses_abstraction "${GRUB_DEVICE}" lvm; then + LINUX_ROOT_DEVICE=${GRUB_DEVICE} +else + LINUX_ROOT_DEVICE=UUID=${GRUB_DEVICE_UUID} fi linux_entry ()