Solving the problem of missing Windows 7 entry in grub2 on Fedora 18

I installed Fedora 18 on laptop a couple of weeks back. I basically set up a dual boot system alongside with Windows 7 as I sometimes need Windows to play games and stuff. Despite the installer being pretty convoluted, I managed to install Fedora 18 successfully. After installation though I didn’t find any entry for Windows 7. My first reaction was that I might have corrupted the windows partition, but I checked and it was not the case. After searching for some time, I came across a pretty straightforward solution to this, which is as follows:

1. First we have check for the partition where our windows is installed. For that we need to fire up the terminal and use the following command:

sudo fdisk -l

There should be an output like this :

Disk /dev/sda: 320.1 GB, 320072933376 bytes, 625142448 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: 0xe3d12c7c

Device Boot Start End Blocks Id System
/dev/sda1 * 2048 357074943 178536448 7 HPFS/NTFS/exFAT
/dev/sda2 357074944 519493904 81209480+ 7 HPFS/NTFS/exFAT
/dev/sda3 519495680 520536063 520192 83 Linux
/dev/sda4 520536064 625142447 52303192 5 Extended
/dev/sda5 520538112 625141759 52301824 8e Linux LVM

Disk /dev/mapper/fedora-root: 12.6 GB, 12582912000 bytes, 24576000 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes …..

In my case I have my Windows 7 installed in /dev/sda1 partition, which might be different for other people so it’s better to check.

2. Now we need to create a custom grub script to add the Windows entry in the Grub menu. Create a file 15_Windows in the /etc/grub.d  folder and add the following lines to it.

 #! /bin/sh -e
echo "Adding Windows" >&2
cat << EOF
menuentry "Windows" {
set root=(hd0,1)
chainloader +1

Note that we would need root permissions to create this file. Also on the line

“set root=(hd0,1)” , it depends on the partition where we have installed our windows on. My Windows was on my first hard disk ( the only one for that matter) and the first partition, hence hd0,1. hd0 refers to the first hard disk and 1 refers to the first partition. Edit this line to point it to the appropriate Windows partition.

3. Now we make this script executable by all users using the command:

chmod +x /etc/grub.d/15_Windows

4. After this we need to update the grub2 configuration file so that the script we created is always loaded at boot time. The following command accomplishes that

grub2-mkconfig -o /boot/grub2/grub2.cfg

And there all done. The next time you boot your computer, you should see the Windows option in the grub2 menu.

I found the guide originally here.