Make your own free website on
Grub Tutorial for non-Geniuses

Hurray, I figured it out. Grub demistified. Well, almost...
I can now tell you how a Linux system is booted, step by step. A thing that with years and years of experience, I have not found out in WIndows XP and never will, because it is a closed (yuCK!) intransparent proprietary system.

You might still benefit from a PhD to follow this, since there are hardly any usable GUIs around when dealing with Grub.

What is grub?

Grub, the GRand Unified Bootloader simply said is the boot loader thingy in Linux. It take the computer from stoneage BIOS world into modern OS level. It bridges the gap of the dumb BIOS that can basically done nothing at all into booting the OS.

Although you can use grub to boot Windows XP, people use it usualy for Linux or dual boot.

One of the BIG problems for newbies (I remember my pain) is when you are stuck in Grub, with a system that won't boot.

Needing a comfortable GUI or help in this cold and alien environment is hard to come by. In order to get all the fancy automatic tools, you gotta boot up the OS and to boot up the OS, you need Grub working.. A conundrum.

Grub has some terms that are pretty much nowhere defined properly. You might still know that /dev/hda1 is the first partition of the first hardisk, but what the heck does (hd1,5) mean? And why do we have to put up with it?

This all shall become clear in a minute and I am writing this here in order to take the pain off somebody coming after me to the same problem.

Here is it, the step by step moves that Linux does from BIOS till having the root filesystem mounted.

Step 1: BIOS

As dumb as the BIOS is (good riddance, give us EFI A.S.A.P. please), it cannot do much. It can however read the MBR and execute.
The basic code to access the harddisk is written there by Grub and executed, namely where the /boot partition is located.

From there it reads stage1 and stage2 and starts up Grub.

Step 2: Grub config

Grub reads menu.lst and from the /boot directory and displays the choices that are defined in menu.lst

this, among other things, may include:

title           Debian GNU/Linux, kernel 2.6.18browny-suspend-etch5
root            (hd0,0)
kernel          /boot/vmlinuz-2.6.18browny-suspend-etch5 root=/dev/hda1 resume2=swap:/dev/hda2 ro vga=ext

title           Debian GNU/Linux, kernel 2.6.18browny-suspend-etch5 (recovery mode)
root            (hd0,0)
kernel          /boot/vmlinuz-2.6.18browny-suspend-etch5 root=/dev/hda1 resume2=swap:/dev/hda2 ro single vga=ext


This will generate two choices to choose from on the Grub menu selector. Checking out the text later below, you will find that grub defines the same things in the config, that we can also do by hand in the Grub command line tool itself. (that you get into by using the floppy below, for example)

Step 3: Mount root filesystem and boot OS

Grub gets the main harddisk (the thing called root in Grub), the kernel from the config,  and maybe the initrd (in the above example, there is none) and has everything to start the kernel.
The parameter behind the kernel name are information that is passed on to the kernel, resume2=swap://dev/hda2 for example tells the kernel that it should take the swappartition hda2 for resume and hibernate business.
This is also the reason why I use a custom made kernel, since hibernate/software suspend just did not work on normal stock kernels as to this writing.

How to get back on the luxury ship from rickety float

If you have a broken hd or cannot figure out on which MBR is it written and need to get into Grub, just use this line to create a boot floppy.
(Now I am not advocating the use of floppies. It is an old and evil technology that deserves to be banned like toxic waste, yet many but the newest systems are too crappy to boot off a USB stick, blame goes to.... BIOS)

This is pretty simple and illustrates pretty much how Grub works, including all the tools you need to figure out how to boot your derailed system (the probably reason you are in Grub in the first place)

cat /boot/grub/stage1 /boot/grub/stage2 > /dev/fd0

Cool and simple enough, this just takes the two files (binary), and copies them raw on the floppy, one after the other.

If you boot from the floppy on a naked system, you get the Grub boot prompt running... Interesting enough, the system just seems to read from the floppy directly and execute the first sectors. I have not figured how this works on USB sticks yet.

From here you can do some nice things, IF you know how to, hence this tutorial.

to boot your system, you need 3 things:

  1. the root device (mind you, that is the Grub root device), meaning the main harddisk or partition that Grub will focus on and get its files from.
  2. the kernel
  3. maybe the initrd (initial ram disk, if your distro needs that) Debian does as a standard.

The important stuff now and that nobody seems to mention:
You can "google" around in Grub for the attached harddisks and partitions by using the lovely command or file completion that make the Linux command line so cool and DOS so sucky.

to provide info number 1, type
root (  and press TAB

immediately Grub spews:

grub> root (hd
 Possible disks are:  hd0 hd1 hd2 hd3

Now we know that the BIOS at least recognizes these disks. The BIOS calls these disks like that, and remember, it starts with 0 not with 1, as in /dev/hda1.

giving Grub a little more to go on

grub> root (hd1,   and TAB again

Grub provides nice info about what we have here. I was so far always looking for a command that would show what is available hd and partition wise and found none. Here it is finally.

 Possible partitions are:
   Partition num: 0,  Filesystem type is ext2fs, partition type 0xfd
   Partition num: 1,  Filesystem type unknown, partition type 0xfd
   Partition num: 2,  Filesystem type is ext2fs, partition type 0x83

now lets say we have the /boot partition on partition number 2 and set it so:

root (hd1,2)

we can go and provide info nr. 2:

kernel /   and TAB again  

will show us a nice variety on kernels that are available.

 Possible files are: lost+found vmlinuz-2.4.27-3-386 config-2.4.27-3-386 grub config-2.6.8-3-k7 initrd.img-2.4.
27-3-386 vmlinuz-2.6.8-3-k7 initrd.img-2.6.8-3-k7

the filename complete works wonderfully, so we don't have to type in all the version riff raff.
root /vmlinuz-2.6.8-3-k7 initrd.img-2.6.8-3-k7 root=/dev/md0 ro vga=ext

now to explain, the root device mentioned with /dev/md0 is the one that is the final Linux root, in my case a software RAID and ro defines that the filesystem is mounted read only first. Finally, with the vga=ext we get slightly (much more) text on the screen ;-), since we got our glasses on and graphic cards and monitors these days can handle more then 80x25 characters.

now provide info nr. 3, the initrd, if you need it, same way as with the kernel:

initrd /initrd.img-2.6.8-3-k7

(make sure it is the same version than your kernel, unless you want to see some really funky effects, like installing palm trees from the jurrasic era into your 21st century high tech city ;-)

now, let give it a go and boot up:


If you get a panic from the kernel being unable to mount the root filesystem, something is still going wrong.
Otherwise you will be happy on the way to start your system again.

I hope this was insightful, as short as it is. I of course also provide also support for companies with stranded unbootable servers, where time is of the essence and the offline system in a pickle.

this document was created on:

10. Jan. 2007
updated on:
10. Jan. 2007