Add variables to grub2 for Chrome OS bringup workarounds.

This adds a temporary hack to grub2, which we're using while the full BIOS
changes aren't yet completed. We set four variables automatically that we
can use in the grub.cfg file to ensure that we get the kernel and rootfs
from the boot device, regardless of which device that is.

Grub refers to the boot device as hd0, hd1, etc. The kernel needs it to be
sda, sdb (and yes, I know that's dependent on the architecture and media,
but so is grub). In addtion, our current BIOS doesn't enumerate the hard
disk in recovery mode, so the first removable drive is hd0, not hd1. Linux
always sees it though.

Grub now sets two variables to specify the rootfs in grub's terms:

  grubpartA == (hdX,3)
  grubpartB == (hdX,5)

where X is the boot device, so we can pick the right kernel in grub.cfg:

  linux $grubpartA/boot/vmlinuz ...
  linux $grubpartB/boot/vmlinuz ...

But we also need to provide "rootfs=/dev/sdX" for the kernel.

We'll map this normally:
  (hd0) -> sda
  (hd1) -> sdb
  etc.

But if the booted media is removable, we'll map like this:
  (hd0) -> sdb
  (hd1) -> sdc
  etc.

and so grub can set two more variables:

  linuxpartA == /dev/sdX3
  linuxpartB == /dev/sdX5

and now our grub.cfg can say:

  linux $grubpartA/boot/vmlinuz root=/dev/$linuxpartA ...
  linux $grubpartB/boot/vmlinuz root=/dev/$linuxpartB ...

And this will let the same grub.cfg file work on any boot device, regardless
of how many others are plugged in or how they're numbered.

Note that once we've switched to our official BIOS we'll no longer be
needing grub at all, so this is just temporary.

Review URL: http://codereview.chromium.org/2113004
1 file changed