Give LILO the Boot and Grab Some GRUB

I was going to go off on a cute riff about “Lilo and Stitch,” but after enduring a rant from a friend about how the movie had NOTHING to do with bootloaders, I reckon I’ll just stick to the point. Darned over-literal geeks anyway.

If you’re still lumbering along with the antique Linux Loader LILO, you really ought to consider migrating to GRUB, the Grand Unified Bootloader. LILO is quite good, and, as the saying goes, if it ain’t broke …. But GRUB has some advantages that make it, in my opinion, the Bootloader of today’s generation. Here’s why:

  • There’s no need to reinstall GRUB with every kernel change
  • GRUB does not need to be restarted after making configuration changes
  • GRUB has its own command shell, for making changes on the fly
  • GRUB reads file systems and kernel executables, rather than inflexibly restricting the
  • user to disk geometry

  • You can boot from a GRUB floppy disk
  • You can boot bare kernels, passing in modules and parameters from the command line
  • You can download OS images over the network

First, you’ll need to know a few things about your system:

  • Partition table
  • Location of Linux kernel (usually /boot/something) and the partition it is on
  • As always, back up your data and have a rescue disk, like Knoppix, at hand
  • Take a look in your /boot directory — this is where much of the GRUB action happens, so take a minute to look at what files are in here. This will remove much mystery later.
  • Make a hard copy of your lilo.conf, it contains information you need. For extra insurance in case things go majorly haywire, backup your existing MBR:

    # dd if=/dev/hda of=/archive/hda.mbr bs=512 count=1

    The output file (of=) can be anywhere you like. It is perfectly safe to copy it to a file on the same system, as long as you have a bootable rescue disk. Except don’t copy it into /tmp– on most systems, this is cleaned out at reboot.

    Continued on Page 2: Installation
    Continued From Page 1

    First, install GRUB. Build from sources, install from packages, I care not, just install it however you choose. So far, you are not fully committed — just installing it to your system does not install it to the MBR.

    Next, find out where in the heck your particular Linux parked the GRUB boot image files. The official location is /usr/lib/grub/$ARCH. Red Hat does /usr/share/grub/$ARCH. Like herding cats, is Linux. This is where you find all those stage1, stage1_5, and stage2 thingies.

    Installation From A GRUB Floppy
    This is the way to install GRUB to the MBR, and create a boot floppy at the same time. Change to your /grub/$ARCH directory, and copy the stage1 and stage2 boot images to a floppy disk:

    # dd if=stage1 of=/dev/fd0 bs=512 count=1
    # dd if=stage2 of=/dev/fd0 bs=512 seek=1

    Now reboot to the floppy disk. You should be greeted by the nice blue GRUB screen:

    GRUB version 0.93 (640K lower / 3072K upper memory)

    [ Minimal BASH-like line editing is supported. For the first word, TAB
    lists possible command completions. Anywhere else TAB lists the possible
    completions of a device/filename. ]


    First, find the location of the boot files:

    grub> find /boot/grub/stage1

    Now set the root device:

    grub> root (hd0,0)

    A Digression Into Partition Numbering
    GRUB uses its own unique partition numbering scheme; it starts from 0. hd0,0 means the first partition of the first drive, or hda1. Both SCSI and IDE drives are represented by hd. GRUB numbers sequentially, from zero:

    hda2     hd0,1
    hda3     hd0,2
    hda4     hd0,3

    But that’s not all. Remember, the standard Linux partition table is like this:

    1-4      primary partitions
    5-up      extended partitions

    In GRUB, it’s like this:

    0-3      primary partitions
    4-up      extended partitions

    Additional drives are hd1, hd2, etc.

    Continued on Page 3: Completing the Installation

    Continued From Page 2

    Completing the Installation
    Now install GRUB to the MBR. This is the point of no return. Well, not really, because you can always restore the MBR from your backup. Isn’t Linux cool?

    grub> setup (hd0)

    This installs it to the first sector of the first drive.

    Now we must finish booting. If you already know the location of your kernel, now is the time to use it:

    grub> root (hd0,0)
    grub> kernel /boot/vmlinuz-2.4.21 root=/dev/hda1 ro
    grub> boot

    Let’s dissect the kernel line, as it is a source of confusion and woe for GRUB newbies. /boot/vmlinuz-2.4.21 is simply the location of the kernel you want to boot. You can have as many different kernels in /boot as you want, and select the one you want to use at boot time.

    root=/dev/hda1 Now GRUB wants to use the /dev name, I don’t know why. Just give it what it wants.

    ro is read-only- always append this to any Linux kernel line.

    Then type the boot command, and away you go.

    The Dog Ate lilo.conf
    You can discover the kernel and root information from the GRUB command line, with tab-completion. Type

    grub> root (hd0,

    and hit the tab key. Stuff will appear:

     Possible partitions are:
       Partition num: 0, Filesystem type is ext2fs, partition type 0x83
       Partition num: 1, Filesystem type is ext2fs, partition type 0x83

    Well, which one is it? It’s trivial to try both. Type

    grub> root (hd0,1)
    Filesystem type is ext2fs, partition type 0x83

    Then search for the kernel image, type:

    grub> kernel /boot/vmlinuz root=/dev/hda1 ro

    and hit the tab key. If there is no /boot directory, GRUB will tell you:

    Error 15: File not found

    So, just do it over:

    grub> root (hd0,0)
    Filesystem type is ext2fs, partition type 0x83
    grub> kernel /boot/vmlinuz
    possible files are: vmlinuz vmlinuz-2.4.21


    grub> kernel /boot/vmlinuz-2.4.21
    grub> boot

    and away you go.

    Weirdo Kernel Names
    vmlinuz is the traditional name for Linux kernels, but they can be named anything at all- fred, kernel-mustard, my-frikken-kewl-kernel, anything at all. To be sure of catching all possible kernels in /boot, widen your search:

    grub> kernel /boot/

    and hit the tab key. This will list all the files in /boot.

    Making The Changes Permanent
    You probably don’t want to do this every time you boot up, so find your GRUB configuration file, and make all this stuff happen automatically. In Debian, /boot/grub/menu.lst. In Red Hat, /boot/grub/grub.conf. Our entry looks like this:

    title       Libranet GNU/Linux, kernel 2.4.21
    root       (hd0,0)
    kernel       /boot/vmlinuz-2.4.21 root=/dev/hda1 ro

    The title is anything you want.

    But What About LILO?
    You can leave LILO on your system, or remove it, as you like. GRUB owns the MBR now, so LILO is in retirement.

    Words to Live by
    “Thus far, you have been adrift in the sheltered harbor of my patience.” From Lilo & Stitch, to show it’s worth watching, even though it has no bootloaders.

    GRUB manual. This is the official manual, and it’s quite good.
    For more information on building and booting custom kernels, see my previous fab articles:
    Tips for Compiling and Installing a Linux 2.6 Kernel
    The Linux 2.6 Kernel Trilogy Ends: Go Configure

    See All Articles by CrossNodes contributor Carla Schroder

    Latest Articles

    Follow Us On Social Media

    Explore More