Dual Booting Linux/Windows

Setting up Dual Boot Linux & Windows 7

This page will go through setting up a dual boot between Linux and Windows, assuming all your disk space is currently taken up by the first operating system. For this tutorial, I’ll be using a Virtual Machine and setting up dual boot both ways (Windows 7 first and Linux second, and vice versa) Depending on your linux distribution, you may or may not have gparted included (most of them do, unless you are, or are intending to use, a terminal-based or terminal-weighted distribution, such as Arch or Ubuntu Server. Make sure you compare the version of gparted against the one on the gparted website and use the latest version. There is a live disk available with gparted on available from the gparted site gpartedlive

 


Contents


Installing Windows 7 alongside Linux (Linux installed first)

This section assumes you have installed a Linux distribution and want to install Windows 7 alongside. gparted will be used in this tutorial to do the resizing, but note that it only supports resizing Physical Volumes, and not the Logical Volumes (at least, at the time of writing this was the case.) So, you will need to spend time in the terminal for the main part of the resize. Before attempting ANY resizing activity, remember to BACKUP. Download and use CloneZilla. It’s free, small, and works with dual boot environments. It can be booted using a USB, and you can save your images off-site using SSH for safety.

Non-LVM-Based installation (e.g. Debian, Ubuntu, Linux Mint and similar Debian derivatives)

Before you install Windows, you need to resize your linux installation. Here’s my starting configuration within gparted live. As with all resizing activities, remember to BACKUP. Download and use CloneZilla. It’s free, small, and works with dual boot environments.

DebianResize1

Now, something you need to be aware of. You see within the picture that my linux swap is within an extended partition. In order to move my data, I first need to shift my extended partition, so what I’ve done is this:

  1. Shrink my main data partition down to 15GB
  2. Extend my extended partition to fill the space.

  3. Move my swap along within the extended partition

  4. Shrink the extended partition back to fit the swap

The result is this:

DebianResize2

Apply the modifications and then shutdown. Restart your linux OS and make sure it boots up okay. If not, restore using your Clonezilla image.

Now, install Windows. For this tutorial, I’m installing Windows 7 Home Basic.

Sandbox2

I’m going to skip a few screens here. Click through until you get to this screen:

Sandbox4

The first two partitions are the linux partitions. In this particular setup, I had Debian installed first. You cannot install Windows onto either of those two partitions due to lack of free space (from Windows’ perspective). So I’m going to install on the free space I have left.

Sandbox6

After the install is complete, Windows will reboot. Note that at this point, your boot record has been rewritten, forcing your machine to boot to Windows, locking you out of linux (we’ll fix that later).

Sandbox7

During the boot, Windows will perform some configurations, and prompt you for some settings:

Sandbox8

Before finally, ending up at your Windows desktop

Sandbox9

So, that is Windows installed. But, we cannot get back into linux because of the way Windows installed itself. That is what we will now fix.

Reinstall bootloader using Boot Repair (recommended)

The easy (and recommended) way to fix this annoying Windows quirk is to use Boot Repair. Get it from this page.

Here’s the boot screen (I’m using the 32-bit version, but there is also a 64-bit version)

Sandbox1

Start the program. Boot Repair will scan your system. This can sometimes take a while.

Sandbox2

When the scan is complete, you will be offered two options:

Sandbox3

Always use the Recommended repair. It almost always works. Only start looking in the Advanced options if the Recommended option doesn’t work.

Sandbox4

When the update is finished, power off the machine and start it up again. If all goes well, you’ll have a boot screen like this:

Sandbox5

Start up you linux install and make sure it is all OK, then reboot and start your Windows install, and also make sure it is OK.

Reinstall bootloader using rescue mode or terminal

Reinstalling the bootloader is also possible using any boot cd that offers a terminal and the common terminal commands. Even the installer discs have “Rescue Mode” options, which allow you to do this. For example, on the Debian installer DVD, it is located in “Advanced Options” -> Rescue Mode

Once Rescue Mode starts, you’ll get this.

Sandbox6

You’ll need to know which partition your main data is on. This would be sda1 in my case. If using a terminal instead, I would do this:

mkdir datamnt
sudo mount /dev/sda1 datamnt

Then, you’ll be offered some common rescue options

Sandbox7

Use the option to reinstall the bootloader.

Sandbox8

You’ll be asked where you want to install the bootloader. I want it to overwrite the Windows record, so I put it right at the front. In my case, that’s /dev/sda

If doing this within a terminal, I would do this:

sudo grub-install --boot-directory=/path/to/datamnt /dev/sda

After the installation is complete, reboot. Here’s what your boot screen will look like

Sandbox9

Notice something? Windows is not showing up. That’s because the process of reinstalling the bootloader did just that – reinstalled it, but did not update it. The Boot-repair option also updated the bootloader as part of its update, which is why it showed up on the list afterwards.

To update the bootloader, go into your linux install, now that you have access to it again. Open up a terminal, and type the following:

sudo update-grub

Sandbox10
Now, reboot,  and this will be your boot screen

Sandbox11

You now have a dual boot working, with linux installed first, and Windows installed second.

LVM-Based installation (e.g. Fedora, CentOS, and similar Red Hat derivatives)

Before you install Windows, you need to resize your linux installation. Here’s my starting configuration within gparted live. As with all resizing activities, remember to BACKUP. Download  and use CloneZilla. It’s free, small, and works with dual boot environments.

FedoraResize1

gparted only supports resizing Physical Volumes, so you will have to use the terminal for this step.

To resize the PV we first need to shrink its usage. That is done within the terminal.

First, activate the VG

sudo vgchange -ay

FedoraResize2

Next, check the contents of your VG.

sudo lvdisplay

FedoraResize3

You can see here that I have two LVs within my VG, one is the root volume (/dev/fedora/root) and the second is the swap space (/dev/fedora/swap). I want to reduce my root volume by 10GB. You can use lvreduce or lvresize here, but I always use lvresize as it can size up or size down. Be careful with switches, otherwise you’ll lose data here. The -L switch indicates the size I want to resize to. The -10G indicates I want to shrink by 10G (i.e. the new size is negative 10GB of the current size), and -r indicates to do a resize of the underlying filesystem.

sudo lvresize -L -10G -r

FedoraResize4

Now we have reduced the LV, we can start looking at resizing the PV. Go back to the gparted window and refresh it.

FedoraResize6

Notice how gparted now sees that space has been freed up by the resizing of the LV. We can now resize the PV. First, we need to deactivate the VG, so right-click on the PV and choose Deactivate to remove the lock on it. Now you should be able to resize the PV. When completed. Shutdown, restart, and verify linux starts up okay. If not, restore from your Clonezilla backup. If it does startup okay, you can install Windows (follow the steps with the Debian installer to reinstall the bootloader using either Boot-repair or using the installer disk/terminal)


Installing Linux alongside Windows 7 (Windows installed first)

This section assumes you have a Windows 7 installation and want to install Linux alongside. Since there is no Linux installation already installed, a lot depends on your distribution. Depending on the distribution, it may offer to resize partitions for you as part of the install process, or it may not. I recommend you resize before running the installer, and not to rely on the installer’s resize routines (I find the resizing as part of the installation process to be flaky and unreliable) Plus, if you resize outside of the installer, you’ll have more control and better visibility of what exactly is going on.

Resizing before installing

Before attempting ANY resizing activity, remember to BACKUP. Download and use CloneZilla. It’s free, small, and works with dual boot environments. So, let’s resize. I’ve loaded up gparted live in my virtual machine and here’s the layout of my Windows 7 installation (Bitlocker is not enabled on this installation.) gpartedlive-loaded I think I’ll resize windows down to 15GB and use the remainder for linux. Resizing Resizing 2 Applying Resize

Shrinking can take a long time, so go and do something else while you wait. When you come back:

Resized

After resizing, shutdown gparted live and reboot to ensure Windows still runs (if it doesn’t, rollback using your CloneZilla image). Windows will run a chkdsk (again, this might take a while). Note that at this stage, we still haven’t made any changes to the Operating System on the machine.

chkdsk

chkdsk 2chkdsk 3

Once you get back into Windows, check your disk size. You should see the reduced size. Here, my disk is down just under 15GB.

ResizedInWindows

As you can see, the disk size has been reduced to just below 15GB. Compare with the original size:

ResizedInWindowsOld

We have now resized our Windows installation down to 15GB. The next step is to install Linux. For this tutorial, I’ll install Debian and Fedora, as they are the basis for the majority of Linux users out there. I know, some of you will be using CentOS, openSUSE, Arch, etc. But for the majority, they will be using Debian or an Ubuntu variant, or Fedora, or similar RedHat variant.

Installing Linux (Debian)

The latest version of Debian is downloaded via this page. The version at the time of writing is Debian 7.5.0, and I’ll be using the standard installer. This is the boot screen for the Live CD: DebianInstall1 I’m going to use the Graphical Install DebianInstall2 I’m going to skip a few screens here. Work your way through until you get to the partitioner step: DebianInstall3 For dual boot to work, you must use either the first option: “Guided – use the largest continuous free space” or the last option “Manual”. If you want to setup LVM, you’ll need to use manual mode. For this tutorial, I’ll use the first option. DebianInstall4 Which option you choose here is up to you. Generally, if you’re setting up a home machine, the first option is best. Setting up as separate partitions is useful if you later want to move those onto a separate disk for contingency. This is particularly important for corporate or business environments. For this tutorial, I’ll use the single partition option. DebianInstall5 Now, the installer has calculated my new partition configuration. You can see here that the first two partition (#1 and #2) are my Windows 7 partitions, and the second two (#5 and #6) are the new partitions with #5 being the main one, and #6 being the swap partition. If you selected to have separate partitions, you would get more lines here. Notice how the first partition is tagged with a B (being its the boot partition). DebianInstall6 The installer asks for final confirmation before continuing. You can see that two new partitions will be created and formatted. This is what we are expecting, so let’s confirm and continue. After partitioning, the installer will start doing its work DebianInstall7   You can also read in the additional DVDs (if you downloaded them) DebianInstall8 The benefit of this is that the installer will use your DVDs first instead of downloading from the net, so you’ll get this when it happens: DebianInstall9 After the main install, you get to pick your configuration. Debian comes with a set of pre-determined sets of packages to meet machine roles: DebianInstall10It’s entirely up to you what you pick from this list.

When you get to the end, Debian will install GRUB. It is here that Debian will detect the other operating system:

DebianInstall11

Although it is actually Windows 7 and not Vista, Debian has detected another Windows operating system, so I’ll let the installer proceed as recommended.

The installer will now finalise and finish its work. And you can now reboot.

DebianInstall12

Upon rebooting, you should now get a boot screen similar to this:

DebianInstall13

Tempting as it might be, what you should NOT do is go into the newly installed linux OS. Go into Windows first, and make sure it loads OK, and THEN shutdown, restart and go into linux to start up any install/config programs. If there are any problems, rollback using your Clonezilla image. You DID make a backup image, didn’t you?

You now have a working dual boot Windows/Linux (Debian) environment.

DebianInstall14

Installing Linux (Fedora)

The latest version of Fedora is download via this page. The version at the time of writing is Fedora 20, and I’ll be using the standard installer, not a Fedora Spin.

Fedora, by default, uses LVM, so this tutorial will use that. If you don’t want to use LVM, you can do so. As with the previous section, you need to resize your Windows installation to free up room for your linux install.

FedoraInstall1

FedoraInstall2

When you get to this screen, make sure you do NOT accept automatic partitioning, customise it:

FedoraInstall2

Select the highlighted icon and pick the disk to install on:

FedoraInstall4

Click done, and you should get a popup

FedoraInstall5

Pick “I want to review/modify my disk partitions before continue”. You can pick whichever partition scheme you want, but I’m going to use LVM and unencrypted for this section.

FedoraInstall6

You will notice that Fedora hasn’t created any mount points for you, and it has detected the Windows installation under the “Unknown” drop down. So, click on the button to create the mounts.

FedoraInstall7

You will notice that Fedora by default puts everything in one partition, like the Debian installer, although you are prompted if you want to use multiple partitions if you are doing a full-disk install. Nonetheless, I’m happy with the current configuration, so I’ll continue. Click done, and the installer will confirm actions:

FedoraInstall8

Accept the changes, and you’ll be taken back to the main screen

FedoraInstall8 FedoraInstall9

You should now select your choice of packages. I’ll continue with defaults, but spend some time here making any adjustments you want to the packages.

Fedora will start installing when you’re ready. During the install, you’ll have to setup a root user.

FedoraInstall10

FedoraInstall11

Once the install finishes and you reboot, your loader should look something like thisFedoraInstall12

Tempting as it might be, what you should NOT do is go into the newly installed linux OS. Go into Windows first, and make sure it loads OK, and THEN shutdown, restart and go into linux to start up any install/config programs. If there are any problems, rollback using your Clonezilla image. You DID make a backup image, didn’t you?

You now have a working dual boot Windows/Linux (Fedora) environment.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.