Blog | About

Adding HelenOS to existing GRUB

28 Feb 2011

Tags: GRUB and HelenOS

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:

Path to GRUB menu configuration file
GRUB device name where boot partition is (something like (hdn,k))
Directory where to copy HelenOS files (directory /boot/helenos is used by default)
GRUB path to -o directory (depending on your partition settings, it might be the same as -o or without the /boot prefix)
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:

    [ -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.


Watch comments through RSS

Add a comment

The e-mail will be used to get a Gravatar picture and will not be directly displayed.

Please, show me you are not a robot.

You can use basic HTML formatting (following tags are allowed: A, CODE, PRE, B, I, STRONG, P and BLOCKQUOTE). For replies, I recommend using the Quote button next to a post.