How to add Vista/Windows 7 partition to Grub 2 (Ubuntu 9.10, Karmic Koala)
Today I decided to give Ubuntu 9.10 (Karmic Koala) a try. I’m using my old laptop for testing purposes. At the moment I have there Windows 7 and Ubuntu 9.04 installed and I can use them both with dual booting. I had no vital documents on my Ubuntu partition so I decided to do a clean install. Karmic Alpha 2 was just released and compared to Alpha 1 it was now using GRUB 2. Install went smoothly with no particular issues so I booted to Karmic and messed around a bit. Then logged off again rebooted, ready to use Windows. Imagine my surprise when there was no boot to Windows option in GRUB.
Here’s what I did to add it. I booted up to Karmic again. Now I only had 1 hard drive, but several partitions. I needed to find out which one was my windows partition. To do that I started a terminal and used the following command:
# sudo fdisk -l /dev/sda
According to this my Windows partition is hda1. To continue with my plan to add Windows boot option I typed in the following line:
# sudo nano /etc/grub.d/11_Windows
This created a new a new file. I then added the following lines:
#! /bin/sh -e
echo “Adding Windows” >&2
cat << EOF
menuentry “Windows 7” {
set root=(hd0,1)
chainloader +1
}
EOF
Now save the 11_Windows file.
Bare in mind that in earlier version of GRUB, if your Windows was installed on first partition then you need to give root=(hd0,0). Thats how GRUB used to number partitions. Starting from GRUB 2, you need to give root=(hd0,1), if your Windows is installed on first partition. So under GRUB 2 it looks like this:
First partition (/dev/sda1): root=(hd0,1)
Next type the following command:
# sudo chmod a+x /etc/grub.d/11_Windows
Next type in the following command:
# sudo update-grub
You should be able to see something like this:
# sudo update-grub
Generating grub.cfg …
Found linux image: /boot/vmlinuz-2.6.30-9-generic
Found initrd image: /boot/initrd.img-2.6.30-9-generic
Found linux image: /boot/vmlinuz-2.6.30-8-generic
Found initrd image: /boot/initrd.img-2.6.30-8-generic
Adding Windows
Found memtest86+ image: /boot/memtest86+.bin
done
Now close all the open programs and type in the following command to your terminal:
# sudo reboot
If all went well you should see Windows 7 option in your GRUB2.
-Eric
Thank you,
it works !!!!!!!!!!!!!!!!!!!!!
Thanks for this informative, quick and effective solution!
Thanks worked for me
ur amazing thnx
Also works with Vista, XP, etc (all windows)
Very quick way to do it if GRUB screws up and doesn’t add Vista/7/XP to the list automatically
I had a hard time figuring out the problem on my computer! I have windows on a separate harddisks (not partitions).
There for the boot to work it should be:
menuentry “Microsoft Windows” {
insmod ntfs
insmod chain
insmod drivemap
set root=(hd1,1)
drivemap -s (hd1) (hd0)
chainloader +1
}
hd1 (in this exmaple) <- the harddisk where windows is
hd0 (in this example) is where grub is installed (the drivemap) is really important
Same for me!!!
sda 320GB/ Windows 7 / 100MB secret partition
sdb 160GB/ Windows XP / Ubuntu / Swap
And I get “error 15: file not found”
Is that safe???
The last time I ve tried to fix this problem I put GRUB2 in Windows disk…
And this is something I want to avoid.
And after that I completely destroyed Windows MRB
Yeah for me!!! 😦
So can I use 11_Windows file method with Fabien way???
my win 7 install put the boot in a hidden partition….would the method explained above work the same?
im dying to install KK on my pc but i cannot loose win for work.
thanks
m
thanks a lot, it’s simple and it works :))
hey eric, could you help me out. my windows 7 is on drive C: which is hd0,1 (/dev/sda1) but no matter how many times I follow your technique, “Adding windows” never comes. please help.
i´ve tried this tutorial but when my computer reboots it show me this
error: too many titles for menuentry: 7″
and then ubuntu 9.10 boots up… what should i do?
:S
thanks in advance
perhaps u got a typo somewhere ? i would recommend going it over agan
I too am getting the same problem as Andre. I’ve checked and rechecked what you suggested above, even to the extend of copy and pasting it all with gedit.
Still trying to figure out how to fix this. Any suggestions?
have you tried lanteshis option ?
“too many titles for menuentry: 7″
I had this issue too. The issue lies in Windows, not Linux. I had to use the Win CD to re-write Win to the MBR, and then use my live Linux Mint CD to re-write Grub2 back to the MBR. After that I was able to get things working
Hi, at the moment i have the issue that grub failed to boot my windows 7 after i select it in grub menu. The loading cursor is blinking but nothing is done after i select it. No error message occurs. Before it i had the problem that the grub menu was disabled, but it could be fixed by changing following property #GRUB_HIDDEN_TIMEOUT=0.
Has anyone this issue too ?
I had the same problem.
The issue lies in the copy pasting from the code above.
With pasting in the terminal in nano the left apostrophe and the right apostrophe of “Windows 7” aren’t the same.. If you edit these apostrophes, it works.
Hey Eric!
Thanks for the tutorial, I did as you said but still nothing happened. I have 2 hard drives all of which are internal. Grub is installed on one, and Windows is installed on the other one. The problem is, that I think the Windows 7 and XP loader was on the drive which I erased for Ubuntu….I have no idea how to configure Windows 7 to boot with grub…..
Can you show me the printout of this command sudo fdisk -l /dev/sda
and also can u show me the file u created for the windows partition.
that’s fdisk -l /dev/sda
Disk /dev/sda: 160.0 GB, 160041885696 bytes
255 heads, 63 sectors/track, 19457 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x0006a321
Device Boot Start End Blocks Id System
/dev/sda1 2 6581 52853850 f W95 Ext’d (LBA)
/dev/sda2 * 6582 12803 49978215 83 Linux
/dev/sda3 12804 18060 42226852+ b W95 FAT32
/dev/sda4 18061 19457 11221402+ 82 Linux swap / Solaris
/dev/sda5 2 6581 52853818+ b W95 FAT32
here’s fdisk -l
Disk /dev/sda: 160.0 GB, 160041885696 bytes
255 heads, 63 sectors/track, 19457 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x0006a321
Device Boot Start End Blocks Id System
/dev/sda1 2 6581 52853850 f W95 Ext’d (LBA)
/dev/sda2 * 6582 12803 49978215 83 Linux
/dev/sda3 12804 18060 42226852+ b W95 FAT32
/dev/sda4 18061 19457 11221402+ 82 Linux swap / Solaris
/dev/sda5 2 6581 52853818+ b W95 FAT32
Disk /dev/sdb: 500.1 GB, 500107862016 bytes
255 heads, 63 sectors/track, 60801 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0xfe0da636
Device Boot Start End Blocks Id System
/dev/sdb1 1 60801 488384001 7 HPFS/NTFS
Disk /dev/sdg: 8086 MB, 8086618112 bytes
249 heads, 62 sectors/track, 1023 cylinders
Units = cylinders of 15438 * 512 = 7904256 bytes
Disk identifier: 0x000b6296
Device Boot Start End Blocks Id System
/dev/sdg1 * 1 1023 7896506 c W95 FAT32 (LBA)
Partition 1 has different physical/logical endings:
phys=(1023, 248, 62) logical=(1022, 248, 62)
And the file is:
#! /bin/sh -e
echo “Adding Windows” >&2
cat << EOF
menuentry “Windows 7″ {
set root=(hd1,1)
chainloader +1
}
EOF
Thanks
which one is the part (harddrive) where win 7 is installed on ?
Windows 7 is on the
/dev/sdb1
partition.
if u scroll up and check comments, u will see the fabiens comment, he had the same issue as u and the solutions is there. I will add it to my post with his permission 🙂
Oh ok, I saw that, but am I supposed to put hd1 or /dev/sdb1 in the drive?
Eric, I have the same problem like Andre: too many titles for menuentry: 7
I have 2 ntfs partitions, and 7 installed on the second.
“too many titles for menuentry: 7”
I had this issue too. The issue lies in Windows, not Linux. I had to use the Win CD to re-write Win to the MBR, and then use my live Linux Mint CD to re-write Grub2 back to the MBR. After that I was able to get things working.
Eric you rock!!! I am a newbie but I followed your instructions to a ‘T’ and it works like a charm !!!
Thanks, grub2 is new for me, but this helped me a lot.
If your grub menu disappears have a look at this:
https://wiki.ubuntu.com/Grub2#Where%20did%20my%20Grub2%20boot%20menu%20go!?!?!
Eric, Merci!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
It’s work. Great!.
Thanks for this guide! I’d like to add my $.02 – I just installed 9.10 next to a fresh Windows 7 install, and was fully expecting to have to deal with this issue.
But… I did not. The Grub menu had a nice bright shiny “Windows 7 (loader)” option at the end of the list. I couldn’t believe my luck until I accessed the option. It worked like a charm with no further intervention from me.
I’m pretty ignorant of what details are relevant. I’m willing to field questions, though.
Hi all.
I had to add the following line to my /etc/default/grub:
GRUB_DISABLE_OS_PROBER=false
in order to grub showing the Windows menu entry.
Thanks a lot for your advices, Eric. This worked fine for me.
Thanks man u are the king worked for me as well !!!
Thank you so much !!
I followed the directions exactly but I am getting this output can someone PLEASE HELP :*(
nathan@nathan-desktop:/$ sudo update-grub
Generating grub.cfg …
Found linux image: /boot/vmlinuz-2.6.31-20-generic-pae
Found initrd image: /boot/initrd.img-2.6.31-20-generic-pae
grub-probe: error: Cannot find a GRUB drive for /dev/sdb1. Check your device.map.
grub-probe: error: Cannot find a GRUB drive for /dev/sdb1. Check your device.map.
“Adding Windows”
Found memtest86+ image: /boot/memtest86+.bin
Found Windows 7 (loader) on /dev/sda1
done
Can someone please tell me where my win7 is in from the details given below:
Disk /dev/sda: 30.0 GB, 30003240960 bytes
255 heads, 63 sectors/track, 3647 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0xe874cf66
Device Boot Start End Blocks Id System
/dev/sda1 * 1 1305 10482381 5 Extended
/dev/sda2 1306 3648 18813952 7 HPFS/NTFS
/dev/sda5 1 996 8000307 83 Linux
/dev/sda6 997 1305 2482011 82 Linux swap / Solaris
Disk /dev/sdb: 320.1 GB, 320072933376 bytes
255 heads, 63 sectors/track, 38913 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0xfdaffe7f
Device Boot Start End Blocks Id System
/dev/sdb1 1 1 992+ 42 SFS
Partition 1 does not end on cylinder boundary.
/dev/sdb2 1 10444 83886080 42 SFS
/dev/sdb3 10444 38914 228683096 42 SFS
—————————–
also please tell the file i should write..
I have GRUB2 on a dual boot machine:
Ubuntu 10.4 LTS (Lucid Lynx)
Windows Vista Ultimate
Is there an option to get Windows Vista to boot in Safe Mode with Networking or do I have to go back to booting from the MBR?
Thank you, Eric. This post is just what I was looking for.
thumbs up! worked like a charm!
gud fix
Thanks, your solution worked perfectly!
It doesn’t work ((
What shoul I do to make it work?
Generating grub.cfg …
Found linux image: /boot/vmlinuz-2.6.32-24-generic
Found initrd image: /boot/initrd.img-2.6.32-24-generic
“Adding Windows”
/etc/grub.d/11_Windows.save.1: 2: Syntax error: “&” unexpected
just double check that you don’t have any unnecessary comas etc.
it’s ok
problem is solved
thanks
Thank you Eric, you just saved me from totally re-installing. =D
Thanx again.
thanks a bunch, this worked for me! I have a lucid x64 server install with XBMC on top and every time I upgrade the kernel, the win7 entry disappears with no chance to get it back automatically.
adding the entry manually by following your instructions finally worked.
I did the steps using a putty terminal, first time I copied the 11_Windows content directly but it changed all the ” signs to . so be aware of this.
It works like a charm
Hello,
Thanks but it did not work. I got as far as seeing ‘adding windows’ then when I reboot nothing.
My Hd looks like this
Disk /dev/sda: 320.1 GB, 320072933376 bytes
255 heads, 63 sectors/track, 38913 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000440f0
Device Boot Start End Blocks Id System
/dev/sda1 1 9668 77657186 7 HPFS/NTFS
/dev/sda2 * 9669 28046 147621285 b W95 FAT32
/dev/sda3 28047 38914 87290881 5 Extended
/dev/sda5 38149 38914 6142976 82 Linux swap / Solaris
/dev/sda6 28047 38149 81146880 83 Linux
Partition table entries are not in disk order
Windows in on the sda1 partition so I assume that that your config lines match mine
Any help would be appreciated
Hey
My Windows 7 is on sda5, how do I do that?
set root = (hd0,5)
those quotes will break the grub.cfg
worked – nice quick solution. Thanks.
Hi
It didn’t solved my error 15 problem.There already is a Windows choice but gives me the error. When I use the Windows Repair Disk (64 bit Repair Disk) says “The version of System Recovery Options is not compatible with this version of Windows…..etc” On my other (32bit) laptop with the (proper 32bit) Repair Disk had no problem
Any ideas?
Thanks a lot!!! it worked like a charm!! Very Thankful to You……
Again Thanks!!!
Thanks a lot.. I was suffering from installing windows on another physical drive while having Ubuntu 10.10 on the other. Windows does not install at all unless it wants to ruin my entire system partition for Linux to start a new MBR as it does not recognise the drive with a Linux system partition, I am sure you know that painful story :), after which I have to reinstall and restore grub2 uhh. But I simply disconnected the Linux physical drive as if it wasn’t there. Installed Windows on the other physical drive, reconnected it again and simply applied your code to the grub2 on my first drive. WOWW.. Thanks man.. You saved me a lot of time and effort.. You are a GENIUS !!! THANK YOU A+++ !!!
This worked. Thank You!!
thank you!
Hi,
I installed Ubuntu with the Alternate-CD on a raid Hard drive my Win 7 is on a different Hard drive here’s my fdisk -l:
“Platte /dev/sda: 1000.2 GByte, 1000204886016 Byte
255 Köpfe, 63 Sektoren/Spur, 121601 Zylinder
Einheiten = Zylinder von 16065 × 512 = 8225280 Bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x4f16d6a4
Gerät boot. Anfang Ende Blöcke Id System
/dev/sda1 1 1 992+ 42 SFS
Partition 1 endet nicht an einer Zylindergrenze.
/dev/sda2 1 1959 15728640 27 Unbekannt
/dev/sda3 1959 1972 102400 42 SFS
/dev/sda4 * 1973 61754 480198915 7 HPFS/NTFS
Platte /dev/sdb: 160.0 GByte, 160041885696 Byte
255 Köpfe, 63 Sektoren/Spur, 19457 Zylinder
Einheiten = Zylinder von 16065 × 512 = 8225280 Bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x97559755
Gerät boot. Anfang Ende Blöcke Id System
/dev/sdb1 * 1 9732 78172258+ 7 HPFS/NTFS
/dev/sdb2 9733 13161 27539062+ 7 HPFS/NTFS
/dev/sdb3 13161 19457 50576737+ f W95 Erw. (LBA)
/dev/sdb5 16319 18565 18048996 7 HPFS/NTFS
/dev/sdb6 18566 19457 7164958+ b W95 FAT32
/dev/sdb7 13161 16182 24266752 83 Linux
/dev/sdb8 16182 16318 1094656 82 Linux Swap / Solaris
Partitionstabelleneinträge sind nicht in Platten-Reihenfolge
Platte /dev/sdh: 1995 MByte, 1995440128 Byte
62 Köpfe, 62 Sektoren/Spur, 1013 Zylinder
Einheiten = Zylinder von 3844 × 512 = 1968128 Bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Gerät boot. Anfang Ende Blöcke Id System
/dev/sdh1 * 1 1013 1946955 c W95 FAT32 (LBA)”
This log is in german, because I’m from germany.
On the first hard drive is Win7(SDA4). How can I add it?
Thanks, Henrik
Man, thanks. It works like magic. I tried to read some documentation but this one is the simplest and the shortest script.
you rock!
thank you mean, you save my life ^^.
Anyone tried to do this with a GPT disk?
I tried adding this to the 11_windows file instead of what the author suggested:
insmod part_gpt
insmod ntfs
set root='(/dev/sda,gpt3)’
chainloader +1
but I get disk not found even though in ubuntu I can see that windows is installed on gpt3 of sda….
Anyone have any idea what the problem is?
Thanks, just what I was looking for.
when i write the file is necessarly to put the # i saw that the commands dont work when I put #. i tried both in the file with and withouth #, after sudo-update i saw the Adding Windows line but still no Windows in boot loader. I found that the windows is in /dev/sda4 so in 11_windows is (hd0,4 ) . I have 2 hdd but Linux and Windows are on the same hdd, different partitions.
Wow thanks!!!
Thx. You saved my Life
Perfekt Work!!! THX… There is some documentation???
Thanks for in-depth guide. Though it seems on current Ubuntu version 11.10 “update-grub” is enough and grub recognizes W7 partition automagically… If creating manual config is needed, hard disk ordering is at /boot/grub/device.map file.
That almost worked perfectly, until I tried to boot the Windows partition from Grub- I got this error:
“error: invalid signature.”
I’ve had this with pretty much any attempt to add windows to grub- update-grub wouldn’t find it, but this method created it. wtf is going on? If it’s any help, partition managers are saying that sda1, the windows boot partition, is a linux-swap partition. Has one of the operating systems (and I have many) misread it and dumped swap data all over it?
youve just saved my life !! thank you
Awesome! Thanks a ton, Eric!
Totally awesome!
The worst thing of all, is that I tried to avoid editing grub. Tried re-installing but nothing was working. Then I found this and in 5 minutes I got my dual boot setted up :E
Thanx!
Clean and clear! Worked flawlessly. Thank you!
hello!
I use Debian6 with Grub2 and tried to add a new menu entry: I followed your instructions.
update-grub finished with “adding windows” and “done”. But there is no new grub entry?! I repeated this procedure 3 or 4 times: no new boot entry appeared….
do you have an idea what was happened?
Thanks for sharing this. I’m glad it helped so many. I just can’t make it work for me, and I don’t know why.
I am trying to dual boot on a single hard drive using Ubuntu 12.04 (on dev/sda6) and Fedora 17 LXDE (on dev/sda2). I started with a clean hard drive, and carefully followed the instructions contained in this tutorial:
http://www.linuxbsdos.com/2011/06/20/dual-boot-fedora-15-and-ubuntu-11-04-with-either-side-on-an-lvm-partitioning-scheme/
Everything worked as expected right up until the very end. My fdisk looks like this:
Disk /dev/sda: 41.1 GB, 41110142976 bytes
255 heads, 63 sectors/track, 4998 cylinders, total 80293248 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0008cb3f
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 1026047 512000 83 Linux
/dev/sda2 1026048 39938047 19456000 8e Linux LVM
/dev/sda3 39940094 77828095 18944001 5 Extended
/dev/sda5 39940096 40718335 389120 83 Linux
/dev/sda6 40720384 77828095 18553856 8e Linux LVM
Fedora is on /dev/sda2, and it booted up properly before I installed Ubuntu. Supposedly, following this procedure would result in both operating systems appearing in my grub. In fact, that’s the only reason I stuck to it. But, only Ubuntu showed up in grub after all was said and done. So, I used the terminal in Ubuntu to apply your fix. I set root=(hd0,2) — assuming the Ubuntu installation had rewritten my master boot record and installed Grub 2. Sure enough, the Fedora option appeared in my next boot-up. But, when I selected it, I got the following message from grub:
“error: invalid signature
Press any key to continue . . .”
Pressing a key or just waiting a few seconds brings me back to grub, where Ubuntu is my only functional selection. I noticed that my grub header said “GNU GRUB version 1.99-21ubuntu3.1,” so I thought that maybe I needed to change the set root value in your fix to (hd0,1), which I did. But, I got the same result — Fedora in the grub menu but not functioning. I even tried set root=(hd0,0) and set root=(hd0,3), for some reason. Same result.
Sigh…
Hllo, I have a new blog. I wanna collect ideas for Linux future 🙂 Thanks for this post.
Very nice tutorial, i would kiss you right now
Works like a charm, only tricky part is finding Windoze partition if its lost amongst the other ones, but indeed the best solution
Hi Eric…i have a laptop with win7 and then i’ve installed linux mint 17 but i dont have a choise to boot win7
fdisk – l command give this information
Device Boot Start End Blocks Id System
/dev/sda1 2048 16351231 8174592 b W95 FAT32
/dev/sda2 * 16351232 32704511 8176640 c W95 FAT32 (LBA)
/dev/sda3 32704512 566714367 267004928 7 HPFS/NTFS/exFAT
/dev/sda4 566716414 625141759 29212673 5 Extended
/dev/sda5 566716416 617588735 25436160 83 Linux
/dev/sda6 617590784 625141759 3775488 82 Linux swap / Solaris
What can i do to add a choise for win 7…what should i change to 11_Windows file to work?
(i dont know almost anything about linux)
Clever ! I got thru the LPIC-1 (old), the CompTIA book that I studied from didn’t go into Grub2 in depth. You certainly get KUDOs for Mastering Boot Loading and GRUB !
Nice work young man !
I have my windows in C drive but userdata is mapped to D drive. When I give “set root = (hd0,1)” I get the entry in boot menu but when I boot with it I get blue screen.