WindowsLinuxDualBoot

Convert a Windows system to dual-boot Linux on a second drive

by Philip J. Hollenback
Originally published on February 21, 2005 at Newsforge

I was recently assigned the task of converting a system running Windows XP to dual-boot Windows and Linux. The user needed to run Windows most of the time, but occasionally needed to boot Linux to run special applications. The one overriding requirement was to change the existing Windows setup as little as possible. In this case, that meant adding a second hard drive. Easy enough, right? Well, not so fast.

The computer in question was a standard white-box PC with Windows XP installed on its one hard drive. One option was to shrink the exiting Windows partition with NTFSresize and install Linux in the resulting free space. However, this was too intrusive. I did not have a backup of the data on the Windows machine, and didn't want to take the time to make one, so I was loath to do anything that could wipe it out.

So I installed and set up a new second drive, then installed Fedora Core 3 in the standard manner. When the installer asked what drive to use, I chose the second IDE drive, hdb. The other key step was to make sure the installer did not install a Linux boot loader on the primary hard drive. While having the installed do this is generally the recommended method of installing a dual-boot Linux/Windows system, I didn't want to do it because of my goal of minimizing changes to the Windows disk.

The Windows bootloader (NTLDR) can be configured to boot Linux partitions, so I decided to use it as the primary bootloader. The default boot option would remain Windows, so if the user took no action on boot, the system would go to Windows as it always had. However, if the user selected Linux in the NTLDR boot menu, it would hand off to the Linux bootloader (GRUB) on the second drive.

The Fedora installer gives you the option of placing GRUB in the master partition of the primary IDE drive (hda) or in the boot partition of the secondary IDE drive (hdb1). I instructed the installer to take the second option. Note that without extra configuration later, this setup will not boot to Linux, because whatever bootloader is on the primary drive -- in this case Windows -- will always be run.

Another option I considered was removing the primary Windows drive and placing the Linux drive in the system as the primary drive. I could then install GRUB on the Linux drive (the primary now) and configure it to also boot Windows on the secondary drive. One caveat here is you must configure GRUB to fool the Windows drive into thinking it is still the primary. Otherwise, Windows gets confused. I elected not do this type of install because it seemed more complicated than installing Linux on the second drive.

Boot sector transplant

The next step in the process is to save a copy of the Linux boot partition. This can be done either with dd in Linux or with the free Bootpart utility under Windows. Either program simply takes the first 512 bytes on the disk and puts them into a file. The dd command to do this is dd if=/dev/hdb1 of=bootsect.lnx bs=512 count=1. Once you have this file, copy it to a diskette or some other removable media so you can then copy it to the Windows drive for NTLDR.

I happened to use Bootpart because I forgot to use dd before I booted the system back to Windows. If you use Bootpart you don't have to copy the boot sector to a diskette, as you are already in Windows. To complete the transplant, place the file you created with dd or Bootpart on the Windows drive as C:\bootsect.lnx.

Now it's time to tell Windows about Linux. Again, there are two ways to go about this. If you are doing everything manually, fire up a text editor in Windows and edit the file c:\boot.ini. Add the line c:\bootsect.lnx="Linux" to the end of the file.

The Bootpart way to do this is simpler: run Bootpart with the command bootpart Linux c:\bootsect.lnx "Linux". Bootpart will take care of adding the proper entry to boot.ini for you.

Testing and final thoughts

Your system should now be correctly configured. To test it, reboot the machine. After the BIOS screen, the first thing you will see is the NTLDR menu asking which OS you wish to boot. If you do nothing you will go to Windows. If you choose Linux on this screen, NTLDR will use bootsect.lnx to hand off the boot process to Linux, and start booting from your second hard drive. The next screen you will see will be your Linux bootloader screen. From this point on, your system boots the same as any other Linux machine.

And there you have it: a Windows machine that boots Linux as well. The advantages of this setup are:

  • The Windows configuration remains essentially untouched.
  • No changes to the Windows hard drive boot sector are necessary.
  • Removing Linux from the machine is simple: physically remove the Linux disk and remove the Linux entry from boot.ini under Windows.
  • Windows users have a tendency to reinstall the OS from time to time. If that occurs on this system, the Linux disk would be untouched (although you might not be able to boot to it until you copy the boot sector again and fix boot.ini).

While this configuration isn't ideal for everyone, it is a great way to add Linux to an Windows machine with minimal disruption of an existing Windows installation.


Special thanks to Wentworth Brookes for pointing out a typo in my invocation of dd. I fixed it in this version of the article.


CategoryGeekStuff



Our Founder
ToolboxClick to hide/show