Linux Tutorial : Easily multibooot Windows 7 with Linux

Dark Star

Well-Known Member
ex-Mod
May 7, 2006
7,062
481
227

Windows7 has been the talk of the town for quite a few months and it will be the favorites due to lower system usage than Vista.. Recently I gave the new Redmond OS a ride and found it reminiscent of Vista, in-addition to few cosmetic changes that it brings with it.

Well we are not here today to talk about what WIn7 is and what it does .This thread is for those people who intend to dual boot Windows 7 with any of the Linux Operating system.

Prerequisites : -
  1. Windows 7 DVD
  2. Any Linux distro with latest grub 0.99.x
  3. A DVD/CD drive..

In this tutorial we will make Linux and Windows7 multi-boot in which Linux has been installed first.

Once you install Windows7 over any Linux installation, the Windows boot-loader will overwrite the existing grub boot loader and you will not get the Linux entry while booting you system.. In order to get a multi boot we have to restore the grub..

After installing Windows 7 over any linux distro. Insert the Linux Live Cd and boot through it. Once the desktop appears open the Terminal in Gnome or Konsole in kde . to open the respective command client you can either gain access from menu's or simply press ALT + F2 and type the following

Code:
 Gnome - [B]gnome-terminal[/B]
KDE - [B]konsole[/B]
This will open the command client in the respective desktop environment. Once it is open, we have to gain root privileges

Code:
 Debian based disto - [B]sudo su root [/B]
Rpm based distro -[B] su -[/B]
After you have gain the desired privileges we will focus on restoring the grub and adding windows entries to it..

Type the following command as super user/root one by one

Code:
grub
find /boot/grub/stage1
This will show your Linux boot file location as following

Code:
 (hd0,1) # consider 0,1 as X,Y
Note the 1'st word 0 say X indicates the hdd entry number (hard disk number -1 ) in which you have installed Linux. For Example, if you have installed the Linux in hard-disk 1 the it will show the number as 0 and if you have installed in second hard-disk as set in BIOS then it will list the number as 1.

The second number output 1 say Y list the partition ( partition number -1) in which you have installed the distro..

Now once you get the numbers you have just to re-install the grub inorder to restore the default Linux boot manager

Code:
root(hd0,1) 
setup (hd0)
Note : Do not forget to replace the number with the output that you get..

Once we are done type quit and reboot the system in Linux.. Open the command client again [not in Live disc mode] and type the following commands after gaining root privileges..

Code:
 [B]For Gnome user[/B][B] -[/B] gedit /boot/grub/menu.lst

[B]KDE user -[/B] kwrite /boot/grub/menu.lst
Add these lines at the end where other Linux entries are listed as well..
Code:
title Windows 7 (Loader)
root (hd0,0)
savedefault
makeactive
chainloader +1
Note : here first 0 indicate hard disk number -1 and second 0 indicate partition number -1.. I have installed Windows 7 in the first partition of my primary hard drive therefore the entries are shown as 0,0. It will vary with the partition and hard disk in which you have installed...

Ubuntu 9.10 Onwards : The Grub 2 Mumbo Jumbo

WIth the release of Ubuntu 9.10, the Canonical was quick to adapt with the venerable Grub2, even though the version 2 of the Gnu Bootloader is still under development the people behind ubuntu thought of including it even though its still not in final stage.

Since Ubuntu is one of the most popular distro out there, playing with Grub2 was an essential for almost all those who plan to use uBuntu, even if you don't plan to use it, getting something new under the hood isn't that bad ? Ain't it ?

To recover the grub after installing Windows over the Ubuntu installation, just follow these steps : -

1. Insert Ubuntu Disc 9.10 onward.
2. Enter sudo fdisk -l. Yo u will get output something similar to this :
Code:
shashwat@shashwat-desktop:~$ sudo fdisk -l
[sudo] password for shashwat: 

Disk /dev/sda: 640.1 GB, 640135028736 bytes
255 heads, 63 sectors/track, 77825 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x0009e36e

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1               1        4514    36258673+   7  HPFS/NTFS
/dev/sda2            4515        8473    31800667+  83  Linux
/dev/sda3   *        8474       11802    26740192+  83  Linux
/dev/sda4           11803       77825   530329716+   5  Extended
/dev/sda5           11803       18800    56211403+  83  Linux
/dev/sda6           18801       48903   241802316   83  Linux
/dev/sda7           48904       63885   120342883+  83  Linux
/dev/sda8           63886       77518   109507041   83  Linux
/dev/sda9           77519       77825     2465946   82  Linux swap / Solaris
shashwat@shashwat-desktop:~$
Now my MBR is installed in the third partition of my hard disk. This means that the main booting parameters are stored here. In no sense this means that my Linux is installed in the same partition, the partition for linux installation can vary from the MBR partition. Just in case you don't rememebr the exact partition you can alway browse the partition using the inbuilt browser Nautilus in Ubuntu disc. Once you have got the partition located (say Ubuntu mount the partition as /media/disk) you can from here get the exact device status from df -h command.

4. df -h should show the following output

Code:
shashwat@shashwat-desktop:~$ sudo df -h
[sudo] password for shashwat: 
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda3              26G   22G  2.5G  90% /
udev                  1.9G  280K  1.9G   1% /dev
none                  1.9G  2.7M  1.9G   1% /dev/shm
none                  1.9G  328K  1.9G   1% /var/run
none                  1.9G     0  1.9G   0% /var/lock
none                  1.9G     0  1.9G   0% /lib/init/rw
/dev/sda7             115G   37G   79G  32% /media/hd0
/dev/sda6             231G  218G   13G  95% /media/hd1
/dev/sda8             105G   32G   73G  31% /media/hd2
/dev/sr0              683M  683M     0 100% /media/cdrom0
shashwat@shashwat-desktop:~$
Once you have got the exact partition under the belt its time for some mounting and installing.

5. Mount the partition using mount command. Make sure you umount all the partition before doing this.

Code:
 umount -a
Now mount that partition using mount command

Code:
mount /dev/sdaX /mnt
Here X refers to the partition number in which the linux (Ubuntu or distro with grub2 is installed). Replace sda with hda or whatever your fdisk -l or df -h output is.

Now install the grub again using the following command : -

Code:
grub-install --root-directory=/mnt /dev/sda
Once done just reboot and open ubuntu, incase your Windows entry is not showing just update the grub using

Code:
sudo update-grub
That is it . You have successfully dual boot Windows 7 and Linux in your machine..

This tutorial is also applicable in case where Windows is installed first. If some distro fails to add grub and windows entries you can use the above stated method to make a multi-boot solution...

I hope this tutorial helps you in multi-booting OS. You can multiboot any linux, windows or mac using the same procedure.

Please feel free to ask your doubts .

Also check : http://www.techenclave.com/guides-and-tutorials/installing-windows-7-rc-7100-ubuntu-137734.html

Regards
 
  • Like
Reactions: 2 people

linuxtechie

Well-Known Member
ex-Mod
Aug 9, 2007
1,494
37
112
119
www.linuxtechie.net
DarkStar,

Agreed, the right way is the way you mentioned if a user wishes to let linux control the bootup. However if the user would like to let window's boot manager continue, then again the grub will come to rescue. Instead of reviving linux boot manager, the user can continue without any of but plainly install grub in windows.

BTW A job done nice.

~LT
 

DanDroiD

New Member
Disciple
Apr 17, 2007
1,576
141
0
55
linuxtechie said:
DarkStar,

Agreed, the right way is the way you mentioned if a user wishes to let linux control the bootup. However if the user would like to let window's boot manager continue, then again the grub will come to rescue. Instead of reviving linux boot manager, the user can continue without any of but plainly install grub in windows.

BTW A job done nice.

~LT
I did that once but it's a bit of a finicky process to load grub from windows and then you still have to contend with 2 boot manager screens.... whereas with Grub bootloader you can boot directly into windows and skip the windows menu.
 

Ryunosuke

New Member
Adept
Jul 18, 2008
872
21
0
31
Well I installed the Windows 7 in my partition that earlier contained XP and despite XP's want of being the primary HDD resulting in mapping of drives in menu.lst file, Windows 7 boots beautifully without any problem. :)

On my setup, I've 3 HDD, each having an OS, Windows 7(32-bit), Vista SP1(64-bit) and Ubuntu 8.10(32-bit). I have made the Ubuntu's drive main Primary boot drive and the GRUB manages it all flawlessly. :cool2:
 

Dark Star

Well-Known Member
ex-Mod
May 7, 2006
7,062
481
227
Update : Mandriva 2009.1 automatically adds Windows 7 and Ubuntu entry, a decent distro with properly integrated grub/distro detector will automatically add windows7 so no need to worry.

I will add a How to soon on adding Linux/Windows entry using Mandriva Control Center .
 

j1n M@tt

New Member
Disciple
Mar 12, 2009
346
3
0
32
sorry for bumping up this old thread, I just have few questions.

At present I have Win 7 RC on my HDD. I got my Ubuntu 9.04 copy lately and I wish to install it soon. If I install it now, will there be a problem with GRUB on MBR?? The last time I have installed linux, it was Ubuntu 8.10 with Vista on my another rig and it worked fine.

And for the new Mandriva which one is the best, KDE or Gnome??.....I mean like Gnome suites best for Ubuntu than KDE.
 

Dark Star

Well-Known Member
ex-Mod
May 7, 2006
7,062
481
227
^^Well thats tricky :p Ubuntu comes with WUBI :| so if you install Ubuntu inside windows MBR will be the bootloader.

But if you install Linux the way it is meant to be installed then Grub will take over (ofcourse you need to install grub during installation)

For Desktop Env. that is personal choice. I use both so get what you are familiar with, unlike (X)Ubuntu (X=K,X,n,L) , mandriva specializes in both Gnome as well in KDE, while ubuntu/canonical focus more on Gnome that KDE.
 

j1n M@tt

New Member
Disciple
Mar 12, 2009
346
3
0
32
I didn't mean that I was installing Ubuntu inside Windows with some kinda virtual machine that Ubuntu disks comes with. I need to dual boot.

so you mean I have to install Grub manually when installing Ubuntu?? if yes, can you plz tell me how to install Ubuntu in command line...I usually use the graphics install, am not an advanced linux user.
 

Dark Star

Well-Known Member
ex-Mod
May 7, 2006
7,062
481
227
^^Just install ubuntu and it will install grub and will add the windows entry as well ;)
 

j1n M@tt

New Member
Disciple
Mar 12, 2009
346
3
0
32
so just like dual booting with vista...but many of them said to me Win 7 crashed after installing Ubuntu 9.04, thats why asked. Anyway will try soon :) and thanx for the help.
 

kamajra

New Member
Disciple
Oct 20, 2009
4
0
1
33
This happens to me usually.

I try booting win 7 with grub and it gives some weird errors and which leads to repairing the Win 7 OS or at times reinstalling.

How to install grub in to the win 7 boot manager. Put a light over that.
 

sikvik

Member
Disciple
Jul 15, 2007
91
0
16
I'm stuck after-
grub> find /boot/grub/stage1
I get (hd0,0)
Can't understand what to enter next, inside the brackets? Get Unrecognised command...
Pls help FIRST time Dual booter win7 RC over Karmic

Wiped the disk with active kill disk. Installed Win7RC and Karmic over it. Dual-boot, was smooth as silk. Cheers...
 

Dark Star

Well-Known Member
ex-Mod
May 7, 2006
7,062
481
227
^^nope not yet. Only encountered the Gub 2 with Buntu and looked pretty messed up :p

Gotta learn it with Constantine shift ;)
 

vishalrao

Global Moral Police
Veteran
Nov 10, 2007
4,568
679
202
Pune, India
grub2 aint so bad. its just got a new config format which is cool once you get a hang of it. grep the web for grub2 tutorials to get a hang of stuff... i am successfully quadbooting win7 with 3 other linux distros using ubuntu's grub2 as the bootloader in the MBR...

there are some annoyances (or cant figure out solutions yet) for example, i cant figure out how to custom arrange the OSes autodetected by os-prober script... i want to put win7 at the top of the list and default boot but cant figure out rearranging the items properly at the moment...