INFO: GRUB2 – 101 Class
Purpose: Since the next generation of GRUB, GRUB2, is slowly trickling down to all major Linux distribution, I thought about writing a basic post regarding GRUB2, which discusses some of the fundamental change in GRUB2. Also the documentation on GRUB2 is not very extensive at this point of time. I am assuming that you have already upgraded to GRUB2. If you are looking for how to install splashimages in GRUB2, see this post.
To begin with, the following files and directories are important to us:
/boot/grub/grub.cfg (/boot/grub/menu.lst file in old GRUB)
/etc/default/grub
/etc/grub.d/
Also the commands:
update-grub2 (update-grub in old GRUB)
grub-mkconfig (Recommended)
are also very important if we really want to customize GRUB2 menu.
Note 1: Never edit the file/boot/grub/grub.cfg
Do not edit this file manually. Do not open the file in a text editor and start editing the entries. You might be tempted to do this but in the long run you are bound to face problems. This file basically constructs how your GRUB2 screen looks like when you boot your system:
This file is auto generated by the following command:
/usr/sbin/grub-mkconfig
and the following file:
/etc/default/grub
and templates/files from the following directory:
/etc/grub.d/
Note 2: Use grub-mkconfig instead of update-grub
For those of you who are use to using update-grub in the legacy version of GRUB, you should use
grub-mkconfig
If you use:
update-grub2
then you will see warnings like the following:
Warning: update-grub_lib is deprecated, use grub-mkconfig_lib instead
Note 3: Partition numbering
In previous version of GRUB, we use to refer to a partition with partition number – 1. In GRUB2, we simply refer to the partition with the same number. For example, in GRUB, the following were the mappings:
/dev/hda1 - (hd0,0)
/dev/hda5 - (hd0,4)
/dev/hdb2 - (hd1,1)
However in GRUB2, the above translates to:
/dev/hda1 - (hd0,1)
/dev/hda5 - (hd0,5)
/dev/hdb2 - (hd1,2)
I personally think that it is a very good change.
Note 4: Adding a custom entry
You can add a custom boot entry in your GRUB2 menu in two ways:
Method 1:
apt-get install os-prober
os-prober
grub-mkconfig
Basically, the os-prober will detect any additional Operating Systems that are installed on your hard drive and will list them at the end. Also I think it adds the respective entries in the file:
/etc/grub.d/30_os-prober
I have not tried this method. If you do try and find problems please post it in the comment section and I will correct it.
Method 2:
Edit the file:
nano /etc/grub.d/40_custom
and add the entries like the following (example only):
#! /bin/sh -e
echo "Adding Windows" >&2
cat << EOF
menuentry "
Windows XP" {
set root=(hd0,1)
chainloader +1
}
EOF
and give the following command:
update-grub2
That’s it!
Hopefully this post has given you enough basic to start your exciting GRUB2 journey.



Email Subscription









October 4th, 2009 at 12:50 pm
Thanks for the info!
Reply to this comment
November 21st, 2009 at 9:08 am
OS-Prober doesn’t detect frugal installs such as Puppy Linux on the same partition. Wish there was a GUI for adding installations, because this is way more complicated than Grub1
Reply to this comment
June 30th, 2010 at 11:29 pm
In Note 2 you refrain us from using ‘update-grub2′ and in Note 4, Method 2 you are using it. Why so?
Is there a reason behind it or is it a mistake?
Reply to this comment
October 18th, 2010 at 1:08 pm
os-prober, nor update-grub2, nor grub-mkconfig doesn’t detect puppy linux.
I have one installed on /dev/sda7
From Xubuntu:
/media/puppy$ ls
extlinux.conf initrd.gz lupu-511.sfs vmlinuz
Reply to this comment
Admin Reply:
October 19th, 2010 at 4:17 pm
I think GRUB2 looks for the kernel and related installation information under /boot directory. I don’t think it looks in /media directory.
Reply to this comment
October 19th, 2010 at 10:39 pm
Well, at the moment I use Xubuntu, and the partition sda7 is mounted there, but it is a clean partition, nothing else is there.
If grub2 is looking for them, I think it is looking before Xubuntu mounts the partition at /media/puppy, doesn’t it?
So, do you have a line for me to put in grub.cfg for this little thing?
http://ubuntuforums.org/showthread.php?p=9992343#post9992343
-there are a few more details about my laptop.
Thank you :)
Reply to this comment
January 2nd, 2011 at 8:06 am
What a nightmare. It’s little things like editing a grub2 menu that should be easy but are not. WHY!?? Can someone smarter than me create a program that does this? All I want to do is change the names and maybe the order without graduating from MIT first.
Reply to this comment
May 30th, 2011 at 12:43 pm
How is this progress?
We count from 0 in one instance, and from 1 in the other. I could never teach any student of mine to invite this kind trouble.
We can’t directly edit config files, as we can with every other Linux program and feature. Quite un-Linux like.
This new version is MANY years old, and STILL can’t be called GRUB v2.
Adding a new OS boot – or fixing a screwup – is so simple with old GRUB that the new isn’t worth anything more than noticing every 3 years or so that it STILL is experimental.
Reply to this comment
June 5th, 2011 at 2:20 pm
[...] de grub2 sur ma Debian. J’ai trouve une petite page bien sympathique expliquant Grub 2. Pour info, j’ai edite /etc/grub.d/40_custom et rempli avec ce qui suit : #!/bin/sh echo [...]
June 10th, 2011 at 3:57 am
I second David, this is the opposite of the right way to go. Any “grand unified” bootloader should be entirely independent of the instances it boots, it should ideally come with its own installer, too, so that, in a pinch, we don’t need any complete OS instance to handle it.
Also, old GRUB is very nice with extended multi-booting. Just create sub-directories off /boot, throw needed images etc into them, let the menu entries point to the right places, and there is no room for confusion.
This way, we can run without /boot being mounted, which is very good for robustness and safety. Also, using ext2 on /boot is simple and adequate, with minimal chances for screwing anything up, as it is only mounted during first stage booting, and normally, there is no need for updating anything – that’s just in maintenance.
Reply to this comment
September 14th, 2011 at 11:55 am
[...] Basics and fundamentals of GRUB2 [...]
August 13th, 2012 at 7:07 am
I believe that linux developers are masochists. Things instead of getting easier, they are getting more complicated. Usually Linux was a kind a freedom for me – nowadays everything is getting worse. New Gnome – I mean Unity is kind of shit, good maybe for smartphones – not for desktop PC (how does it look like). Thanks the Lord I can use Gnome classic but why they force us to use pulseaudio, epiphany ?? Now very complicated GRUB2 (try to change it from inside the distro, which GRUB2 hasn’t been in installed with). Linux Developers – why do you change things that are working well, why do you make everything more complicated ?? Better is enemy of the good – isn’t it ??
Reply to this comment