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

68 Responses to How to add Vista/Windows 7 partition to Grub 2 (Ubuntu 9.10, Karmic Koala)

  1. Geert says:

    Thank you,

    it works !!!!!!!!!!!!!!!!!!!!!

  2. Joe Chrysler says:

    Thanks for this informative, quick and effective solution!

  3. piggy says:

    Thanks worked for me

  4. Jon says:

    ur amazing thnx

  5. Juchmis says:

    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

  6. Fabien says:

    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

    • Tzes says:

      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???

  7. miche says:

    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

  8. wassim says:

    thanks a lot, it’s simple and it works :) )

  9. Usman says:

    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.

  10. Pingback: วิธี Dual boot บน Ubuntu 9.10 Karmic Koala หลังลงวินโดว์ทับ « ที่ว่างๆ ของคนธรรมดาคนหนึ่ง

  11. Andre says:

    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

    • Eric says:

      perhaps u got a typo somewhere ? i would recommend going it over agan

      • brad says:

        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?

      • Eric says:

        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

      • Andi says:

        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 ?

      • Jorn says:

        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.

  12. Ivan says:

    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…..

  13. Ivan says:

    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

  14. Ivan says:

    Windows 7 is on the

    /dev/sdb1

    partition.

    • Eric says:

      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 :)

  15. Aleksey says:

    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.

    • Lantesh says:

      “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.

  16. Balas says:

    Eric you rock!!! I am a newbie but I followed your instructions to a ‘T’ and it works like a charm !!!

  17. kt says:

    Thanks, grub2 is new for me, but this helped me a lot.

  18. Tijmen says:

    If your grub menu disappears have a look at this:

    https://wiki.ubuntu.com/Grub2#Where%20did%20my%20Grub2%20boot%20menu%20go!?!?!

  19. Michael says:

    Eric, Merci!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    It’s work. Great!.

  20. Steve says:

    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.

  21. madrioso says:

    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.

  22. QuAz@r says:

    Thanks man u are the king worked for me as well !!!

  23. schwiz says:

    Thank you so much !!

  24. schwiz says:

    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

  25. sandy says:

    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..

  26. Rand E. Gerald says:

    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?

  27. @acarback says:

    Thank you, Eric. This post is just what I was looking for.

  28. jk says:

    thumbs up! worked like a charm!

  29. Ben says:

    Thanks, your solution worked perfectly!

  30. frisquet says:

    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

  31. R2 says:

    Thank you Eric, you just saved me from totally re-installing. =D

    Thanx again.

  32. Pingback: Dual booting Ubuntu 10.04 and Solaris 10

  33. Hannes The Hun says:

    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.

  34. Siddhartha says:

    It works like a charm

  35. mark says:

    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

  36. Josh says:

    Hey
    My Windows 7 is on sda5, how do I do that?

  37. André says:

    those quotes will break the grub.cfg

  38. Eric H says:

    worked – nice quick solution. Thanks.

  39. badenia says:

    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?

  40. xyz says:

    Thanks a lot!!! it worked like a charm!! Very Thankful to You……
    Again Thanks!!!

    • yousry says:

      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+++ !!!

  41. Mark says:

    This worked. Thank You!!

  42. matej says:

    thank you!

  43. henrik says:

    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: 0×97559755

    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: 0×00000000

    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

  44. thisisme says:

    Man, thanks. It works like magic. I tried to read some documentation but this one is the simplest and the shortest script.

    you rock!

  45. Pingback: Setting up Grub to multiboot

  46. Colin Cedric says:

    thank you mean, you save my life ^^.

  47. Pingback: Sistem Operasi Idle Cuma 60MB dan Processor Usage 1% | Uchan

  48. AJ says:

    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?

  49. m3nt4t says:

    Thanks, just what I was looking for.

  50. 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.

  51. Pascal says:

    Wow thanks!!!

  52. rasputi says:

    Thx. You saved my Life

  53. Joseph says:

    Perfekt Work!!! THX… There is some documentation???

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

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

Twitter picture

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

Facebook photo

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

Connecting to %s

Follow

Get every new post delivered to your Inbox.