By making 100 MB available for Windows to create a primary partition with boot essentials, I was able to get it happily installed in a logical partition without even disturbing my Gentoo Linux installation.

Almost 10 years since I removed Windows from my computer and gave the whole hard drive to Gentoo Linux, I had a specific reason to put it back on. Naturally I’ve gone through a few computers in the last decade, but the flexibility of Gentoo has enabled me to transfer my Linux installation across numerous hard drive upgrades and computer changes. I have not been in the habit of leaving hard drive space for any secondary operating system. At first I feared I would have to do a full backup and then restore my system to a new set of partitions, but found a much quicker solution where the hardest part was persuading Windows to install on a logical partition.

I have developed the habit of keeping my /usr/portage directory on its own partition (coincidentally the end of the drive) so that the huge number of file writes that occur during a Portage sync don’t have a chance to corrupt or fragment my main system partitions. Happily, I discovered that this partition was just large enough to fit Windows 7. I was able to copy the /usr/portage contents over to my root partition (where they would “normally” reside anyway) and with no further impact on my Linux installation there was free space for Windows. This is one of the less commonly acknowledged reasons why having a Linux system split over a few partitions can be wise.

Windows would not install on the space I made for it, and I quickly discovered (on the web, not from the uncommunicative Windows installer) that the problem was the type of partition. Because I have numerous partitions, I had made a small primary partition for /boot and then put the rest into an extended partition. The space I had cleared for Windows was thus a logical partition. I didn’t want to mess with the extended partition, even with a “safe” resizing tool.

This installation guide for Windows 7 suggested that it could be done on a logical partition as long as Windows had space to create a small primary boot partition (just like I had set up for Linux). To try this all I had to do was resize my 256 MB /boot partition, which was trivial to backup. I made almost 200MB available as completely empty space, and Windows loved it. When I checked subsequently it turned out that Windows only needed 100MB of primary partition as can be seen in the gparted screenshot. Windows 7 can indeed be installed to a logical partition.

Of course the Windows installer clumsily wrote over the Master Boot Record on the disk, replacing GRUB and making it impossible for me to boot into Linux. This is easy to fix with a Linux bootable USB drive. I used the Gentoo liveCD image, mounted my own partitions, chrooted into my own system, and reinstalled GRUB to the MBR. Adding the lines

title=Windows 7
root (hd0,1)
chainloader +1

to my grub.conf file made it possible to reach either operating system at boot.

Linux is so good for that sort of thing. I just helped a friend at uni do a gentoo install. He was very impressed that you could stop the installation at any point and just chroot back into it later. Technically, of course, you can do that with any Linux distrobution, but only gentoo users seem to know about chroot.