Previous Section  < Day Day Up >  Next Section

Recipe 12.2. Migrating from LILO to GRUB

12.2.1 Problem

You've read the advantages of GRUB in the previous section. You are using LILO and would like to replace it with GRUB, preferably without needing to overhaul your entire system.

12.2.2 Solution

GRUB can be installed without disrupting anything.

First, install GRUB, or upgrade to the latest version. To get the version number, use:

$ grub —version

grub (GNU GRUB 0.94)

Then, take a few preparatory steps:

  1. Make a hard copy of your partition table (fdisk -l | lpr).

  2. Make a hard copy of lilo.conf.

  3. Back up your data and have a rescue disk, like a LILO boot diskette or Knoppix, at hand.

  4. Leave your LILO installation intact, in case you want it back.

Next, follow these steps, in order:

  1. Create a GRUB boot diskette.

  2. Install GRUB to the MBR.

  3. Boot the system.

  4. Edit GRUB's configuration file, menu.lst.

To create a boot floppy, find the /grub/i386 directory. The official location is /usr/lib/grub/i386-pc. Red Hat uses /usr/share/grub/i386-pc, and other distributions may vary as well. Copy the stage1 and stage2 files to the diskette with dd:

$ dd if=stage1 of=/dev/fd0 bs=512 count=1

1+0 records in

1+0 records out

512 bytes transferred in 0.550740 seconds (930 bytes/sec)

$ dd if=stage2 of=/dev/fd0 bs=512 seek=1

209+1 records in

209+1 records out

107250 bytes transferred in 6.889581 seconds (15567 bytes/sec)


Now reboot to the diskette. You will 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. ]



Next, you need to find the root device, which is the partition that contains GRUB's first- and second-stage boot files:

grub> find /boot/grub/stage1


This value is our root device. Set the root device:

grub> root (hd0,0)

Note that GRUB has its own partition numbering scheme. hd0,0 is the same as /dev/hda1. (See the "Discussion" section of this recipe for details.)

Now install GRUB to the MBR, which is the first sector of the first drive:

grub> setup (hd0)

Now it is time to finish booting. Again, set the root device:

grub> root (hd0,0)

Next, enter the path to the kernel and the path to the root filesystem. These are in lilo.conf. Be sure to append ro, to mount the kernel and root filesystem read-only:

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

Don't confuse "root" on the kernel line with the root device. "Root" on the kernel line identifies the root filesystem. The root device is the partition containing the /boot directory.

This step applies only to systems that require a ramdisk to boot. Enter the path to the initrd image, which should also be in lilo.conf:

grub> initrd /boot/initrd-2.4.21.img

Finally, enter the boot command, and the system should start normally:

grub> boot

If your root and kernel parameters do not work, see Recipe Recipe 12.7 for how to find them from the GRUB command shell.

Now you'll probably want to create the GRUB boot menu. See Recipe 12.9 for details.

12.2.3 Discussion

Always test your rescue disks before you need them.

GRUB uses its own partition numbering scheme; it starts from 0, instead of 1. Both SCSI and IDE drives are represented by hd. Floppy drives are fd.

This is the Linux partition table:

Primary partitions
5 and up
Extended partitions

In GRUB, it's like this:

Primary partitions
4 and up
Extended partitions

Additional drives are hd1, hd2, and so on. So hd0,3 is the same as /dev/hda4; hd1,5 is /dev/hdb6.

Note that the root device uses GRUB's numbering system:

grub> root (hd0,0)

and the root filesystem, which is specified on the kernel line, does not:

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

12.2.4 See Also

    Previous Section  < Day Day Up >  Next Section