Wednesday, June 22, 2011

Adding Windows to GRUB in Debian Squeeze

Recently I installed Debian 6 Squeeze on my notebook, where I already have an installation of Windows 7 Professional. For work reasons I couldn't delete this installation, so I installed Debian on a logical partition. During the installation everything went good, even at the moment of the GRUB configuration (GRUB detected the Windows Loader), but when I booted for the first time there wasn't an option to boot Windows. So this is the steps I made to add the menu entry.

The first step is to check the names of the partitions:

tepeyolotl@satellite:/$ sudo fdisk -l|grep NTFS
[sudo] password for tepeyolotl: 
/dev/sda1   *           1          13      102400    7  HPFS/NTFS
/dev/sda2              13       16908   135705600    7  HPFS/NTFS
tepeyolotl@satellite:/$ 

The fdisk command is only available to the superuser (you can also execute all of this commands from a root terminal), th -l option lists the devices and the outputis piped to the grep to be filtered. We note that the partition we search for is listed in "/dev/sda2".

The next step is create a script to indicate this info to the GRUB.

tepeyolotl@satellite:/$ sudo gedit /etc/grub.d/11_windows

This command opens the file (if it doesn't exists, it will be created), due to the directory in which we're working we need to execute this command as superuser. In the file we should type this:

#!/bin/bash
cat<<EOF
menuentry "Windows 7 Professional"{
set root(hd0,2)
chainloader (hd0,2)+1
}
EOF

The important thing here is the fragment "(hd0,2)" which indicates the partition with the OS that we are adding to the menu. Save the file, and give the file permissions as executable, after that, the only thing to do is update the grub.

tepeyolotl@satellite:/$ sudo chmod +x /etc/grub.d/11_windows
tepeyolotl@satellite:/$ sudo update-grub
Generating grub.cfg ...
Found background image: /usr/share/images/desktop-base/desktop-grub.png
Found linux image: /boot/vmlinuz-2.6.32-5-686
Found initrd image: /boot/initrd.img-2.6.32-5-686
Found Windows 7 (loader) on /dev/sda1
done
tepeyolotl@satellite:/$

And that's all, the menu entry is now ready to start Windows 7.

No comments:

Post a Comment