Linux newbies often get frightened by GRUB errors. This article will give you an insight of “What the hell is this GRUB ??” and may also help you solve you many GRUB errors.
What is GRUB ??
GRUB is a boot loader. Now, you *might* be asking what is boot loader (calm down! you would get to know as you read on.)
FYI: GRUB stands for GRand Unified Bootloader.
How does GRUB work ??
During the boot process, BIOS transfers its control to the booting device according to the priority set in the BIOS. For the sake of simplicity, let us assume that our first boot device is our hard disk.
The first sector of Hard Disk is called the Master Boot Record (MBR). This sector is only 512 bytes long. It contains the partition table (64 bytes) describing the primary and extended partitions and the primary boot loader (446 bytes). Now you can figure out, why there can be only 4 primary partitions or 3 primary partitions and 1 extended partition. (Size of partition table is fixed)
GRUB replaces default MBR with its own code. But GRUB is too big to fit in MBR, so it works in stages.
STAGE 1 : This stage either points directly to STAGE 2 or it points to STAGE 1.5 which loads STAGE 2. STAGE 1.5 is stored immediately after MBR. STAGE 2 can be located anywhere on the disk.
STAGE 2 : This stage contains all the configuration files which results is complex user interface and menus we normally see.
GRUB Naming Conventions
The naming convention used in GRUB is bit different from Linux and Windows.
Following examples will clarify the naming convention rules -
(fd0)
The device name must be enclosed in ‘(‘ and ‘)’ . The ‘fd’ part means floppy disk and similarly ‘hd’ means hard disk. The number 0 indicates the drive number which starts from 0. This expression means the grub will use the entire floppy disk.
(hd0,1)
hd means Hard Disk. The 0 here indicates the drive number that is the first hard disk. And the integer 1 here indicates the partition number. Here again partition number starts from 0. So, 1 indicates the 2nd partition. This expression means the second partition of the first hard disk. In this case GRUB uses only one partition of the hard disk.
(hd0,4)
This expression specifies the first extended partition of the first disk. Important point to note is that, the partition number for extended partitions are counted from 4, regardless of the actual number of primary partitions on the disk.
Another point to note is that GRUB does not differentiate between IDE and SCSI drives unlike Linux.
GRUB command line interface has TAB completion feature. For example :
grub> root (
If you press <Tab> at this point, GRUB will display the list of drives and partitions.
To specify a file we write like this:
(hd0,0)/vmlinuz
This expression means the file vmlinuz in the first partition of the first disk. Tab completion works with file names as well.
Now let use explore few configuration files of GRUB
How to change the GRUB menu ?
GRUB menu that we see when we boot a system with Linux is generated from the file
/boot/grub/menu.lst
Lines starting with a hash (#) is a comment. One can safely edit this file to customize the menu that we see at the start up. Let us quickly analyze this file.
Here’s a screenshot of my menu.lst file :
At the top you will find a line (this line is not visible in the above screenshot):
default 0
This sets the default entry, i.e. the the Operating System that will load by default if you do not press any key for a specified number of seconds. Here 0 signifies the first entry in the menu. As usual numbering starts from 0.
Another line you will se somewhere near the above line is
timeout 3
This sets the timeout in seconds, before automatically booting the default entry starts. Here 3 signifies three seconds. You can easily change 3 with any number according to your convenience.
Another optional line is
hiddenmenu
If this line is present, menu will not be displayed by default. This is by default set in Ubuntu and unset in Fedora.
We can have a colorful GRUB menu by setting this line :
color cyan/blue white/blue
Syntax of this line is
color normal [highlight]
The colour normal is used for most lines and the color highlight is used for the lines where the cursor points. Highlight color is optional. By default, the inverted colour of normal is used for highlighted line. The format of a color is foreground/background. The colors that can be specified here are limited and can be found in GRUB manual pages. We can even have different menu items in different colours. I will write about coloured GRUB menu in some other post. Stay Tuned !
Now lets come straight to the menu items. Consider an example:
title Ubuntu 8.04.1, kernel 2.6.24-19-generic
root (hd0,0)
kernel /boot/vmlinuz-2.6.24-19-generic root=UUID=ee3978bb-3563-4445-a6c4-6ba90675cbac ro quiet splash
initrd /boot/initrd.img-2.6.24-19-generic
- title: This one is simple. Simply edit it and get your own custom title for every menu entry.
- root (hd0,0) tells grub to look in the 1st partition of 1 disk.
- kernel specifies the location of kernel image
- initrd is the temporary file system image
There can be many blocks like the above one in your menu.lst file. To remove any entry from the GRUB menu, comment the entire block by placing a hash (#) at the beginning of every line.
And take a backup of menu.lst file before making any changes.
Booting from GRUB command line interface.
Sometimes when you delete a partition or resize a partition or … bla bla … and then restart you computer you see an error like
GRUB error 22 …..
or may be some other error and u see a grub prompt like this
grub>
To boot for the grub prompt follow the following steps:
You need to know which disk and which partition contains your kernel image.
grub> root (
press <tab> at this point and the all disk and partitions will be displayed. enter the correct partition at the prompt. Say for example linux kernel image is on the first partition of first disk.
grub> root (hd0,0)
grub> kernel /vmlinuz-.. root=/dev/sda1 ro
this loads the kernel. Here also you can use tab completion feature to find the exact filename. You can specify some other options like ro , vga etc. After this just enter boot :
grub> boot
And voilla ! you see your linux booting.
If you use initrd, execute the command initrd after kernel at grub prompt like this :
grub> initrd /initrd.img-…
Again Tab completion helps you in completing the file name.
Booting Windows from GRUB prompt:
Say for example windows is installed on 1st partition of first hard disk.
grub> rootnoverify (hd0,0)
grub> makeactive
grub> chainloader +1
grub> boot
Woow.. you see your Windows booting normally.
There’s a lot more about this GRUB. If you are interested in learning more read the GNU GRUB Manual . I also learnt from this manual only.
If you want me to explain any particular thing in this post drop down a comment.
And even if you find any mistakes please drop down a comment.
…………

Ubuntu has a gui for that called startupmanager. It lets you use pull down lists of all that is in the grub and simple check boxes for grub options. sudo apt-get install startupmanager
@phil
You are true I forgot to mention it in the blog.
For n00bs who want to customize their GRUB menu, they can use a package startupmanager.
Thanks for reminding me.
Though my main aim was to explain about GRUB.
Doesn’t the windows have a boot loader?i had windows and fedora on my PC.after doing a windows recovery,i was not getting any boot menu to start the linux OS.
@Anurag
Windows also has its own boot loader. That is why when we boot Windows from GRUB we enter the command
grub> chainloader +1
This calls the windows boot loader. Windows Bootloader’s name is NTLDR .
Anyways when you did a Windows recovery, Windows replaced its own boot loader code in MBR. So, your computer now is not able to know if there is any Linux OS installed. You can easily get back your Linux by installing GRUB.
May be I will write another Blog on this issue.
Till then you can check out this link : https://help.ubuntu.com/community/RecoveringUbuntuAfterInstallingWindows
I am wondering if you can change the UUID thing to something move human readable like dev1 in GRUB.
@nearownkira
Ya we can use Linux disk notation instead of UUID like this
root=/dev/sda1 instead of root=UUID=…..
Though we can always find UUID corresponding to any drive using following commands as root :
1) blkid or
2) vol_id
Anything else??
Hi,
Thank you for the guide. I have some problem with grub loader.
The unit has Fedora 8. grub waits for a “Press any key to continue” at stage 1.5 to go to stage 2. I want to use this box in setting where no human interaction. Therefore need to boot without waiting for a key press at any stage. From stage 2.0, I can manage the timeout with grub.conf file. But do not know, how to remove the wait for the key press at stage 1.5.
Would be a great help, if I know how to solve this problem.
Thanks.
Kumudini
Hello
I have created bootable grub CD for ubuntu 9.I want to boot it from command.
But on grub prompt, error message is printed that file not found.
Thanks
Madhukar Ojha
Hello. Very good post. I have a question and hope you can help me. I want to make a grub entry for a windows partition but using UUID and don’t know how the exact syntax goes (and whether it’s possible).
So instead:
rootnoverify (sd0,0)
chainloader +1
what should I change and where to put the UUID?
Thanks in advance.
what do i add to grub.conf to boot up straight to a default user without prompting for a password? (I did it in an older version of fedora but forgot and did not save the file, sorry)
I found it:
but, as luck would have it, it is not in grub.conf but in /etc/gdm/custom.conf
the lines to add at the bottom are
[daemon]
TimedLoginEnable=true
TimedLogin=greg
TimedLoginDelay=1
I set the time delay to 5 for a few days – till I was sure it was what I wanted, then I set it to 1.
maybe you can clarify this a little. It is not exactly the /boot/grub/grub.conf file, but grub must be the one in control.
Thanks
I found it:
but, as luck would have it, it is not in grub.conf but in /etc/gdm/custom.conf
the lines to add at the bottom are
[daemon]
TimedLoginEnable=true
TimedLogin=user <– your user-id
TimedLoginDelay=1
I set the time delay to 5 for a few days – till I was sure it was what I wanted, then I set it to 1.
maybe you can clarify this a little. It is not exactly the /boot/grub/grub.conf file, but grub must be the one in control.
Thanks
interesting. myself I have just found this cool CD for booting and repairing Windows at windowsbootcd.com, trying it out right now
Pingback: Diigo – tg3793 ‘s Bookmarks | Gott Marks !!!!
Pingback: GRUB | Warren Tang's Blog