[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#696615: grub2: no possibility to install from usb media



Cyril Brulebois <kibi@debian.org> (24/12/2012):
> I've just tried the following, instead of using some mini.iso (or any
> official iso) in a CD-Rom drive:
>  - convert it to a VDI image:
>      VBoxManage convertfromraw dest/netboot/gtk/mini.iso dest/netboot/gtk/mini.vdi
>  - attach the resulting VDI image to SATA port 0 in virtualbox.
>  - use guided partitioning, everything in a single partition, into
>    /dev/sdb (SATA port 1)
>  - enjoy the attempted “grub-install /dev/sda” call.
> 
> I'll be trying to fix that before rc1.

Here's what happens in grub-installer, with comments inline:
| # Try to avoid using (hd0) as a boot device name.  Something which can be
| # turned into a stable by-id name is better.
| default_bootdev_os="$($chroot $ROOT grub-mkdevicemap --no-floppy -m - | head -n1 | cut -f2)"

Notice the head -n1 here. If you're booting from /dev/sda, that's what
you get, no matter what.

For reference, here's what it looks like for two disks:
  (hd0) /dev/disk/by-id/ata-VBOX_HARDDISK_id1-id2
  (hd1) /dev/disk/by-id/ata-VBOX_HARDDISK_id3-id4

| if [ "$default_bootdev_os" ]; then
|         default_bootdev="$($chroot $ROOT readlink -f "$default_bootdev_os")"

That one turns the former top line into:
  /dev/sda

| else
|         default_bootdev="(hd0)"
| fi
| 
| # Set a sensible default boot device, so that we aren't installing GRUB to
| # installation media which may be removed later.  The disk containing /cdrom
| # is very unlikely to be a sensible default.  If we had to fall back to
| # (hd0), then we can't tell exactly which disk that is, but if /cdrom seems
| # to be a USB stick then (hd0) may not be safe.  If we hit either of those
| # checks, then try the disk containing /boot instead.
| # The same goes for /hd-media, so avoid installing there as well.
| cdsrc=$(mount | grep "on /cdrom " | cut -d' ' -f1)
| cdfs=$(mount | grep "on /cdrom " | cut -d' ' -f5)
| hdsrc=$(mount | grep "on /hd-media " | cut -d' ' -f1)

Unfortunately, that kind of filtering can't really work for the boot
from USB case, since no /dev/sda shows up in mount's output (or in
/proc/mounts). All we have about it is presumably:
  rootfs / rw 0 0

which isn't exactly sufficient. Otherwise, we could just insert some
“grep -v $foo” before the head/cut pair in the first line I quoted.

Another way I see would be:
 1. use /etc/fstab in /target to see whether there's a /boot there,
    and fall back to / if needed.
 2. use readlink on /dev/disk/by-uuid/$UUID to get the appropriate
    partition (say /dev/sdb1 for a full disk installation in my case),
    and get back to the actual disk (/dev/sdb).
 3. use that as the default.

Let's see whether a big red man pops up tonight with a clever(er) idea.

Mraw,
KiBi.

Attachment: signature.asc
Description: Digital signature


Reply to: