2011-02-28

Adding HelenOS to existing GRUB

Last week we started testing our USB drivers on real hardware. That involves a lot of quick fixes, followed by burning the CD image (or creating bootable USB disk) and rebooting the computer. Not very comfortable. So I decided to polish my script for adding HelenOS to existing GRUB and make it available for everyone.

The script is intended for PC platform and all it does is that it copies HelenOS kernel image to directory where existing GRUB can find it (i.e. the GRUB that is used to boot on real hardware) and adds a menu entry to GRUB.

The usual disclaimer - the script is provided as is. I have used it on my PC and it worked. However, it modifies boot loader files and double checking them before rebooting is more than recommended. Otherwise, you may end up with computer that will not boot at all.

You can download the script here. I placed it in /usr/local/sbin and created sudo entry for it (it needs root privilege to modify /boot directory where GRUB usually resides).

The script can modify GRUB menu in two ways. First, it can append the HelenOS entry to it or replace existing HelenOS entry. I prefer the latter because I do not need to modify the menu file manually at all. In order to use the replacing version, you need to add following two lines to your GRUB menu (usually /boot/grub/menu.lst or /boot/grub/grub.conf). Configuration needed for booting HelenOS will be placed between them.

### HelenOS automatic install start
### HelenOS automatic install end

Once you have done that, you can install HelenOS to it. Build HelenOS and run the script with -h parameter. It will display quite verbose help together with guessed values of several important parameters. If the guesses looks okay, you can proceed to actual installation. I use following command:

sudo /usr/local/sbin/helenos_add_to_grub \
    -c -r -t "HelenOS (USB support)"
This replaces existing entry in GRUB (-r), removes files from previous install (-c) and sets a nice title. The script produces following output informing about performed actions:
==> Cleaning previous install ...
  --> rm -rf /boot/helenos
==> Creating GRUB HelenOS directory ...
  --> mkdir -p /boot/helenos
==> Installing HelenOS kernel and modules ...
  --> cp -R REPO-PATH/boot/distroot/boot /boot/helenos
==> Updating HelenOS GRUB menu ...
==> Backing-up current GRUB menu ...
  --> cp /boot/grub/menu.lst /boot/grub/menu.lst.bak
==> Replacing HelenOS entry in GRUB menu ...
==> Adding HelenOS to GRUB completed.

If you are not using standard locations of GRUB, you can use following parameters to change them:

-g
Path to GRUB menu configuration file
-d
GRUB device name where boot partition is (something like (hdn,k))
-o
Directory where to copy HelenOS files (directory /boot/helenos is used by default)
-O
GRUB path to -o directory (depending on your partition settings, it might be the same as -o or without the /boot prefix)
-b
Where is the boot dir of HelenOS build (REPO_DIR/boot/distroot/boot)

Ideas for improvements are welcomed. Patches with these improvements even more so.

UPDATE: New version supporting GRUB2 can be downloaded here. It also fixes bad usage of getopt. Using it with GRUB2 is quite easy, difference is that as a GRUB configuration file is taken HelenOS file in /etc/grub.d/.

I tested the updated script on Ubuntu in VirtualBox and adding following lines to Makefile in root directory of HelenOS (USB branch checkout) allowed me smooth install:

install-to-grub:
    [ -e "image.iso" ]
    sudo /usr/local/sbin/helenos_add_to_grub \
        --grub2 --title "HelenOS (USB)" \
        -g /etc/grub.d/35_helenos_usb \
        -o /boot/helenosusb -O /boot/helenosusb
    sudo update-grub

Advantage of having GRUB2 is that you can have more entries and removal is pretty simple (just remove entry in /etc/grub.d and run update-grub).

Still, be careful. Your GRUB installation may use slightly different settings. Verify that the /etc/grub.d/35_helenos file looks okay, try to run it to see that it produces reasonable output before running update-grub. Before rebooting double check /boot/grub/grub.cfg.

3 komentáře:

  1. Hi Vojta,

    in your opinion, is this something that could be added to the main Makefile so that you can type for instance make grubinstall which will invoke your script?

    Another question is. If my Ubuntu uses grub2, will this eat my computer :-)?

    Jakub

    OdpovědětVymazat
  2. Hi Jakub,

    I am really not sure about adding this to the main Makefile. It needs root privileges and it relies on being run on the correct platform etc. Plus, this can break the system if you supply wrong arguments (or the guesses won't be accurate) and such thing should be kept separate from main Makefile and shall be more difficult to launch. Just my opinion, though.

    This will not work with GRUB2 as new GRUB uses completely different format of the menu. But I am just upgrading my virtual machine with Debian to have GRUB2 and I will see what I can do.

    OdpovědětVymazat
  3. Added new version supporting GRUB2.

    Jakub: I guess you can try the new version but, please, read the warnings first.

    OdpovědětVymazat