November 19, 2004

Boot-managing your Linux+Windows box

Author: Preston St. Pierre

Operating system tinkerers have learned to their displeasure that installing Windows after Linux on a system with a dual-boot configuration disables access to Linux. Here's how to get the system up and booting in no time.

Every system with more than one operating system installed needs a boot manager -- a piece of software that allows users to choose which operating system they wish to use. The boot manager generally resides in the master boot record (MBR) of the hard disk.

The most popular boot managers that come with Linux distributions are LILO (LInux LOader) and GRUB (GRand Unified Bootloader). Lately many distributions, such as Fedora, are encouraging the use of GRUB.

If you install or re-install Windows on a system that already has Linux installed, the Windows bootloader will replace GRUB or LILO in the MBR, so that after you are done installing, you will simply boot into Windows. This doesn't mean your Linux distribution has been erased or uninstalled; it simply means that your current bootloader is unaware of where to find it. It's up to you to tweak the system to get your boot manager back.

Rescuing GRUB

If you were using GRUB as your boot manager, you just need to reinstall it. Use the first installation disk of the distribution you had installed. Pop it in your drive and, if necessary, change the boot order in your BIOS to boot off the CD-ROM drive. Reboot, and at the boot prompt, enter:

boot: linux rescue

Let the installer load itself into the rescue mode. When the installer asks you which partition holds the distribution that has to be rescued, select the appropriate partition. The installer will finally mount this partition at /mnt/sysimage and drop you to the shell. To re-install GRUB you need to be 'in' the distribution's environment, so enter the command chroot /mnt/sysimage, then install GRUB in the MBR with the command grub-install /dev/hda.

Press Ctrl-D twice to log out and restart. Voila -- there's GRUB. But where's Windows?

Well, now you have to tell GRUB where it can find Windows. Boot into Linux, log in as root, and issue the fdisk -l command. You should see output similar to the following:

Disk /dev/hda: 40.0 GB, 40020664320 bytes
255 heads, 63 sectors/track, 4865 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/hda1   *           1         255     2048256    6  FAT16
/dev/hda2             256        3545    26426925    f  W95 Ext'd (LBA)
/dev/hda3            3546        4865    10602900   83  Linux
/dev/hda5             256         893     5124703+   b  W95 FAT32
/dev/hda6             894         959      530113+  82  Linux swap
/dev/hda7             960        1724     6144831   83  Linux
/dev/hda8            1725        2010     2297263+  83  Linux
/dev/hda9            2011        2270     2088418+   b  W95 FAT32
/dev/hda10           2271        2780     4096543+   b  W95 FAT32
/dev/hda11           2781        3545     6144831   83  Linux

Note the device values corresponding to the partition in which you installed Windows. Edit the file /etc/grub.conf and append the following lines, substituting hd0 for hda (or hd1 for hdb and so on). The partition number, specified after the comma below, should be one less than the number you noted. This tells GRUB on which disk and in what partition is Windows installed.

title Windows
	rootverify (hd0,0)
	chainloader +1

Save the file and reboot. This time GRUB will show the Windows entry (as specified next to title in the configuration file).

Rescuing LILO

The process of reclaiming LILO is similar to the one for GRUB. Boot from the first installation disk. Enter the rescue mode as described above. Mount the "to-be-rescued" system under /mnt/sysimage and chroot to it as shown.

If you lost LILO because you re-installed Windows, just issuing the /sbin/lilo command should do the trick. If you lost LILO because of a fresh installation of Windows, issue the fdisk -l command and note the device values next to the partition into which you installed Windows, then edit the file /etc/lilo.conf and append these lines to the end:


Use your device values instead of the /dev/hda1 above.

Save the file and issue the /sbin/lilo command. You should see a list of entries that LILO adds to the boot list. Windows (or whatever you specified as the label) should be listed as well.

Now you can reboot, and when the system comes up again, both operating systems should appear on the boot menu.

If you have a choice, which boot manager should you use? Trust me when I say there are as many GRUB vs. LILO battles as there are GNOME vs. KDE, but unlike the latter you can use only one boot manager per machine.

There are various other tricks you can do with boot managers, such as putting up an animated screen instead of simple text. Take some time to go through the configuration files of whichever boot manager you use. Read their documentation to fully understand and appreciate their power and usefulness.

Click Here!