2

I have been running Ubuntu 14.04 on my desktop for a year now. Today, I got Windows 7 and installed it on a separate drive with the Ubuntu drive removed. Now I can boot each OS by interrupting the BIOS and changing the boot order, so I know both bootloaders work, but when I ran sudo update-grub and sudo udpate-grub2, Windows was not listed. What can I do to add Windows to grub?

Giaphage47
  • 327
  • 1
  • 2
  • 6

1 Answers1

0

Try to locate and mount the Windows partition first, then run sudo update-grub.

For example,

sudo fdisk -l

results

/dev/sda1            2048  53035007 53032960 25.3G 83 Linux
/dev/sda2        53035008  99139583 46104576   22G 83 Linux
/dev/sda3        99139584 141266943 42127360 20.1G 83 Linux
/dev/sda4  *    141266944 215681023 74414080 35.5G  7 HPFS/NTFS/exFAT

in this case the Windows partition is /dev/sda4 (because of NTFS Type and because I know it). Then,

sudo mount /dev/sda4 /mnt

and then

sudo update-grub

Windows entry in grub.cfg is nothing special. It is just a chainloader entry. If above method fails to identify Windows properly, then you can manually add the entry in /etc/grub.d/40_custom file.

Example of Windows 40_custom entry for MBR (not GPT)

menuentry "Windows 7 64bit" --class windows --class os {
        insmod part_msdos
        insmod ntfs
        set root='hd0,msdos4'
        chainloader +1
}

What matters here is the set root parameter. hd0,msdos4 = /dev/sda4. If you have more than one HDDs then it might be hd1,msdos4 = /dev/sdb4.

If you follow the manual method, don't forget to run sudo update-grub after editing the 40_custom file.

NickTux
  • 17,539
  • Does that code go in grub.cfg, or 40_custom? – Giaphage47 Dec 26 '14 at 00:13
  • The code goes to /etc/grub.d/40_custom , then sudo update-grub, but first try the automatic discover by mounting the Windows partition and running sudo update-grub. In any case, do not copy-paste the code from here, this is just an example (of my system). You should change the /dev/sda4 partition with yours. – NickTux Dec 26 '14 at 00:16
  • fdisk won't show the windows partition because the disk is formatted with GPT, so I used parted. Is the correct partition the one with the boot flag, the msftres flag, or the ntfs partition type? Thanks for your patience, by the way.

    EDIT: I'm sure the boot flagged partition isn't used by Ubuntu, because this disk was blank when I installed windows, if that matters.

    – Giaphage47 Dec 26 '14 at 00:19
  • If you have GPT, you can use gdisk instead. Also you must change other entries as well, insmod part_msdos to insmod part_gpt . Above example code is for MBR, not GPT. You can edit your question and add the results of parted command and also you can try both NTFS and msftres types with separate entries in 40_custom and see what is work. – NickTux Dec 26 '14 at 00:25
  • Then you cannot boot from grub. You need to totally reinstall Ubuntu in UEFI boot mode. Of if Ubuntu drive is gpt but BIOS boot then convert to UEFI. Grub will only boot systems installed in same boot mode either UEFI or BIOS as Ubuntu install. So all systems should be installed in the same boot mode. https://help.ubuntu.com/community/UEFI and: http://askubuntu.com/questions/221835/installing-ubuntu-on-a-pre-installed-uefi-supported-windows-8-system – oldfred Dec 26 '14 at 00:26
  • Tried 3 times to back up my home folder before formatting my drive, with 3 different errors. I'll just stick to switching through the BIOS until I have more patience. Thanks for the help, though, I'll comment here if I get it to work. – Giaphage47 Dec 26 '14 at 03:02
  • I've reinstalled Ubuntu on the drive where I installed Windows. Now Windows shows up in the grub menu, but my computer doesn't boot grub by default, it boots Windows. – Giaphage47 Dec 30 '14 at 04:18
  • And how you managed to show grub in first place ? Maybe you need to change the boot order in BIOS/UEFI ? – NickTux Dec 30 '14 at 15:04
  • For some reason, booting Ubuntu is only an option from the boot menu and not the BIOS setup. I can only select the drive from the BIOS, and there the drive is labelled "UEFI Hard Drive: Windows Boot Manager." – Giaphage47 Dec 30 '14 at 20:36
  • Probably this is because the UEFI implementation as @oldfred said above. Maybe you can't boot from the other HDD because of "Secure Boot" ? that's my guess. – NickTux Jan 03 '15 at 14:03
  • When I re-installed Ubuntu, I selected the unformatted portion of my SSD to mount at "/" and created a swap partition, and left everything else as default. This is the only thing I can think of that could have gone wrong; was I supposed to have the Windows boot sector mounted to /boot, or make some other change? – Giaphage47 Jan 07 '15 at 02:26