Monday, May 16, 2011

GRUB'd

In my last post, I talked about how I had built my dream computer with two hard drives, each with it's own Operating System (OS). One is Windows 7 and the other is Ubuntu. At that point I was using the Basic Input-Output System (BIOS) to select the hard disk with the OS I wanted to load, and one of my future goals was to figure out how to add Windows 7 into the GRUB bootloader which is used for Ubuntu.

I accomplished that goal last night. I did some research first, searching for articles on how to set up GRUB to point to Windows 7. I read three of them and they all talked about editing a file named "menu.lst". I wrote down the syntax for adding Windows 7 to this file, booted into Ubuntu and proceeded to conduct a search for "menu.lst". It was not to be found. Not to be deterred, I started poking around.

In the articles I had seen a reference to the path "/boot/grub". I opened a terminal window and changed directories to that location.

There I saw a file named "grub.cfg" I opened it up with vi and this is what I saw.

This gave me the necessary bits of information I needed. I first proceeded to "/etc/grub.d", which is a directory.

I used vi to read the "README" file. Based on that, I was able to determine that I should edit the "40_custom" file. I used the command "sudo vi 40_custom" to edit the file. Using the "sudo" command temporarily elevates your privileges to that of root, which is the owner of these system files.

I used the syntax I had learned from the articles to add the entry enclosed in the box above. I then proceeded to the directory "/etc/default".

Once again, I used the "sudo" command to edit the file "grub" (sudo vi grub). I knew from the articles that the menu items index in GRUB starts at zero. Since I already had four entries on the existing GRUB menu list, I knew my new entry would be the fifth one, or number 4 with a zero-base count. I wanted to set Windows 7 as the default, so I set the default entry to 4.

After making that change, I ran the "update-grub" command as specified in the "grub" file, again using sudo: sudo update-grub. After that, I rebooted and was very happy to see Windows 7 as the last item on the list and highlighted as the default option.

I do have to say that I'm not positive adding the Windows 7 entry to the "40_custom" file actually did anything. In my entry, I set the title to "Windows 7". On the GRUB menu list it displays as "Windows 7 (Loader)". I don't know if GRUB added that last part to my entry or whether I could have saved myself the trouble of adding the entry and just run "update-grub" and it would have picked up Windows 7 itself. It's working great, so I'm not going to tinker with it. But let me know if you try that option and it works for you.

P.S. I wrote this entire blog post in Firefox on Ubuntu, using a screen capture tool called Shutter. How's that for open source?

No comments: