Dual Boot Windows 7 & Debian 6.0

Written by Wayne MacKenzie on July 10th, 2011

Purpose

This tutorial will instruct how to configure a PC to dual boot between Windows 7 and Debian 6.0 with the use of the Grub Boot Loader 2.  A single hard disk drive will be used for the example.

This tutorial will also instruct on repairing the GRUB2 loader if a new Windows install is performed which automatically replaces the MBR (Master Boot Record) as part of the normal Windows install..

As Built for this tutorial

Dual Boot PC
Hardware Dell Core2Duo 2.6Ghz, 4GB RAM, 640GB HDD
Operating System Debian 6.0 (Squeeze)
Operating System Microsoft Windows 7 PRO

 

For this tutorial I will assume that Windows 7 was already installed.  But with a simple manipulation of these processes the reverse could also be achieved.

Method

A partition with adequate room is required for the Debian installation.  A partition can be resized in order to make a spare partition available.  The size of the new partition will need to be appropriate to your requirements.  As a guide the base Windows 7 PRO installation uses approx 7GB of hard drive space whereas Debian 6.0 Desktop uses approximately 3.5GB.

Install Debian in the spare partition as per your requirements.  Since Debian has now replaced the MBR (Master Boot Record) Windows will need to be added to the GRUB boot menu so it is still available.

The Windows partition will need to be identified in order to create the menu item.  This can be done by checking fdisk list output.

fdisk –l

The output should look something similar to the below.  In my case the Windows partition was sda1.

Device Boot      Start         End      Blocks   Id  System
/dev/sda1               1          13      102400    7  HPFS/NTFS
/dev/sda2              13        3339    26710016    7  HPFS/NTFS
/dev/sda3            3339        5251    15358977    5  Extended
/dev/sda5   *        3339        5167    14683136   83  Linux
/dev/sda6            5167        5251      674816   82  Linux swap / Solaris

Now that the Windows partition has been identified create file /etc/grub.d/09_Windows7PRO with the following contents amended to suite.  Note! The numbers at the front of the file name depicts the order in which the files will be run and therefore also the order in which the menu items will appear.  In my case the Debian file was 10_linux. I wanted Windows to be the default so I needed the entry to appear first on the Grub menu hence 09_Windows...

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

In the above script the menu entry field can be modified to whatever you want to appear in the menu.  The set root=(hd0,?) needs to be set to reflect the windows boot partition.
e.g.
/dev/sda1 = …root=(hd0,1)
/dev/sda5 = …root=(hd0,5)

Give the new script execute permissions

chmod a+x /etc/grub.d/09_Windows7PRO

To make things a little nicer and less automated I decided to remove the os-prober application from my Debian installation. (I don’t like the format that os-prober uses)

apt-get remove os-prober

Now let’s update the grub menu with a simple command.

update-grub2

The following output should be seen if all went well.  Note the order.

root@debian:~# update-grub2
Generating grub.cfg …
Adding Windows 7 to Menu
Found linux image: /boot/vmlinuz-2.6.32-5-686
Found initrd image: /boot/initrd.img-2.6.32-5-686
done

Reboot to view the results

You should now be able to boot either Debian or the default Windows 7 Installations.

If you want to be really lazy!!!!

If the os-prober application is installed you should be able to just run the update-grub2 command and have a Windows entry added to the bottom without having to go through all the above steps.  Not as nice though I say.  Plus it identified the Windows 7 install as Vista in the menu and placed it last in the list. (Talk about insult on top of insult)


 

Grub Repairs

Let’s say you had the dual boot running all well and good then you go and re install windows.  Guess what?  That’s right Windows have replaced Grub MBR with its own so now you have no access to you Debian system.  Well there is no need to reinstall Debian which will lose all you good setup.  We just need to re install Grub.

Boot PC from “debian-live-6.0.1-i386-gnome-desktop” or “debian-live-6.0.0-i386-standard”.

Note! If non GUI Live Debian CD is used then you will need to switch to root user via the command sudo su

Grub will need to be installed.  During the installation just <ENTER> through the option screens and select YES “Continue without installing GRUB.

apt-get install grub

Confirm the Linux partition with the FDISK command.

fdisk -l

As below my example has been identified as sda5

Device Boot         Start         End      Blocks   Id  System
/dev/sda1               1          13      102400    7  HPFS/NTFS
/dev/sda2              13        3339    26710016    7  HPFS/NTFS
/dev/sda3            3339        5251    15358977    5  Extended
/dev/sda5   *        3339        5167    14683136   83  Linux
/dev/sda6            5167        5251      674816   82  Linux swap / Solaris

Next mount the Linux partition to a temporary directory and confirm the mounting was OK.

mkdir /media/root

mount /dev/sda5 /media/root

ls –lah /media/root

Install GRUB to the MBR (Master Boot Record)

grub-install --root-directory=/media/root /dev/sda

After the installation the response should be

Installation finished. No error reported.

When the PC is next rebooted your original Grub menu should now be present.


References

Accessed July 8th 2011 – http://linux.koolsolutions.com/2008/12/28/windows-xpvista-dual-boot-does-not-boot-from-grub2-or-grub-pc/

Accessed July 8th 2011 – http://www.ohbuntu.blogspot.com/2009/11/repair-grub2-after-install-windows-7.html


Print Friendly
 

You must be logged in to post a comment.