TechFRP Search

Custom Search

Friday, December 10, 2010

Change Grub Default OS in Ubuntu

     If you have Multiple Operating systems installed on your PC with Ubuntu/Linux then you're probably at least aware of the Grub Boot Loader. Grub, included with Ubuntu, automatically checks during installation for an Operating System already installed. If there is one, then Grub is automatically configured to allow you to choose which operating system to boot when you start your PC. It is a good tool and it does it's job well.

     After all Operating Systems are detected and you've rebooted you'll notice the Grub Boot Loader as the first thing after your hardware's load screens. Here's a sample of what it looks like below.

     In this example I don't have multiple operating systems installed but I do have Multiple Linux Kernels that you can choose to boot just like you would an Operating System. The Highlighted entry is the default instance created when Ubuntu was installed. You can see at the bottom that a Timer is counting down from 10 seconds. If you don't choose a different entry from the list within that time it will automatically start the default instance, in this case, Ubuntu with Linux Kernel 2.6.32-26.

     The great thing about Grub is that it is very customizable. One of the features you can customize is the Default OS entry. If for example I wanted to boot Ubuntu with Linux Kernel 2.6.32-25 instead by default, I can do this by changing the Grub.cfg file. Linux Kernel 2.6.32-25 could easily be Windows XP or Windows 7 if those operating systems had been detected during install.

     A word of advice before we begin. It is good practice whenever making changes to configuration files of any kind to make a copy of the file before you begin. Whether it's through Nautilus or at a command line copy the Grub.cfg file to a backup location for reference and possible replacement if for any reasons things don't go as planned.

     Now to change the default OS selection we need to go in and edit Grub.cfg which is located under /Boot/Grub. There are several ways you can do this, the quickest is to open a terminal and enter the following:

     The Gedit graphical word editor will popup with the Grub.cfg file loaded. Change the line Highlighted below to the Sequential number in the listed order starting with "0" that you want to boot by default. In this example to boot the Linux Kernel 2.6.32-25 counting from "0" would be "2" for the 3rd item listed.

Unedited Grub.cfg file set to "0"

When updated it should look like this:

Click Save and close Gedit.

     When you reboot your PC the next boot up should now have the 3rd option from the top highlighted as the default OS to boot.

     As I said earlier the Linux Kernel 2.6.32-25 entry could just as easily be Windows XP, Vista or 7. The key thing to remember here is that the numbering begins at "0" not "1". As long as you count correctly from the top when assigning the number in the Grub.cfg file then you can't miss.

     To undo any of these changes simply reverse what you did and assign "0" again in the Grub.cfg file. Easy Peasy, hopefully. As always, these steps have been tested in my lab setup and work correctly in my environment. If they don't work for you or you encounter problems with your PC after, I take no responsibility for any problems you may encounter. That being said, you really shouldn't experience any issues with this so long as you follow the steps outlined above.

     Next Week we'll look at how to remove extra Kernels from your system and the Grub loader.

    Until then, I hope you found this tip helpful. If you did, please let me know, leave a comment.

No comments:

Post a Comment