Sunday, July 19, 2009

How to boot from the grub console in Linux.

The following works in Ubuntu 9.04 Jaunty, but probably works in most versions of Linux. If you find yourself at the grub console line at boot time you can easily boot up your system with just a few commands.

To boot into Ubuntu we need to first specify the kernel. By default the latest kernel installed is linked to at /boot/vmlinuz. In the /boot folder lies all of the other kernels you have installed as well. At the console type:
kernel /boot/vmlinuz
You can stop there, but if you want a list of all kernels hit the tab key twice and it will list out each kernel. You can start typing any kernel you wish to boot from, but leaving vmlinuz will boot to the newest kernel.

Now all we have to do is tell grub to boot the os.
If you have Windows installed, we can still boot in it as well, however the instructions are different.

First we have to tell grub which hard drive and partition Windows is installed. The first hard drive, as the bios sees it is 0, and the second is 1 and so on. If you only have one hard drive then we know that it is on hard drive 0. Partitions are zero-based as well. If Windows is on the first partition, then it is partition 0, and so on. For our example Windows is installed on the first hard drive, but the second partition. Here is how we enter that.
root (hd0,1)
Remember that there is no space after the comma, but there is one after root. If you aren't sure what your options are, simply type everything up to the hd and hit tab. If you only have one hard drive it will auto-complete the "0," If you have more than one it will list the available hard drives. After you have selected a hard drive you can hit the tab key after the comma and it will again either give you 0 if you only have one partition on that hard drive, or it will give you a list of possible partitions to choose from.

The next three commands will bot up Windows:
chainloader +1
If you just find yourself back at the grub console, then you probably entered in the wrong hard drive and/or partitions. Keep trying until you find the right location of Windows.

I haven't tested this out, but if have multiple installs of Linux you can use the root and makeactive command to select the hard drive and partition of the Linux you want to boot into, and then use the kernel command to select the kernel on that hard drive and partition. If anyone knows for sure please drop me a line.