Multi-boot configuration for Vista, Windows XP, Linux

I bought my (Dell) notebook with Windows Vista preinstalled. Because some of my customers stay loyal to Windows XP and I prefer Linux for flexibility, I wanted to also install both of these OSes on the same disk, so as to have a choice of each operating system through the GRUB boot menu (Linux being the dominant OS and the other two secondary choices). This article contains a record of my installation with some warnings and explanations mixed in, unlike those "easy" HOWTOs that omit the gory details and leave you wanting if anything goes wrong in the process or your preconditions differ slightly.

First of all, it is important to note that the final configuration which I settled upon does not include all three OSes within a single GRUB boot menu. Instead, the menu contains two categories of items: Linux (one item per kernel configuration) and Windows (just one item for booting either Windows XP or Vista). The Windows menu item instructs GRUB to delegate control to Vista's own boot loader, which then offers a second choice between Vista and XP.

The entry for the Windows menu item in /boot/grub/menu.lst is trivial:

title           Windows Vista/XP
root            (hd0,2)
chainloader     +1

The partition table in the final configuration looks as follows - (hd0,2) in GRUB-speak refers to /dev/sda3:

  Device Boot      Start         End      Blocks   Id  System
/dev/sda1               1          23      184716   de  Dell Utility
/dev/sda2              24        1069     8401995    7  HPFS/NTFS
/dev/sda3   *        1070        7494    51602432    7  HPFS/NTFS
/dev/sda4            7495       29863   179678992+   5  Extended
/dev/sda5   *        7495        9925    19526976   83  Linux
/dev/sda6            9926       10411     3903763+  82  Linux swap / Solaris
/dev/sda7           10412       29863   156248158+  83  Linux

/dev/sda1"Diagnostics" partition; this is a small FAT16 partition preinstalled by Dell. It contains programs for testing memory etc.
/dev/sda2The Windows XP partition; originally the same block range used to hold a ~10 GB "recovery" partition, which was apparently too small for Vista for its intended purpose.
/dev/sda3The Windows Vista partition; originally it occupied the rest of disk and had to be shrunk to make room for Linux.
/dev/sda4The extended partition which holds /dev/sda5, /dev/sda6, /dev/sda7. It is very important to create this partition because any disk can only hold 4 primary partitions. If you forget this little quirk, you will likely end up with large amounts of unpartitioned (that is, unusable) disk space.
/dev/sda5The Linux boot/root partition.
/dev/sda6The Linux swap partition.
/dev/sda7The Linux "data" partition, which in my case holds an encrypted file system for /home and /usr/local (not quite relevant)

The non-trivial part of the setup concerns the order of installation and the steps required to make both boot managers work correctly. The same approach might be used to install in a different order. The key piece of information to keep in mind is which step overwrites which boot records.

  1. Before installing anything, I made snapshots of the Master Boot Record (/dev/sda) as well as of each partition's initial sectors using a Knoppix CD. After booting from the CD, I issued commands like dd if=/dev/sda1 of=/path/to/sda1/backup/file bs=512 count=32 for each partition and the main MBR. To store the backup files, I used the /dev/sda1 "diagnostics" partition. A USB stick could be used just as well. I heuristically chose to back up the first 32 sectors of each partition, not being sure how many of them really need to be protected. This number has later turned out sufficient.
  2. I began by resizing Vista's own partition using Vista's disk management tool. It didn't allow me to go below 50 GB. I used the same tool to delete the /dev/sda2 "recovery" partition in order to create a gap for installing Windows XP. (By the way, an attempt to use the Partition Magic tool to scale down Windows XP below 40 GB and move it to the beginning of disk resulted in an unbootable system; now I believe PM can't deal at all with Vista.)
  3. I installed Windows XP, creating a new partition for it during the installation process. Actually, I had to first create a custom Windows XP installation CD based on the original one, in order to include some missing SATA disk drivers. The Windows XP installer did not just alter the MBR, but it also overwrote the beginning of the Vista's /dev/sda3 partition. Accordingly, I was unable to boot Vista after this step (instead Windows XP booted itself).
  4. Using the Knoppix CD, I created another set of boot sector backup files (just in case; those were not used later on).
  5. I proceeded to install Linux (Debian), taking care to use the "expert mode" to create an extended partition. (It later turned out that fdisk is too dumb to expand this partition in order to accommodate new logical partitions; I recommend cfdisk instead.)
  6. At this point, I had a configuration which booted Linux, and (if I recall correctly) Windows XP, based on an entry in GRUB's menu.lst created by the installer - the same entry I pasted in the beginning of this post.
  7. Having booted into Linux, I created another set of boot sector backup files (again, just in case).
  8. The really interesting part begins now. To "revive" Vista's boot loader, I restored with dd the 16KB backup of Vista's partition I made in Step 1. This left me being able to boot Linux and Vista, but not Windows XP. (It is noteworthy that partition numbering changes when you delete a partition. For example, /dev/sda1, /dev/sda2, /dev/sda3 became /dev/sda1, /dev/sda2 after deleting the "recovery" /dev/sda2 partition. The original ordering was restored after installing Windows XP into /dev/sda2, though.)
  9. In Vista, I installed the free EasyBCD tool, which lets you edit Vista's own boot loader entries. Here I added a "Windows XP" menu entry and pointed it to the partition with Windows XP (which is called D: from Vista's own perspective).
  10. At this stage, my attempts to boot into Windows XP using Vista's boot loader failed with an error message about missing NTLDR. To fix this, following advice from the EasyBCD forum, I booted into Vista and copied c:\ntldr.dll to Windows XP's d:\ntldr.dll (where it was, in fact, missing). In order to see the file c:\ntldr.dll in Vista, I had to tweak some settings regarding displaying hidden and system files.

Having completed all of the above steps, I was able to boot all three OSes - Linux directly using GRUB, and the two versions of Windows by redirecting GRUB into Vista's boot loader. It might not be the nicest possible configuration (requires a few extra key strokes during the boot process), but it works.

No comments:

Post a Comment