Technology Tales

Adventures in consumer and enterprise technology

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

Published on 21st November 2010 Estimated Reading Time: 3 minutes

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 side by side on there. 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 of the form 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 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 (staring with chainloader) tells GRUB to load the first sector of the Windows drive so that it can boot. After all that decoding, my final remark 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 in 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!

Comments:

  • Richard Mansell says:

    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.

  • Matthias says:

    Thanks!

  • Deli Soft says:

    Thanks! It’s working.

  • Kim says:

    I get an invalid EFI file path?
    It shows up in the boot menu but windows isn’t loading. Have I done something wrong?

    • John says:

      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.

  • The content, images, and materials on this website are protected by copyright law and may not be reproduced, distributed, transmitted, displayed, or published in any form without the prior written permission of the copyright holder. All trademarks, logos, and brand names mentioned on this website are the property of their respective owners. Unauthorised use or duplication of these materials may violate copyright, trademark and other applicable laws, and could result in criminal or civil penalties.

  • All comments on this website are moderated and should contribute meaningfully to the discussion. We welcome diverse viewpoints expressed respectfully, but reserve the right to remove any comments containing hate speech, profanity, personal attacks, spam, promotional content or other inappropriate material without notice. Please note that comment moderation may take up to 24 hours, and that repeatedly violating these guidelines may result in being banned from future participation.

  • By submitting a comment, you grant us the right to publish and edit it as needed, whilst retaining your ownership of the content. Your email address will never be published or shared, though it is required for moderation purposes.