Dual-Booting Linux and Windows 2000/XP/Vista

As mentioned earlier, when you run Windows, its boot loader expects to be the one in charge; therefore, the standard way to dual-boot Windows and Linux is to add Linux as an option on the Windows boot menu. This section describes how to do that. The information provided here applies to Windows 2000 and Windows XP, which use the Windows NT loader ntldr (so called because it was developed for Windows NT). Windows Vista uses a different boot loader. If you want to set up Vista to dual-boot Linux, you can use the free download EasyBCD by Neosmart Technologies (neosmart.net).

Note again that you do not need the information in this section if your Linux installation software set up the dual-booting for you, which it probably did.

To set up dual booting with the NT loader manually, you need to provide the loader with a copy of the Linux boot sector. We’ll describe how to do that on a computer running Windows with an NTFS filesystem (note that Windows should be installed on your system already). See the “Linux+NT-loader” mini-HOWTO for more information and other alternatives.

You should have a Linux boot floppy or CD available so that if necessary you can boot Linux before the Windows boot loader has been modified. You should also have a DOS-formatted floppy to transfer the boot sector to the Windows partition. If you are running LILO and it is already installed, you may need to modify /etc/lilo.conf as described later. Otherwise, install LILO or GRUB to the boot sector of the Linux partition; once the Linux boot manager is installed and you have a configuration file, you can set up the system for dual booting.

The following instructions assume your Linux partition is on /dev/hda2. If Linux is on another partition in your system, be sure to replace /dev/hda2 in the following examples with the correct partition. The instructions also assume that you have a floppy drive to make a diskette for transferring the boot sector to your NTFS filesystem. If you don’t have a floppy drive, you will have to use some other means of doing the transfer. If you have a FAT partition, you can mount that on Linux and transfer the file there. Other possibilities include putting it on a CD, transferring it over a network to another system while you reboot to Windows, or even emailing it to yourself and reading it from the Windows side.

  1. If you are running LILO, specify the Linux root partition as your boot device in /etc/lilo.conf. If you are editing /etc/lilo.conf manually, your entry will look like this:

    boot=/dev/hda2

    and will be the same as the root= entry.

    If you are running GRUB, make sure your configuration file, /boot/grub/menu.lst, includes a menu entry for booting Linux. The exact values of the entries in the menu depend on the filename of the kernel image that you wish to boot. For example:

    title Linux 2.6.28
    root (hd0,1)
    kernel /vmlinuz-2.6.28 ro root=LABEL=/
    initrd /initrd-2.6.28

    You can then skip to Step 3.

  2. Run the lilo command to install LILO on the Linux root partition.

  3. At this point, if you need to reboot Linux, you’ll have to use a boot floppy or CD because the NT loader hasn’t been set up yet to boot Linux.

  4. From Linux, run the dd command to make a copy of the Linux boot sector:

    $ dd if=/dev/hda2 of=/bootsect.lnx bs=512 count=1

    This command copies one block, with a block size of 512 bytes, from the input file /dev/hda2 to the output file /bootsect.lnx. Note that if you are running GRUB, the boot sector is actually the stage1 file. (The output filename can be whatever makes sense to you; it doesn’t have to be bootsect.lnx.)

  5. Copy bootsect.lnx to a DOS-formatted floppy disk if that is how you are going to transfer it to Windows:

    $ mount -t msdos /dev/fd0 /mnt
    $ cp /bootsect.lnx /mnt
    $ umount /mnt
  6. Reboot the system to Windows and copy the boot sector from the floppy disk to the hard disk. You can drag and drop the file to the hard drive, or use the command line to copy the file, as in the following example:

    C:> copy a:\bootsect.lnx c:\bootsect.lnx

    It doesn’t matter where on the hard drive you put the file because you’ll tell the NT loader where to find it in step 8.

  7. Modify the attributes of the file boot.ini[4] to remove the system and read-only attributes so you can edit it:

    C:> attrib -s -r c:\boot.ini
  8. Edit boot.ini with a text editor to add the line:

    C:\bootsect.lnx="Linux"

    This line adds Linux to the boot menu and tells the NT boot loader where to find the Linux boot sector. You can insert the line anywhere in the [operating systems] section of the file. Its position in the file determines where it will show up on the boot menu when you reboot your computer. Adding it at the end, for example, results in a boot.ini file that looks something like this (the second multi(0) entry is wrapped to fit the margins of this page):

    [boot loader]
    timeout=30
    default=multi(0)disk(0)rdisk(0)partition(1)\WINNT
    [operating systems]
    multi(0)disk(0)rdisk(0)partition(1)\WINNT="Windows NT Server Version 4.00"
    multi(0)disk(0)rdisk(0)partition(1)\WINNT="Windows NT Server Version
    4.00 [VGA mode]" /basevideo /sos
    C:\bootsect.lnx="Linux"

    If you want Linux to be the default operating system, modify the default= line:

    default=C:\bootsect.lnx
  9. Rerun attrib to restore the system and read-only attributes:

    C:> attrib +s +r c:\boot.ini

Now you can shut down Windows and reboot. Windows will prompt you with a menu that looks something like this:

OS Loader V4.00
Please select the operating system to start:
Windows NT Workstation Version 4.00
Windows NT Workstation Version 4.00 [VGA mode]
Linux

Select Linux, and the NT loader will read the Linux boot sector and transfer control to LILO or GRUB on the Linux partition.

If you are using LILO and you later modify /etc/lilo.conf or rebuild the kernel, you need to rerun the lilo command, create a new bootsect.lnx file, and replace the version of bootsect.lnx on the Windows partition with the new version. In other words, you need to rerun steps 2–6.

Tip

If you have any problems or you simply want to remove LILO or GRUB later, you can reverse the installation procedure: boot to Windows, change the system and read-only attributes on boot.ini, re-edit boot.ini to remove the Linux entry, save the file, restore the system and read-only attributes, and remove the Linux boot sector from the Windows partition.



[4] boot.ini is the Windows counterpart to /etc/lilo.conf. It defines which operating systems the -Windows loader can boot.

Get Linux in a Nutshell, 6th Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.