Tuesday, January 19, 2010

Fun with Grub2

As I posted already, I'm running Ubuntu Lucid Lynx (10.4) Alpha 2 on my EeePC 901. Working well with no serious problems.
However, it does use Grub2 and my hitherto experience has been exclusively with Grub0.97 (otherwise known as Grub1). My biggest problem with Grub2 was the stern warning on /boot/grub/grub.cfg (which is Grub2's equivalent to menu.lst) advising "Do not edit this file".
See, I do a lot of weird things in my multibooting which hitherto demanded frequent fiddling around with menu.lst

Including "non-standard" OSes in the boot menu

In particular, Grub2 did not find the Haiku OS which I have installed on my larger SSD. However, in searching around I found this that explained exactly what to do. Strangely, it wasn't that difficult and worked perfectly.
Hmmm, maybe I need to give Grub2 a shot after all.
The key steps are:
1. Edit /etc/grub.d/40_custom
2. Add this at the bottom of the file

menuentry "Haiku" {
set root=(hd1,7)
chainloader +1
}

and save the file.
Note that while disk counting starts at zero just like Grub1, in Grub2 partition counting inexplicably starts at one.
3. Now update grub using
sudo update-grub

which took over a minute for me.

Booting from USB keys with Grub2

OK, great but what about booting from usb key through Grub2.
With Grub1, I was able to boot ChromeOS (both Cherry and Zero) from usb key by (among other methods) adding
title chromeOS Cherry
root (hd2,1)
chainloader +1

to a new stanza in menu.lst.
But this didn't do anything at all when added to /etc/grub.d/40_custom even after remembering that what was hd2,1 now becomes hd2,2 in Grub2.
Googling around seemed to indicate that Grub2 doesn't "see" usb disks. Well, why the hell not?
Nevertheless, when I did an "update-grub" with the chromeOS usb key inserted, Grub2 did seem to see something as it identified as Debian Squeeze/Sid for ChromeOS Zero and as Ubuntu Karmic for ChromeOS Cherry.
However, in neither case was booting successful. In each case booting seemed to be proceding well and the initial splash showed up. Then however I got the following error message:
Not activating Mandatory Access Control now since /sbin/tomoyo-init doesn't exist

What's strange is that Grub2 didn't see anything at all when I had usb keys with either a bootable Mepis 8.0 or an equally bootable Parted Magic 4.5 was inserted.
Looks like there's more to this than meets the eye.
So how do you get an OS on a pendrive to boot when you've got Grub2 sitting in your mbr? Well, with the EeePC 901, this is easy as tapping "esc" during the early part of the boot brings up a list of bootable disks (including usb-devices) any of which can be selected to boot to.

PLoP Bootmanager

I also had a look at the interestingly-named PLoP Bootmanager
It's use in this context is explained here and mentioned here too.
After installing this bootmanager, instead of Grub you now see a new bootmenu that allows you to choose among various bootable devices including usb keys. With this I was able to boot without problem to ChromeOS Zero. Whoopee-doo!
However, in choosing the SSDs, I found that only some of the various OSes I had installed and used without difficulty before failed to boot.
So, now I had a seemingly half-assed bootmanager in my mbr and could no longer boot to Lucid Lynx.
What to do?
Why reinstall Grub2 to the mbr as explained here.
In my case I mounted my Ubuntu root directory using
sudo -i mount /dev/sdb2 /media/ubuntu

and then installed Grub2 using
sudo grub-install --root-directory=/media/ubuntu/ /dev/sda

Problem solved.
Sorry if anybody thinks I spoke harshly of PLoP above but it really seems to be more useful for older computers where USB or CDROM booting is not allowed in the BIOS. Wait, I have an older computer like that.....hmmm

Customizing the bootsplash and font colors in the boot menu

Now, when I started using Grub2, I was unimpressed by the black background to the bootmenu. Well, this is very easy to resolve as explained here.
Actually, although this article is only 10 weeks old, it's actually out of date.
The steps I took to place my own image as bootsplash (after creating a 640x480 .tga file in Gimp) were:
1. sudo apt-get install grub2-splashimages
2. Copy your .tga file to /usr/share/images/grub/
3. sudo gedit /etc/grub.d/05_debian_theme
and in the editor look for this line
WALLPAPER="/usr/share/images/********/********"
and change it to
WALLPAPER="/usr/share/images/grub/yourfile.tga"
4. Immediately underneath this line you can change either the font color (COLOR NORMAL) or highlight color (COLOR HIGHLIGHT) by replacing what's there.
The SplashImage & Theming section here provides more details including which (of a limited number of font and highlight) colors are available.

The splash images that show up on booting are sooooooo much better than those pathetic and distorted and discolored attempts we had to put up with in Grub1.

Changing the bootsplash resolution

Now, I did see in this forum post that you were not necessarily confined to the default 640x480 pixel image.
As my screen resolution is 1024x600 on the EeePC 901, I tried that.
OK, the bootmenu was different and the font size quite a bit smaller. So, seems to have worked, right?
Well, no as Ubuntu would no longer boot (or maybe for some reason it booted but nothing was visible on the screen).
The other OSes were all bootable and I tried various stratagems to recover the situation including copying copying /etc/default/grub from the Live USB to the Ubuntu install. Then I tried to "update-grub" from another OS using chroot.
However, this bombed out immediately claiming that /dev wasn't mounted.
Also tried to boot to Ubuntu in recovery mode (despite having asked for no recovery options to appear in the boot menu). Here you can punch "e" to edit the boot menu but instead of "esc" to go back to boot menu as in Grub1, now you need to hit "ctrl-x". Unfortunately, this ran into a "nothing visible" problem too.
I then tried to re-install grub2 into Ubuntu (and mbr) from the LiveUSB as mentioned above. This worked but didn't resolve the problem.
So, nothing for it boot to re-install Lucid which I did.
Oh well, you have to expect this if you insist on experimenting.
Nevertheless, I'm now less afraid of Grub2 and am willing to get to explore it a lot more.

No comments:

Post a Comment