12 December 2015

Fixing the Grub boot options if your Linux installation does not see the Windows installation

A colleague and another experienced colleague had trouble installing Linux on a machine because Windows wasn't being recognized after Linux installation. The department head as usual, recommended me to them, as the go-to guy when others couldn't solve it either.

This problem was new to me. I had never had any problem with a dual-boot system. First install Windows, and then Linux. Grub would always show Windows as one of the boot options.
But here, after installing Linux, only the Linux boot options were shown. At first all of us thought that all hope was lost, and we'd have to reinstall Windows and settle for a lower version of Linux which would recognize the Windows partition.

A bit of searching showed me that all that actually had to be done, was to point Grub to the Windows partition.

The technique
  • First, login to Linux.
  • Open a terminal and use "su" to login as root user.
  • Type "cfdisk". This will show you all the partitions available, including the Windows partition.
  • At the left of the cfdisk output, you'll see "boot". Take note of the partition name which is on the same line. It might either be "sda1" or "sda2".
  • Open the Grub config file with "vi /boot/grub2/grub.cfg".
  • You'll see some lines which say "menuentry". Above one such "menuentry", add a menuentry for Windows, like this:

    menuentry "WINDOWS"{
    set root='(hd0, msdos1)'
    chainloader +1

This is if  the partition name you saw near the "boot" flag was /dev/sda1.
If it was /dev/sda2 you saw, then change the "msdos1" text to "msdos2".
Then type "grub2-mkconfig" to finalize your changes.
Reboot the system, and you'll find Windows also as a boot option!!!

p.s: When the system boots, if you want a more fancy name instead of just "Windows" in the Grub menu, you can change the "WINDOWS" text in the above code to make it "Nav's awesome Windows OS" or something like that.

The wish for a better bootloader

For a long time, I have wished that boot-loaders would be more reliable. If a person installs five different operating systems on five different partitions of the same hard disk, is it so hard to create a third-party boot-loader which is on a separate tiny partition, and able to recognize all five OS'es without even being told that there are OS'es on each partition? It would have been such a boon to have such a boot-loader which would automatically create the menu for us.
I even asked on SuperUser and got two upvotes but no response: http://superuser.com/questions/1009739/have-separate-bootloaders-for-windows-and-linux-on-a-single-hard-disk

No comments: