1. Introduction

You need Windows for a program you use for work, your favorite game runs only on Windows or you are a developer that works on some cross-platform project. And of course, you can't even think about giving up your favorite OS. Whatever the reason, you need Windows and a virtual machine won't cut it so all you're left with, if you don't have a spare machine, is dual-boot. I usually recommend against multiple-boot machines, but I can't argue with the fact that here are situations when the idea is very useful. So this is what this article is about: making sure you need a dual-boot system, acknowledging the requirements, making backups if need be and proceed. You are expected to have some experience in installing Windows as well as Linux, at least Ubuntu in this case, and some courage. But first let's make some concepts clear.

2. Concepts

We don't want to lie to you: any task that involves advanced partitioning schemes isn't for the faint of heart. But it isn't rocket science either, and we're here to help you. Various operating systems have various partitioning schemes but since the partitioning concepts of the PC are so "smart", there are some things you should know. Every OS that I know of that is installable on the PC requests a primary partition to boot from. Linux is the most flexible in this respect, as you can have its' /boot or / on a logical partition, but I'm not so sure if your BIOS will be able to boot from it. Windows, Solaris and the BSDs absolutely demand primary partitions, with Windows being the most "oppressive" in that respect. So whenever you install a dual-boot system with Windows involved, install it first, as it won't ask you and overwrite the MBR. If you want to dual-boot Linux and BSD or Solaris, install Linux first. Now that we settled this, we will insist you make backups if you have other partitions on the target disk, and you still need them. Our setup will start with a blank drive, and we'll show you how it's done.

3. Installing Windows 7

As said, you need to install Windows first, and this is more than an advice, and it doesn't apply only to Windows 7 either. We suggest you don't try over-complicated setups, because your chances of having a system actually up and running in decent time are decreasing rapidly that way. Take note that this article is not a step-by-step how-to on installing Windows 7 and/or Ubuntu. We will only refer to the parts that involve partitioning for a successful dual-boot experience. So, when you will get to Windows' partitioning screen, here's a screenshot for you to get an idea:

Windows 7 partitioning

So, since Windows asks for a minimal primary partition size of more than 12 GB (!) , I gave it that, it auto-created it's system one and left me the rest of the disk empty and blank. After installing finished successfully, I was prepared for the tricky part: installing Linux. No, I'm just kidding, it's as simple as it can be.

4. Installing Ubuntu

We chose Ubuntu for it's popularity, but the idea is the same regarding of distribution: sda1 and sda2 are Windows, sda3 is Linux / or /boot, marked as bootable (very important!) and the rest of the disk is yours to use as you please. This only applies if using Win7, because Windows XP, for example, doesn't ask for a separate system partition, so you have another primary partition available for yet another operating system. Maybe there's a way to do without a system partition in Windows 7, but I'm not a Windows guru, so if anyone knows, tell us.

So, pop your Ubuntu 11.10 CD into the drive and boot from it, being aware that this tutorial is also applicable to older versions, such us LTS version of Ubuntu Lucid Lynx 10.04, as long as they offer GRUB 2. When you arrive at the partitioning screen, it will let you know it found another OS installed so choose "Install Ubuntu alongside", and the next screen should look like this:

Ubuntu partitioner

So, use "Add" for creating that bootable /boot or / partition I was telling you about, don't forget a swap partition and continue with some other partitions if you need them, but make sure the aforementioned partition is primary and marked as bootable. Ubuntu will install GRUB inside the MBR when you choose /dev/sda as its' target (yes, this setup assumes a single disk machine), which will detect the Windows boot code automatically and create an entry in its' menu, as you see below:

Ubuntu GRUB screen

When trying dual-booting Windows 7 and Debian testing, although at install the installer told me it detected Windows, at first boot there wasn't an entry. All I has to do was run "update-grub" as root and problem solved. This applies to distributions using GRUB 2, which seem to form the majority nowadays. On legacy GRUB, just create an entry in menu.lst to instruct GRUB to chainload Windows, and you should be set. Here's an example entry considering that Windows is, as is in our example, installed on sda1:

(1) Windows
title Windows 7 x86
rootnoverify (hd0,0)
chainloader +1

As with old and tried LiLO, yes, it can boot Windows with no problem. Here's what I found as an example lilo.conf:

boot = /dev/sda
timeout = 10

default = Linux
vga = normal

image = /boot/vmlinuz-2.6.32-20

label = Linux
initrd = /boot/initrd-2.6.32-20.img
root = /dev/sda3

other = /dev/sda1
label = Windows 7 

Remember to run lilo after altering the configuration file and reboot. You'll find the Windows entry right there.

5. Conclusion

As you can see, with Linux distributions becoming more and more friendly to the neophyte, dual-booting isn't the nightmare it used to be. However, if you have the means, try installing the two OSs to separate hard drives (I used to work on a Windows 7 box in the past and that thing ate disk space like a kid eating candy, believe me) or even better, separate systems. But if you can't, we just hope this article will help you accomplish your task seamlessly.

6. Famous last words

As I have noticed, there are cases when GRUB 2 doesn't detect your Windows 7 at all, regardless of the incantations or sacrifices to unholy deities you might make. What you need to do is calm down, write a small text file , update GRUB and reboot. GRUB 2, as opposed to legacy GRUB, isn't that consistent with numbering partitions and disks. While legacy GRUB starts numbering from 0, partitions and disks alike, GRUB 2 thinks it's smarter and numbers disks from 0 and partitions from 1 (nice touch). So, if you look above to the legacy GRUB example, there the first partition of the first disk, where Windows boots from in our example, is (hd0,0). In GRUB 2 that would be (hd0,1). Trust me, remembering this will help you a lot at the wee hours in the morning.

Let's start: create a file in /etc/grub.d/ named 12_windows7 (only the number counts, as it will set the order Windows will have in the boot menu) and write this in it:

#! /bin/sh -e
echo “Adding Windows” >&2
cat << EOF
menuentry “Windows 7″ {
set root=(hd0,1)
chainloader +1

Save the file and close the editor, make sure that the file is executable with "chmod a+x ... " , of course run "update-grub" and reboot. Voila.

Free Linux eBooks

Go to top