Debian Bug report logs - #540786
[grub-common] update-grub/grub-mkconfig doesnt work with btrfs as rootfs

version graph

Package: grub-common; Maintainer for grub-common is GRUB Maintainers <pkg-grub-devel@alioth-lists.debian.net>; Source for grub-common is src:grub2 (PTS, buildd, popcon).

Reported by: Robert Wohlrab <robert.wohlrab@gmx.de>

Date: Mon, 10 Aug 2009 11:03:02 UTC

Severity: normal

Tags: fixed-upstream, moreinfo

Merged with 567077

Found in versions grub2/1.96+20090725-1, grub2/1.96+20090808-1, grub2/1.97~beta3-1

Fixed in version grub2/1.98+20100602-1

Done: Colin Watson <cjwatson@debian.org>

Bug is archived. No further changes may be made.

Toggle useless messages

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to debian-bugs-dist@lists.debian.org, GRUB Maintainers <pkg-grub-devel@lists.alioth.debian.org>:
Bug#540786; Package grub-common. (Mon, 10 Aug 2009 11:03:04 GMT) (full text, mbox, link).


Acknowledgement sent to Robert Wohlrab <robert.wohlrab@gmx.de>:
New Bug report received and forwarded. Copy sent to GRUB Maintainers <pkg-grub-devel@lists.alioth.debian.org>. (Mon, 10 Aug 2009 11:03:04 GMT) (full text, mbox, link).


Message #5 received at submit@bugs.debian.org (full text, mbox, reply):

From: Robert Wohlrab <robert.wohlrab@gmx.de>
To: submit@bugs.debian.org
Subject: [grub-common] update-grub/grub-mkconfig doesnt work with btrfs as rootfs
Date: Mon, 10 Aug 2009 12:56:56 +0200
Package: grub-common
Version: 1.96+20090725-1
Severity: normal

I have following test machine setup:
linux-2.6.31-rc5
/dev/sda2 - ext2 for /boot
/dev/sda3 - btrfs for /
/dev/sda4 - extended
/dev/sda5 - ext4 for /home
/dev/sda6 - swap

The system is booted (added a own block at /boot/grub/grub.cfg). When I run 
`update-grub` or `grub-mkconfig -o /boot/grub/grub.cfg` it just prints
 grub-probe: error: cannot find a device for /.

The problem seems to be that / is different then /dev/sda3

root.st_dev == 16
sda3.st_rdev == 2051

root.st_dev != sda2.st_rdev

If I look at /boot it looks like:
boot.st_dev == 2050
sda2.st_rdev == 2050

Maybe it has something to do with btrfs's subvolume support.

The problem is now that grub-probe now tests st_dev of / against st_rdev of 
the block devices in util/getroot.c find_root_device(..).
 if (S_ISBLK (st.st_mode) && st.st_rdev == dev)

Here the complete struct stat of /dev/sda3
1: st = {
 st_dev = 13,
 st_ino = 3243,
 st_nlink = 1,
 st_mode = 25008,
 st_uid = 0,
 st_gid = 6,
 __pad0 = 0,
 st_rdev = 2051,
 st_size = 0,
 st_blksize = 4096,
 st_blocks = 0,
 st_atim = {tv_sec = 1249898809, tv_nsec = 773817591},
 st_mtim = {tv_sec = 1249898809, tv_nsec = 753815550},
 st_ctim = {tv_sec = 1249891613, tv_nsec = 405308420},
 __unused = {0, 0, 0}}

and of /
1: st = {
 st_dev = 16,
 st_ino = 256,
 st_nlink = 1,
 st_mode = 16877,
 st_uid = 0,
 st_gid = 0,
 __pad0 = 0,
 st_rdev = 0,
 st_size = 286,
 st_blksize = 4096,
 st_blocks = 8,
 st_atim = {tv_sec = 1249891701, tv_nsec = 425313494},
 st_mtim = {tv_sec = 1249891699, tv_nsec = 353312069},
 st_ctim = {tv_sec = 1249891699, tv_nsec = 353312069},
 __unused = {0, 0, 0}}

--- System information. ---
Architecture: amd64
Kernel:       Linux 2.6.31-rc5

Debian Release: squeeze/sid
  500 unstable        ftp.debian.org 
    1 experimental    ftp.debian.org 

--- Package information. ---
Depends                    (Version) | Installed
====================================-+-====================
libc6                       (>= 2.3) | 2.9-23
libfreetype6              (>= 2.2.1) | 2.3.9-5
libncurses5      (>= 5.6+20071006-3) | 5.7+20090803-1
zlib1g                  (>= 1:1.1.4) | 1:1.2.3.3.dfsg-15
base-files               (>= 4.0.1~) | 5.0.0


Package's Recommends field is empty.

Suggests           (Version) | Installed
============================-+-===========
multiboot-doc                | 





-- 
Robert Wohlrab




Information forwarded to debian-bugs-dist@lists.debian.org, GRUB Maintainers <pkg-grub-devel@lists.alioth.debian.org>:
Bug#540786; Package grub-common. (Thu, 13 Aug 2009 08:51:13 GMT) (full text, mbox, link).


Acknowledgement sent to Vladimir Stavrinov <vs@inist.ru>:
Extra info received and forwarded to list. Copy sent to GRUB Maintainers <pkg-grub-devel@lists.alioth.debian.org>. (Thu, 13 Aug 2009 08:51:13 GMT) (full text, mbox, link).


Message #10 received at 540786@bugs.debian.org (full text, mbox, reply):

From: Vladimir Stavrinov <vs@inist.ru>
To: Debian Bug Tracking System <540786@bugs.debian.org>
Subject: Re: update-grub/grub-mkconfig doesnt work with btrfs as rootfs
Date: Thu, 13 Aug 2009 12:47:47 +0400
Package: grub-common
Version: 1.96+20090808-1
Severity: normal


The same problem exists in diskless and chrooted environment.

chroot is done onto logical volume, while root directory is partition on
physical device, but both filesystems is ext3. It break chrooted system
upgrade process with error:

grub-probe: error: cannot find a device for /.

that is output of

grub-probe /

calling by update-grub from postinst script.

In case of diskless workstation the root fs is aufs based on cifs.

-- System Information:
Debian Release: squeeze/sid
  APT prefers unstable
  APT policy: (500, 'unstable'), (500, 'testing'), (500, 'stable')
Architecture: i386 (x86_64)

Kernel: Linux 2.6.30-1-amd64 (SMP w/2 CPU cores)
Locale: LANG=C, LC_CTYPE=ru_RU.KOI8-R (charmap=KOI8-R)
Shell: /bin/sh linked to /bin/bash

Versions of packages grub-common depends on:
ii  base-files             5.0.0             Debian base system miscellaneous f
ii  libc6                  2.9-24            GNU C Library: Shared libraries
ii  libfreetype6           2.3.9-5           FreeType 2 font engine, shared lib
ii  libncurses5            5.7+20090803-1+b1 shared libraries for terminal hand
ii  zlib1g                 1:1.2.3.3.dfsg-15 compression library - runtime

grub-common recommends no packages.

Versions of packages grub-common suggests:
pn  multiboot-doc                 <none>     (no description available)
pn  os-prober                     <none>     (no description available)

-- no debconf information




Information forwarded to debian-bugs-dist@lists.debian.org, GRUB Maintainers <pkg-grub-devel@lists.alioth.debian.org>:
Bug#540786; Package grub-common. (Thu, 13 Aug 2009 09:15:03 GMT) (full text, mbox, link).


Acknowledgement sent to Vladimir Stavrinov <vs@inist.ru>:
Extra info received and forwarded to list. Copy sent to GRUB Maintainers <pkg-grub-devel@lists.alioth.debian.org>. (Thu, 13 Aug 2009 09:15:03 GMT) (full text, mbox, link).


Message #15 received at 540786@bugs.debian.org (full text, mbox, reply):

From: Vladimir Stavrinov <vs@inist.ru>
To: Debian Bug Tracking System <540786@bugs.debian.org>
Subject: Re: update-grub/grub-mkconfig doesnt work with btrfs as rootfs
Date: Thu, 13 Aug 2009 13:11:41 +0400
On Thu, Aug 13, 2009 at 12:47:47PM +0400, Vladimir Stavrinov wrote:

> calling by update-grub from postinst script.
                              ^^^^^^^^^^^^^^^^

I mean postinst script of grub-pc package. Please, reassign to this
package if it should to be reassigned.

-- 

*********************************
****   Vladimir Stavrinov  ******
*******   vs@inist.ru   *********
*********************************





Information forwarded to debian-bugs-dist@lists.debian.org, GRUB Maintainers <pkg-grub-devel@lists.alioth.debian.org>:
Bug#540786; Package grub-common. (Sun, 18 Oct 2009 05:39:04 GMT) (full text, mbox, link).


Acknowledgement sent to Anthony DeRobertis <anthony@derobert.net>:
Extra info received and forwarded to list. Copy sent to GRUB Maintainers <pkg-grub-devel@lists.alioth.debian.org>. (Sun, 18 Oct 2009 05:39:04 GMT) (full text, mbox, link).


Message #20 received at 540786@bugs.debian.org (full text, mbox, reply):

From: Anthony DeRobertis <anthony@derobert.net>
To: Debian Bug Tracking System <540786@bugs.debian.org>
Subject: Patch to work around btrfs, etc. problems
Date: Sun, 18 Oct 2009 01:30:29 -0400
[Message part 1 (text/plain, inline)]
Package: grub-common
Version: 1.97~beta3-1
Severity: normal
File: /usr/sbin/grub-mkconfig
Tags: patch

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

The attached patch works around the bug by allowing GRUB_DEVICE to be set in
/etc/default/grub and not probing if its set there.


- -- System Information:
Debian Release: squeeze/sid
  APT prefers oldstable
  APT policy: (500, 'oldstable'), (500, 'testing'), (130, 'unstable'), (120, 'experimental')
Architecture: amd64 (x86_64)

Kernel: Linux 2.6.32-rc5 (SMP w/2 CPU cores)
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/bash

Versions of packages grub-common depends on:
ii  base-files             5.0.0             Debian base system miscellaneous f
ii  libc6                  2.9-25            GNU C Library: Shared libraries
ii  libfreetype6           2.3.9-5           FreeType 2 font engine, shared lib
ii  libncurses5            5.7+20090803-2    shared libraries for terminal hand
ii  zlib1g                 1:1.2.3.3.dfsg-15 compression library - runtime

Versions of packages grub-common recommends:
pn  os-prober                     <none>     (no description available)

Versions of packages grub-common suggests:
pn  multiboot-doc                 <none>     (no description available)

- -- no debconf information

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)

iEYEARECAAYFAkrap/IACgkQ+z+IwlXqWf4fQgCgisuWEqxKKW7G+V6zAdog+bfm
q0MAmQFhHqy/BV06SlC4/9pj/+JWCrq8
=a29R
-----END PGP SIGNATURE-----
[grub.diff (text/x-diff, attachment)]

Added tag(s) patch. Request was from Anthony DeRobertis <anthony@derobert.net> to control@bugs.debian.org. (Sun, 18 Oct 2009 05:39:05 GMT) (full text, mbox, link).


Added indication that bug 540786 blocks 567077 Request was from Joey Hess <joeyh@debian.org> to control@bugs.debian.org. (Wed, 27 Jan 2010 05:18:04 GMT) (full text, mbox, link).


Information forwarded to debian-bugs-dist@lists.debian.org, GRUB Maintainers <pkg-grub-devel@lists.alioth.debian.org>:
Bug#540786; Package grub-common. (Thu, 28 Jan 2010 21:03:03 GMT) (full text, mbox, link).


Message #27 received at 540786@bugs.debian.org (full text, mbox, reply):

From: Robert Millan <rmh@aybabtu.com>
To: Robert Wohlrab <robert.wohlrab@gmx.de>, 540786@bugs.debian.org
Cc: Vladimir Stavrinov <vs@inist.ru>, Anthony DeRobertis <anthony@derobert.net>, Joey Hess <joeyh@debian.org>
Subject: Re: Bug#540786: [grub-common] update-grub/grub-mkconfig doesnt work with btrfs as rootfs
Date: Thu, 28 Jan 2010 22:01:00 +0100
tags 540786 - patch
tags 540786 moreinfo
forcemerge 540786 567077
thanks

On Mon, Aug 10, 2009 at 12:56:56PM +0200, Robert Wohlrab wrote:
> The problem is now that grub-probe now tests st_dev of / against st_rdev of 
> the block devices in util/getroot.c find_root_device(..).
>  if (S_ISBLK (st.st_mode) && st.st_rdev == dev)
> 
> Here the complete struct stat of /dev/sda3
> 1: st = {
>  [...]
>  st_rdev = 2051,
> and of /
> 1: st = {
>  st_dev = 16,
>  [...]

We need some way to match up the files with the device that contains them.
If that's not possible, we won't be able to support /boot in btrfs.

But if you just want grub-mkconfig not to break with btrfs in /, we need more
information on what calls are failing.  There's a gazillon invocations of
grub-probe in there, I can't do anything without knowing which one is causing
the script to fail.

-- 
Robert Millan

  "Be the change you want to see in the world" -- Gandhi




Removed tag(s) patch. Request was from Robert Millan <rmh@aybabtu.com> to control@bugs.debian.org. (Thu, 28 Jan 2010 21:03:07 GMT) (full text, mbox, link).


Added tag(s) moreinfo. Request was from Robert Millan <rmh@aybabtu.com> to control@bugs.debian.org. (Thu, 28 Jan 2010 21:03:08 GMT) (full text, mbox, link).


Forcibly Merged 540786 567077. Request was from Robert Millan <rmh@aybabtu.com> to control@bugs.debian.org. (Thu, 28 Jan 2010 21:03:09 GMT) (full text, mbox, link).


Information forwarded to debian-bugs-dist@lists.debian.org, GRUB Maintainers <pkg-grub-devel@lists.alioth.debian.org>:
Bug#540786; Package grub-common. (Fri, 29 Jan 2010 03:24:08 GMT) (full text, mbox, link).


Acknowledgement sent to Joey Hess <joeyh@debian.org>:
Extra info received and forwarded to list. Copy sent to GRUB Maintainers <pkg-grub-devel@lists.alioth.debian.org>. (Fri, 29 Jan 2010 03:24:08 GMT) (full text, mbox, link).


Message #38 received at 540786@bugs.debian.org (full text, mbox, reply):

From: Joey Hess <joeyh@debian.org>
To: Robert Millan <rmh@aybabtu.com>
Cc: Robert Wohlrab <robert.wohlrab@gmx.de>, 540786@bugs.debian.org, Vladimir Stavrinov <vs@inist.ru>, Anthony DeRobertis <anthony@derobert.net>
Subject: Re: Bug#540786: [grub-common] update-grub/grub-mkconfig doesnt work with btrfs as rootfs
Date: Thu, 28 Jan 2010 22:23:11 -0500
[Message part 1 (text/plain, inline)]
Robert Millan wrote:
> But if you just want grub-mkconfig not to break with btrfs in /, we need more
> information on what calls are failing.  There's a gazillon invocations of
> grub-probe in there, I can't do anything without knowing which one is causing
> the script to fail.

root@gnu:/home/joey>grub-probe --target=device /boot # ext3
/dev/hda1
root@gnu:/home/joey>grub-probe --target=device / # btrfs
grub-probe: error: cannot find a device for / (is /dev mounted?).
root@gnu:/home/joey>grub-probe --device /dev/hda1 --target=fs_uuid
a2c9d183-7f03-4451-b781-3e8fcd72c095
root@gnu:/home/joey>grub-probe --device /dev/hda2 --target=fs_uuid
grub-probe: error: unknown filesystem.

I had meant to send the attached patch to #540786 yesterday
(it's the patch that the patch I sent to #567077 depends on).
This makes it fall back to the old method of parsing
the fstab to find the info when grub-probe fails.

See also: https://bugs.launchpad.net/debian/+source/grub2/+bug/450260

-- 
see shy jo
[grub2-probe.patch (text/x-diff, attachment)]
[signature.asc (application/pgp-signature, inline)]

Information forwarded to debian-bugs-dist@lists.debian.org, GRUB Maintainers <pkg-grub-devel@lists.alioth.debian.org>:
Bug#540786; Package grub-common. (Fri, 29 Jan 2010 12:48:03 GMT) (full text, mbox, link).


Acknowledgement sent to Vladimir Stavrinov <vs@inist.ru>:
Extra info received and forwarded to list. Copy sent to GRUB Maintainers <pkg-grub-devel@lists.alioth.debian.org>. (Fri, 29 Jan 2010 12:48:03 GMT) (full text, mbox, link).


Message #43 received at 540786@bugs.debian.org (full text, mbox, reply):

From: Vladimir Stavrinov <vs@inist.ru>
To: Joey Hess <joeyh@debian.org>
Cc: Robert Millan <rmh@aybabtu.com>, Robert Wohlrab <robert.wohlrab@gmx.de>, 540786@bugs.debian.org, Anthony DeRobertis <anthony@derobert.net>
Subject: Re: Bug#540786: [grub-common] update-grub/grub-mkconfig doesnt work with btrfs as rootfs
Date: Fri, 29 Jan 2010 15:43:40 +0300
As for me, in chrooted environment, as I wrote above, this problem gone
away for me now and 

grub-probe /

return

ext2

-- 

*********************************
****   Vladimir Stavrinov  ******
*******   vs@inist.ru   *********
*********************************





Information forwarded to debian-bugs-dist@lists.debian.org, GRUB Maintainers <pkg-grub-devel@lists.alioth.debian.org>:
Bug#540786; Package grub-common. (Fri, 29 Jan 2010 14:15:03 GMT) (full text, mbox, link).


Message #46 received at 540786@bugs.debian.org (full text, mbox, reply):

From: Robert Millan <rmh@aybabtu.com>
To: Joey Hess <joeyh@debian.org>
Cc: Robert Wohlrab <robert.wohlrab@gmx.de>, 540786@bugs.debian.org, Vladimir Stavrinov <vs@inist.ru>, Anthony DeRobertis <anthony@derobert.net>
Subject: Re: Bug#540786: [grub-common] update-grub/grub-mkconfig doesnt work with btrfs as rootfs
Date: Fri, 29 Jan 2010 15:11:49 +0100
On Thu, Jan 28, 2010 at 10:23:11PM -0500, Joey Hess wrote:
> root@gnu:/home/joey>grub-probe --target=device / # btrfs
> grub-probe: error: cannot find a device for / (is /dev mounted?).

Ok.  Problem here is not related to lack of btrfs support in GRUB, but to
Linux not providing a match between st_rdev and st_dev (even though a
theoretical match exists).

We're working on that.

> root@gnu:/home/joey>grub-probe --device /dev/hda2 --target=fs_uuid
> grub-probe: error: unknown filesystem.

UUID fetching itself doesn't sound too much work.  I'll probably implement
this as well.

> I had meant to send the attached patch to #540786 yesterday
> (it's the patch that the patch I sent to #567077 depends on).
> This makes it fall back to the old method of parsing
> the fstab to find the info when grub-probe fails.

Sorry but I want a proper fix.  fstab parsing had its own set of problems
and it was (rightfully, IMO) abandoned.

-- 
Robert Millan

  "Be the change you want to see in the world" -- Gandhi




Information stored :
Bug#540786; Package grub-common. (Sat, 30 Jan 2010 23:45:05 GMT) (full text, mbox, link).


Acknowledgement sent to Anthony DeRobertis <anthony@derobert.net>:
Extra info received and filed, but not forwarded. (Sat, 30 Jan 2010 23:45:05 GMT) (full text, mbox, link).


Message #51 received at 540786-quiet@bugs.debian.org (full text, mbox, reply):

From: Anthony DeRobertis <anthony@derobert.net>
Cc: 540786-quiet@bugs.debian.org
Subject: Re: Bug#540786: [grub-common] update-grub/grub-mkconfig doesnt work with btrfs as rootfs
Date: Sat, 30 Jan 2010 18:23:50 -0500
[I messed up the BTS address; the has already been sent to everyone 
else. Just sending to the bug this time]

> But if you just want grub-mkconfig not to break with btrfs in /, we need more
> information on what calls are failing.  There's a gazillon invocations of
> grub-probe in there, I can't do anything without knowing which one is causing
> the script to fail.

The one that is failing (at least for me) is the one I patched around:

	@@ -119,8 +122,12 @@
	 fi
	 	 # Device containing our userland.  Typically used for root= parameter.
	-GRUB_DEVICE="`${grub_probe} --target=device /`"
	-GRUB_DEVICE_UUID="`${grub_probe} --device ${GRUB_DEVICE} 
--target=fs_uuid 2> /dev/null`" || true
	+if [ -z "$GRUB_DEVICE" ]; then
	+	GRUB_DEVICE="`${grub_probe} --target=device /`"
	+fi
	+if [ -z "$GRUB_DEVICE_UUID" ]; then
	+	GRUB_DEVICE_UUID="`${grub_probe} --device ${GRUB_DEVICE} 
--target=fs_uuid 2> /dev/null`" || true
	+fi
	 	 # Device containing our /boot partition.  Usually the same as 
GRUB_DEVICE.
	 GRUB_DEVICE_BOOT="`${grub_probe} --target=device /boot`"

(full patch 
http://bugs.debian.org/cgi-bin/bugreport.cgi?msg=20;filename=grub.diff;att=1;bug=540786)

PS: Its probably nice to have a way to override the auto-detect (i.e.,
that patch) completely independent of this bug.




Information forwarded to debian-bugs-dist@lists.debian.org, GRUB Maintainers <pkg-grub-devel@lists.alioth.debian.org>:
Bug#540786; Package grub-common. (Tue, 18 May 2010 12:21:03 GMT) (full text, mbox, link).


Acknowledgement sent to Colin Watson <cjwatson@ubuntu.com>:
Extra info received and forwarded to list. Copy sent to GRUB Maintainers <pkg-grub-devel@lists.alioth.debian.org>. (Tue, 18 May 2010 12:21:03 GMT) (full text, mbox, link).


Message #56 received at 540786@bugs.debian.org (full text, mbox, reply):

From: Colin Watson <cjwatson@ubuntu.com>
To: grub-devel@gnu.org
Cc: Robert Wohlrab <robert.wohlrab@gmx.de>, Anthony DeRobertis <anthony@derobert.net>, Joey Hess <joeyh@debian.org>, 540786@bugs.debian.org, Surbhi Palande <surbhi.palande@canonical.com>
Subject: btrfs-probe branch
Date: Tue, 18 May 2010 13:17:24 +0100
I've pushed sftp://bzr.sv.gnu.org/srv/bzr/grub/branches/btrfs-probe/
(world-readable: 'bzr get
http://bzr.savannah.gnu.org/r/grub/branches/btrfs-probe/') to handle
probing single-device btrfs filesystems.  I'm not going to pretend that
this is anything other than a hack, but it is reasonably well isolated
and it should be enough to handle the simple case where somebody has a
btrfs root filesystem and an ext[234] /boot.

Background and justification: since btrfs supports multiple-device
mounts, it always returns a virtual device (major number 0) in st_dev.
This means that grub-probe can't find the appropriate device node for a
given filesystem path just by statting the directory path and walking
/dev.  Instead, for the moment, I've taken the approach of looking
through /proc/self/mountinfo.  Note that this is pretty much exactly
what the now-widely-used udisks package does (src/mount-monitor.c), and
that's where I got the idea, although I implemented it independently to
avoid copyright assignment questions.

(Vladimir cited a rumour to the effect that libblkid may be able to
handle this, but I haven't been able to find any evidence of it knowing
how to deal with mount points at all.  We can always revisit this
later.)

This only deals with the single-device case for now.  Dealing with the
multiple-device case would (I think) require interface changes to
grub-probe, and I haven't thought about that much yet.

I've done basic testing, but would appreciate testing from others as
well.  For those who don't want to bother checking it out from revision
control, the patch follows.  It's against trunk, but should apply with
only a little bit of fuzz to 1.98; just note that in that case you'll
need to apply the patch for kern/emu/hostdisk.c to util/hostdisk.c
instead.

=== added file 'ChangeLog.btrfs-probe'
--- ChangeLog.btrfs-probe	1970-01-01 00:00:00 +0000
+++ ChangeLog.btrfs-probe	2010-05-18 12:01:59 +0000
@@ -0,0 +1,8 @@
+2010-05-18  Colin Watson  <cjwatson@ubuntu.com>
+
+	Add btrfs probing support, currently only in the single-device case.
+
+	* kern/emu/getroot.c (find_root_device_from_mountinfo): New
+	function.
+	(grub_guess_root_device): Call find_root_device_from_mountinfo
+	before looking in /dev.

=== modified file 'kern/emu/getroot.c'
--- kern/emu/getroot.c	2010-05-06 03:15:39 +0000
+++ kern/emu/getroot.c	2010-05-18 12:01:59 +0000
@@ -80,6 +80,84 @@ xgetcwd (void)
   return path;
 }
 
+#ifdef __linux__
+
+/* Statting something on a btrfs filesystem always returns a virtual device
+   major/minor pair rather than the real underlying device, because btrfs
+   can span multiple underlying devices (and even if it's currently only
+   using a single device it can be dynamically extended onto another).  We
+   can't deal with the multiple-device case yet, but in the meantime, we can
+   at least cope with the single-device case by scanning
+   /proc/self/mountinfo.  */
+static char *
+find_root_device_from_mountinfo (const char *dir)
+{
+  FILE *fp;
+  char buf[1024];	/* XXX */
+  char *ret = NULL;
+
+  fp = fopen ("/proc/self/mountinfo", "r");
+  if (! fp)
+    return NULL; /* fall through to other methods */
+
+  while (fgets (buf, sizeof (buf), fp))
+    {
+      int mnt_id, parent_mnt_id;
+      unsigned int major, minor;
+      char enc_root[PATH_MAX], enc_path[PATH_MAX];
+      int count;
+      size_t enc_path_len;
+      const char *sep;
+      char fstype[PATH_MAX], device[PATH_MAX];
+      struct stat st;
+
+      if (sscanf (buf, "%d %d %u:%u %s %s%n",
+		  &mnt_id, &parent_mnt_id, &major, &minor, enc_root, enc_path,
+		  &count) < 6)
+	continue;
+
+      if (strcmp (enc_root, "/") != 0)
+	continue; /* only a subtree is mounted */
+
+      enc_path_len = strlen (enc_path);
+      if (strncmp (dir, enc_path, enc_path_len) != 0 ||
+	  (dir[enc_path_len] && dir[enc_path_len] != '/'))
+	continue;
+
+      /* This is a parent of the requested directory.  /proc/self/mountinfo
+	 is in mount order, so it must be the closest parent we've
+	 encountered so far.  If it's virtual, return its device node;
+	 otherwise, carry on to try to find something closer.  */
+
+      free (ret);
+      ret = NULL;
+
+      if (major != 0)
+	continue; /* not a virtual device */
+
+      sep = strstr (buf + count, " - ");
+      if (!sep)
+	continue;
+
+      sep += strlen (" - ");
+      if (sscanf (sep, "%s %s", fstype, device) != 2)
+	continue;
+
+      if (stat (device, &st) < 0)
+	continue;
+
+      if (!S_ISBLK (st.st_mode))
+	continue; /* not a block device */
+
+      ret = strdup (device);
+    }
+
+  fclose (fp);
+  return ret;
+}
+
+#endif /* __linux__ */
+
 #ifdef __MINGW32__
 
 static char *
@@ -355,6 +433,12 @@ grub_guess_root_device (const char *dir)
 #else /* !__GNU__ */
   struct stat st;
 
+#ifdef __linux__
+  os_dev = find_root_device_from_mountinfo (dir);
+  if (os_dev)
+    return os_dev;
+#endif /* __linux__ */
+
   if (stat (dir, &st) < 0)
     grub_util_error ("cannot stat `%s'", dir);
 

-- 
Colin Watson                                       [cjwatson@ubuntu.com]




Information forwarded to debian-bugs-dist@lists.debian.org, GRUB Maintainers <pkg-grub-devel@lists.alioth.debian.org>:
Bug#540786; Package grub-common. (Tue, 18 May 2010 12:27:08 GMT) (full text, mbox, link).


Acknowledgement sent to Colin Watson <cjwatson@ubuntu.com>:
Extra info received and forwarded to list. Copy sent to GRUB Maintainers <pkg-grub-devel@lists.alioth.debian.org>. (Tue, 18 May 2010 12:27:08 GMT) (full text, mbox, link).


Message #61 received at 540786@bugs.debian.org (full text, mbox, reply):

From: Colin Watson <cjwatson@ubuntu.com>
To: grub-devel@gnu.org
Cc: Surbhi Palande <surbhi.palande@canonical.com>, Anthony DeRobertis <anthony@derobert.net>, Joey Hess <joeyh@debian.org>, 540786@bugs.debian.org, Robert Wohlrab <robert.wohlrab@gmx.de>
Subject: Re: btrfs-probe branch
Date: Tue, 18 May 2010 13:23:49 +0100
On Tue, May 18, 2010 at 01:17:24PM +0100, Colin Watson wrote:
> I've done basic testing, but would appreciate testing from others as
> well.  For those who don't want to bother checking it out from revision
> control, the patch follows.  It's against trunk, but should apply with
> only a little bit of fuzz to 1.98; just note that in that case you'll
> need to apply the patch for kern/emu/hostdisk.c to util/hostdisk.c
> instead.

Err, just checking whether you were paying attention ... obviously I
meant "you'll need to apply the patch for kern/emu/getroot.c to
util/getroot.c instead".

-- 
Colin Watson                                       [cjwatson@ubuntu.com]




Information forwarded to debian-bugs-dist@lists.debian.org, GRUB Maintainers <pkg-grub-devel@lists.alioth.debian.org>:
Bug#540786; Package grub-common. (Tue, 18 May 2010 13:00:02 GMT) (full text, mbox, link).


Acknowledgement sent to Colin Watson <cjwatson@ubuntu.com>:
Extra info received and forwarded to list. Copy sent to GRUB Maintainers <pkg-grub-devel@lists.alioth.debian.org>. (Tue, 18 May 2010 13:00:03 GMT) (full text, mbox, link).


Message #66 received at 540786@bugs.debian.org (full text, mbox, reply):

From: Colin Watson <cjwatson@ubuntu.com>
To: grub-devel@gnu.org
Cc: Robert Wohlrab <robert.wohlrab@gmx.de>, Anthony DeRobertis <anthony@derobert.net>, Joey Hess <joeyh@debian.org>, 540786@bugs.debian.org, Surbhi Palande <surbhi.palande@canonical.com>
Subject: Re: btrfs-probe branch
Date: Tue, 18 May 2010 13:56:47 +0100
On Tue, May 18, 2010 at 01:17:24PM +0100, Colin Watson wrote:
> (Vladimir cited a rumour to the effect that libblkid may be able to
> handle this, but I haven't been able to find any evidence of it knowing
> how to deal with mount points at all.  We can always revisit this
> later.)

Scott James Remnant chased this up.  'blkid -o list' shows mount points,
but this is implemented in the blkid command-line tool rather than in
the libblkid library.  I don't think it would be significantly easier
for grub-probe to parse the output of a command-line tool than for it to
just parse /proc/self/mountinfo, and it certainly wouldn't be any
quicker, so I suggest staying with the approach in my branch until some
appropriate feature is available in libblkid or another common library.

-- 
Colin Watson                                       [cjwatson@ubuntu.com]




Added tag(s) fixed-upstream. Request was from Colin Watson <cjwatson@debian.org> to control@bugs.debian.org. (Tue, 01 Jun 2010 17:36:02 GMT) (full text, mbox, link).


Added tag(s) pending. Request was from Colin Watson <cjwatson@debian.org> to control@bugs.debian.org. (Wed, 02 Jun 2010 00:36:02 GMT) (full text, mbox, link).


Reply sent to Colin Watson <cjwatson@debian.org>:
You have taken responsibility. (Thu, 03 Jun 2010 11:54:16 GMT) (full text, mbox, link).


Notification sent to Robert Wohlrab <robert.wohlrab@gmx.de>:
Bug acknowledged by developer. (Thu, 03 Jun 2010 11:54:16 GMT) (full text, mbox, link).


Message #75 received at 540786-close@bugs.debian.org (full text, mbox, reply):

From: Colin Watson <cjwatson@debian.org>
To: 540786-close@bugs.debian.org
Subject: Bug#540786: fixed in grub2 1.98+20100602-1
Date: Thu, 03 Jun 2010 11:51:07 +0000
Source: grub2
Source-Version: 1.98+20100602-1

We believe that the bug you reported is fixed in the latest version of
grub2, which is due to be installed in the Debian FTP archive:

grub-common_1.98+20100602-1_i386.deb
  to main/g/grub2/grub-common_1.98+20100602-1_i386.deb
grub-coreboot_1.98+20100602-1_i386.deb
  to main/g/grub2/grub-coreboot_1.98+20100602-1_i386.deb
grub-efi-amd64_1.98+20100602-1_i386.deb
  to main/g/grub2/grub-efi-amd64_1.98+20100602-1_i386.deb
grub-efi-ia32_1.98+20100602-1_i386.deb
  to main/g/grub2/grub-efi-ia32_1.98+20100602-1_i386.deb
grub-efi_1.98+20100602-1_i386.deb
  to main/g/grub2/grub-efi_1.98+20100602-1_i386.deb
grub-emu_1.98+20100602-1_i386.deb
  to main/g/grub2/grub-emu_1.98+20100602-1_i386.deb
grub-firmware-qemu_1.98+20100602-1_i386.deb
  to main/g/grub2/grub-firmware-qemu_1.98+20100602-1_i386.deb
grub-ieee1275_1.98+20100602-1_i386.deb
  to main/g/grub2/grub-ieee1275_1.98+20100602-1_i386.deb
grub-linuxbios_1.98+20100602-1_i386.deb
  to main/g/grub2/grub-linuxbios_1.98+20100602-1_i386.deb
grub-pc_1.98+20100602-1_i386.deb
  to main/g/grub2/grub-pc_1.98+20100602-1_i386.deb
grub-rescue-pc_1.98+20100602-1_i386.deb
  to main/g/grub2/grub-rescue-pc_1.98+20100602-1_i386.deb
grub2_1.98+20100602-1.diff.gz
  to main/g/grub2/grub2_1.98+20100602-1.diff.gz
grub2_1.98+20100602-1.dsc
  to main/g/grub2/grub2_1.98+20100602-1.dsc
grub2_1.98+20100602-1_i386.deb
  to main/g/grub2/grub2_1.98+20100602-1_i386.deb
grub2_1.98+20100602.orig.tar.gz
  to main/g/grub2/grub2_1.98+20100602.orig.tar.gz



A summary of the changes between this version and the previous one is
attached.

Thank you for reporting the bug, which will now be closed.  If you
have further comments please address them to 540786@bugs.debian.org,
and the maintainer will reopen the bug report if appropriate.

Debian distribution maintenance software
pp.
Colin Watson <cjwatson@debian.org> (supplier of updated grub2 package)

(This message was generated automatically at their request; if you
believe that there is a problem with it please contact the archive
administrators by mailing ftpmaster@debian.org)


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Format: 1.8
Date: Thu, 03 Jun 2010 11:24:41 +0100
Source: grub2
Binary: grub2 grub-linuxbios grub-efi grub-common grub-emu grub-pc grub-rescue-pc grub-coreboot grub-efi-ia32 grub-efi-amd64 grub-ieee1275 grub-firmware-qemu grub-yeeloong
Architecture: source i386
Version: 1.98+20100602-1
Distribution: unstable
Urgency: low
Maintainer: GRUB Maintainers <pkg-grub-devel@lists.alioth.debian.org>
Changed-By: Colin Watson <cjwatson@debian.org>
Description: 
 grub-common - GRand Unified Bootloader, version 2 (common files)
 grub-coreboot - GRand Unified Bootloader, version 2 (Coreboot version)
 grub-efi   - GRand Unified Bootloader, version 2 (dummy package)
 grub-efi-amd64 - GRand Unified Bootloader, version 2 (EFI-AMD64 version)
 grub-efi-ia32 - GRand Unified Bootloader, version 2 (EFI-IA32 version)
 grub-emu   - GRand Unified Bootloader, version 2 (emulated version)
 grub-firmware-qemu - GRUB firmware image for QEMU
 grub-ieee1275 - GRand Unified Bootloader, version 2 (Open Firmware version)
 grub-linuxbios - GRand Unified Bootloader, version 2 (dummy package)
 grub-pc    - GRand Unified Bootloader, version 2 (PC/BIOS version)
 grub-rescue-pc - GRUB bootable rescue images, version 2 (PC/BIOS version)
 grub-yeeloong - GRand Unified Bootloader, version 2 (Yeeloong version)
 grub2      - GRand Unified Bootloader, version 2 (dummy package)
Closes: 450505 497085 540786 548320 567211 584176 584218
Changes: 
 grub2 (1.98+20100602-1) unstable; urgency=low
 .
   * New Bazaar snapshot.
     - Add btrfs probing support, currently only in the single-device case
       (closes: #540786).
     - Fix grub-emu build on mips/powerpc/sparc.
     - Add safety check to make sure that /boot/grub/locale exists before
       trying to probe it (closes: #567211).
     - Several 'info grub' improvements, including a new section on
       configuration file generation using grub-mkconfig which documents the
       available keys in /etc/default/grub (closes: #497085).
     - Many USB fixes.
 .
   [ Colin Watson ]
   * Reorganise configure and build targets in debian/rules to use stamp
     files.  configure/* never existed and build/* was always a directory, so
     make never considered either of them up to date (closes: #450505).
   * Remove config.h.in from AUTOGEN_FILES, since autoheader doesn't
     necessarily update it.
   * Remove conf/gcry.mk from AUTOGEN_FILES, and conf/gcry.rmk from their
     dependencies.  autogen.sh runs util/import_gcry.py after autoconf et al,
     so conf/gcry.rmk's timestamp will be later than some of the
     autogenerated outputs.
   * Go back to shipping rescue images in the grub-rescue-pc .deb itself
     rather than generating them in the postinst.  This means that (a) they
     get removed when the package is removed (closes: #584176); (b) they are
     listed in package metadata, as is proper for files in /usr (closes:
     #584218); (c) grub-rescue-pc can potentially be used as a
     build-dependency for other packages that need to build GRUB images into
     installation media etc., without having to build-depend on grub-pc which
     isn't coinstallable with other platform variants and does invasive
     things in its postinst.
   * Add grub-mkrescue patch from Thomas Schmitt to allow reducing the size
     of xorriso-created images.  Use this to ensure that
     grub-rescue-floppy.img fits well within size limits (closes: #548320).
Checksums-Sha1: 
 d7c8a7ca219f59854e33a42a8e91ecfdd036d75d 2641 grub2_1.98+20100602-1.dsc
 5a7788deecc812a71e2219f088d66fb465205539 1709707 grub2_1.98+20100602.orig.tar.gz
 5eb50c3990e4f897a0ad30961013c2f08bcca15d 496607 grub2_1.98+20100602-1.diff.gz
 210c8b48ad990820470f4ccd0971df4c2c952626 258678 grub2_1.98+20100602-1_i386.deb
 37ce5fc303b774a91011a825edb24dbda1da82e1 257472 grub-linuxbios_1.98+20100602-1_i386.deb
 4d99decb1f748e06338507c9ba83bf88414453bd 257476 grub-efi_1.98+20100602-1_i386.deb
 2205466b9d9aa3f32d89e8dc4be5f1bbf16c2f8c 1237136 grub-common_1.98+20100602-1_i386.deb
 2e4385bcae654e6916ee52725059463ac7fb9859 2568648 grub-emu_1.98+20100602-1_i386.deb
 8b7b26016f5d7fcd42de15b66fcb04569f368881 912518 grub-pc_1.98+20100602-1_i386.deb
 e1aa233bdaabb853bceec0f118a3ad50996d1ead 1405960 grub-rescue-pc_1.98+20100602-1_i386.deb
 cde82bc0dd302a98740ccffbab22e645dac6ac45 714532 grub-coreboot_1.98+20100602-1_i386.deb
 23181afde01e0e418d46c772a188b85caa8ba2a5 750244 grub-efi-ia32_1.98+20100602-1_i386.deb
 d6137413c432c46881ac89ed979166d60dee1468 824930 grub-efi-amd64_1.98+20100602-1_i386.deb
 229825f827e7df7c801a5cc4aa872b015673e0ef 707950 grub-ieee1275_1.98+20100602-1_i386.deb
 d93278bd2644c3256c2cb7a45469c4ee19144892 662958 grub-firmware-qemu_1.98+20100602-1_i386.deb
Checksums-Sha256: 
 9f21072606323d78ae68f938c7c06796cc55d227d9aeef2096c49c7cdc6d5899 2641 grub2_1.98+20100602-1.dsc
 2194ed5f47b5c3b5799751f515893cfb185e4d2774bc17c93a1cbde54b32a593 1709707 grub2_1.98+20100602.orig.tar.gz
 d45e49878ea42d8183bf9b103e35bf1f804c1d78888a9f35cf71dc3bfac7d14e 496607 grub2_1.98+20100602-1.diff.gz
 30618d7debf58a14ad30788cb7dd433c7170ad13b5d3beab00cf7c4d327ac036 258678 grub2_1.98+20100602-1_i386.deb
 a00b8d95f3b57ed4ad63d967c3f26ed99f67d817dfc74e377785079c810b9ad0 257472 grub-linuxbios_1.98+20100602-1_i386.deb
 bf78aa7639880fadfd5bf5f543cc9e1e70edfeb6daf4d8a9f62ba6200d645f5d 257476 grub-efi_1.98+20100602-1_i386.deb
 9bf619e679ce1175281e0fd9537cb4a5fe2a1a27421b800a7616aebaa206178a 1237136 grub-common_1.98+20100602-1_i386.deb
 5d754f807f278547e0a386e21b0cad5352fbfb8414ac2599cf2bc63f5bd08fb3 2568648 grub-emu_1.98+20100602-1_i386.deb
 6f2d6277da522469845f8b3f4682ecfd3756fc9f3400afb10812f14302b68d7d 912518 grub-pc_1.98+20100602-1_i386.deb
 3054f0bf986db68ba0351bb84d0604cd14e6177f11f5f2d35b5057d1e8eb6a3f 1405960 grub-rescue-pc_1.98+20100602-1_i386.deb
 55d99e5cd9caa69a2bf2066275afc3d80c1f7b83a6a989e747e5f39497f90d9d 714532 grub-coreboot_1.98+20100602-1_i386.deb
 8b3cf4e4d12aba1015e715062d302d3db0272cfbe782915734a4ad19f72a7941 750244 grub-efi-ia32_1.98+20100602-1_i386.deb
 d25cf3cbcda0626466bfd83cc8119d1d2692ff086abb881cc6e9c60583e20bd7 824930 grub-efi-amd64_1.98+20100602-1_i386.deb
 bb73ef7ac08765d6dfd470ca853ff067933023f826f6b9158e23791eaff03ccf 707950 grub-ieee1275_1.98+20100602-1_i386.deb
 2c6b0fae25a5b37308ee97b4e85a5620263e8ec37bde2103ff640cab5ee389f2 662958 grub-firmware-qemu_1.98+20100602-1_i386.deb
Files: 
 2358fb1cad5df500b688a314c06d8cff 2641 admin extra grub2_1.98+20100602-1.dsc
 fbb8fdb4b47541c2dc1a8d13e8f7208f 1709707 admin extra grub2_1.98+20100602.orig.tar.gz
 a5e58ac4c1ed4b6d4e7403721792f3ea 496607 admin extra grub2_1.98+20100602-1.diff.gz
 25dfcf4335c40fdc060532fbf63a6f1b 258678 admin extra grub2_1.98+20100602-1_i386.deb
 071396419ee9249733942e0e7a76a374 257472 admin extra grub-linuxbios_1.98+20100602-1_i386.deb
 0b12a321df8e2118c11c061bdfe6fd3e 257476 admin extra grub-efi_1.98+20100602-1_i386.deb
 b011c9f47aa1cc965a13a96f62e8a50e 1237136 admin extra grub-common_1.98+20100602-1_i386.deb
 781e90c2a3af192ca86fd636784fbc5d 2568648 admin extra grub-emu_1.98+20100602-1_i386.deb
 223c81ed09766589668f36e737a394b3 912518 admin extra grub-pc_1.98+20100602-1_i386.deb
 9806e8ce2ead822414dc2fa30d08c168 1405960 admin extra grub-rescue-pc_1.98+20100602-1_i386.deb
 e72c222644d6294ec7c83f24f48a9db3 714532 admin extra grub-coreboot_1.98+20100602-1_i386.deb
 cde6dbc40abf95e1c74fd1e45c8b380d 750244 admin extra grub-efi-ia32_1.98+20100602-1_i386.deb
 50547fc5f3ca69f03c8e71b165b1c39e 824930 admin extra grub-efi-amd64_1.98+20100602-1_i386.deb
 fff5bb9b076a7b0c2b58576c408249ff 707950 admin extra grub-ieee1275_1.98+20100602-1_i386.deb
 d0cf9382700b0d95e9f6d4b7282cb019 662958 admin extra grub-firmware-qemu_1.98+20100602-1_i386.deb

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Colin Watson <cjwatson@debian.org> -- Debian developer

iQIVAwUBTAeREjk1h9l9hlALAQgjQRAAmnOqrFnDDWlQ13mLkURpIMBd6N/HpHoK
3wFdBRdf92nWL25qY+XW42WRMgoYSg7OZi0l50apFbzW/iXS3HzlQZrfd4d6rayv
7igdU+j1edCWK47JOyd07wGSy54jFayAn8N9euOe+xCCnUwMeZl0a4SNBoZUyau/
STgJ/sfTC33tTaY6jpOfgxCVRumuj6jADI/pgKRUFxBq+sVSCa20rAqZHrMIIrBx
JT1dP0LTafBgNVId/ecDmD0bDcBSHb0GagnCLeMCYE+4hWL3ca8gMcFIA/JOR88q
gihlrVj8xx2QETfIuyWvg0yy2s1SPk4ESJ4ifrJqThLs+hTYoTFDDV+gmkUKH1jE
DHuZnfg05KJf3jGVaM+7xiMwsdz/g75EDCd6t5fQwfmBIn4nuplh9wIflI8rTJt2
2DAir+Ce4YHr2wPkuXgpBBF8BN/JM3cQaZtFisodIBad/k8zi/nf+DsIJDB7p6EG
prpblHtNyer/5UbPgmPQ5sHHcyo/87tqbZKVrEZ2rwqtvkvVzM9VVv7L8WgZ/FkX
UqQn1iIPeMGc4h7bVmSH4oS1RE0VtmAbt3okygQ9XRumxrFkpXqCNV9+I3E7mCEg
zcGAVCXPaSKVkPmwtv/tFzQfMNsIMNn7+nt4Eb8US1qAkyrjm2kf2emyAF7eNTy+
urtwI+q+eb8=
=U1sJ
-----END PGP SIGNATURE-----





Reply sent to Colin Watson <cjwatson@debian.org>:
You have taken responsibility. (Thu, 03 Jun 2010 11:54:17 GMT) (full text, mbox, link).


Notification sent to Joey Hess <joeyh@debian.org>:
Bug acknowledged by developer. (Thu, 03 Jun 2010 11:54:17 GMT) (full text, mbox, link).


Bug archived. Request was from Debbugs Internal Request <owner@bugs.debian.org> to internal_control@bugs.debian.org. (Sun, 18 Jul 2010 07:34:57 GMT) (full text, mbox, link).


Send a report that this bug log contains spam.


Debian bug tracking system administrator <owner@bugs.debian.org>. Last modified: Tue Aug 14 21:55:34 2018; Machine Name: beach

Debian Bug tracking system

Debbugs is free software and licensed under the terms of the GNU Public License version 2. The current version can be obtained from https://bugs.debian.org/debbugs-source/.

Copyright © 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson, 2005-2017 Don Armstrong, and many other contributors.