Manually adding an entry for Windows 7 to an Ubuntu GRUB2 menu

A recent endeavour of mine has been to set up a dual-booting arrangement on my Toshiba Equium laptop with Ubuntu 10.10 and Windows 7 on there side by side. However, unlike the same attempt with my Asus Eee PC where Windows XP coexists with Ubuntu, there was no menu entry on the GRUB (I understand that Ubuntu has had version 2 of this since 9.04 though the internal version is something like 1.9x; you can issue grub-install -v at the command line to find out what version you have on your system) menu afterwards. Thankfully, I eventually figured out how to do this and the process is shared here in a more coherent order than the one in which I discovered all of the steps.

The first step is to edit /etc/grub.d/40_custom (using SUDO) and add the following lines to the bottom of the file:

menuentry ‘Windows 7′ {
set root='(hd0,msdos2)’
chainloader +1
}

Since the location of the Windows installation can differ widely, I need to explain the “set root” line because (hd0,msdos2) refers to /dev/sda2 on my machine. More generally, hd0 (or /dev/sda elsewhere) refers to the first hard disk installed in any PC with hd1 (or /dev/sdb elsewhere) being the second and so on. While I was expecting to see entries like (hd0,6) in /boot/grub/grub.cfg, what I saw were ones like (hd0,msdos6) instead with the number in the text after the comma being the partition identifier; 1 is the first (sda1), 2 (sda2) is the second and so on. The next line (chainloader) tells GRUB to load the first sector of the Windows drive so that it can boot. After all that decoding, my final comment on what’s above is a simple one: the text “Windows 7” is what will appear in the GRUB menu so you can change this as you see fit.

After saving 40_custom, the next step is to issue the following command to update grub.cfg:

sudo update-grub2

Once that has done its business,  then you can look into /boot/grub/grub.cfg to check that the text added into 40_custom has found its way into there. That is important because this is the file read by GRUB2 when it builds the menu that appears at start-up time. A system reboot will prove conclusively that the new entry has been added successfully. Then, there’s the matter of selectively to see if Windows loads properly like it did for me, once I chose the correct disk partition for the menu entry, that is!

5 comments

Thank you for taking the time to not only show how to manually add a Windows entry, but also to explain what the different parts were. Thanks to you, I got my grub2 fixed and the dual boot is working fine now.

It needs to be pointed out that this was written based on a system that used BIOS and not UEFI. That may explain what you are getting. Is your partition table GPT because that triggers the UEFI needs? Setting up a GPT/UEFI system is different as you should see from a Windows GRUB entry for such a system:

menuentry ‘Windows Boot Manager (on /dev/sda2)’ –class windows –class os $menuentry_id_option ‘osprober-efi-xxxx-xxxx’ {
insmod part_gpt
insmod fat
set root=’hd0,gpt2′
if [ x$feature_platform_search_hint = xy ]; then
search –no-floppy –fs-uuid –set=root –hint-bios=hd0,gpt2 –hint-efi=hd0,gpt2 –hint-baremetal=ahci0,gpt2 xxxx-xxxx
else
search –no-floppy –fs-uuid –set=root xxxx-xxxx
fi
chainloader /EFI/Microsoft/Boot/bootmgfw.efi
}

Here, xxxx-xxxx needs to be replaced by the UUID of the partition where all the EFI boot files are stored.

Leave a Reply