LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Linux Answers > Applications / GUI / Multimedia
User Name
Password

Notices


By widget at 2010-09-23 12:36
Grub2 Introduction

There is a lot of great information on grub2 on this forum.

I wrote this up to give folks a flying start. This will not make you an expert but it will, hopefully, get you headed in the right direction.

Some people have trouble, right after installation, with other OS' being missing from the menu. The first thing to do for this is go to your terminal and;
Code:
sudo update-grub
Run this to have /boot/grub/grub.cfg output to your terminal to check it;
Code:
sudo grub-mkconfig
Grub2 is completely different from grub-legacy. If you are using grub2 be prepared to learn something new.

The menu that you see on the screen when you boot up comes from the /boot/grub/grub.cfg file.

The /boot/grub/grub.cfg file is generated everytime “update-grub” is run. This is run everytime you get a kernal update and many times when you get a grub update. It does not make sense to edit this file.

Grub.cfg is generated by scripts in /etc/grub.d.

00_header gets the ball rolling and gets your timeout and hidden menu information for the menu.
05_debian-theme sets up how your menu looks on the screen.
10_linux is the one that gives you the menu entry for the OS that you are on.
20_memtest86+ is what sets the memtest on your menu.
30_os-prober is what is responcible for finding the rest of your OS'.
40_custom is designed so that you can make custom entries.

Grub2 gets its time out information and sets up a hidden menu for you in /etc/default/grub.
This is what it looks like without the hidden menu;
Code:
GRUB_DEFAULT=5
GRUB_TIMEOUT=100
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"
GRUB_CMDLINE_LINUX="
If you need to edit a menu entry that does not work do not mess with grub.cfg. It is silly to do so. It will be over written.

Go to /etc/grub.d and add to the 40_custom file. For instance;
30_os-prober does not generate a functional menu entry for my Mandriva installs. So I have a custom entry that works every time and comes right up on the menu every time. It is not over written because it is regenerated every time that “update-grub” is run.
Code:
    menuentry "linux-nonfb (on /dev/sda12)" {
    insmod ext2
    set root=(hd0,12)
    search --no-floppy --fs-uuid --set c23ad2ca-67a5-4a42-8fcc-3baa6d8e454e
    linux /boot/vmlinuz BOOT_IMAGE=linux-nonfb root=UUID=c23ad2ca-67a5-4a42-8fcc-3baa6d8e454e resume=UUID=59fe476e-6d4f-e390-ced9-f29328538dfc
    initrd (hd0,11)/boot/initrd.img
}
As you can see the partition is defined as being in two different places in this entry. It will not boot. The entry below will boot very well indeed.
Code:
menuentry "Mandriva-Gnome" {
        linux (hd0,12)/boot/vmlinuz
        initrd (hd0,12)/boot/initrd.img
}
I use a slightly different entry for any Debian based installs;
Code:
menuentry "Kinky-Grub2-A2 on sda10 2.6.31-11-generic" {
        set root=(hd0,10)
        linux /vmlinuz root=/dev/sda10 so quiet splash
        initrd /initrd.img
}
This entry works even if you change the OS on the partition. That was written for Ubuntu 9.10, I know what Ubuntu calls it. This is Linux, it is my box I can call it Kinky Kitty if I want. The Grub2-A2 in the title is from the Alpha2 or 9.10 testing when Grub2 was thrown at us with no documentation to speak of. That was FUN. I used that install for trying to figure out how to use Grub2 at a time, in Ubuntu, that it did not work well at all.

If you copy/paste that entry, editing only the partition definitions in the "set" and "linux" lines, it will boot ANY Debian based OS on the defined partition.

Your custom entries must be in the proper form. The first thing to do is start your favorite text editor (I use gedit). Go to preferences and set it so that there is NO test wrapping.

Then, in your 40_custom file put in an entry such as;
Code:
echo "Adding Kinky-Grub2-A2 on sda10 (2.6.31-11-generic)" >&2 
cat << EOF
menuentry "Kinky-Grub2-A2 on sda10 2.6.31-11-generic" {
        set root=(hd0,10)
        linux /vmlinuz root=/dev/sda10 so quiet splash
        initrd /initrd.img
}
EOF
That is the entire entry for that OS. It is the one that I use for experimenting on grub2. The part that does the work is between the { }s. Make sure that they are where they belong.

If you save this file as 06_custom it will appear at the top of menu you see on the screen. If you save it as 40_custom it will appear at the bottom of menu you see on the screen.

Now, what is the advantage of this rigamarole compared to grub-leagacy.

Well, if you have three OS' on your drive and you set up a custom menu you do not need any other menu entries at all. So you change the permissions on 10_linux, 20_memtest86+, 30_custom so that they are not executable. They will not run when “update-grub” is run and so the onoy thing on your menu is your custom entries. There is nothing that can mess with these entries except you.

I have ignored, for the most part MS installs. Do not and will not have one on any box in this house. That said, if you only want a custom menu just copy the MS entry from your /boot/grub/grub.cfg file to the /etc.grub.d/06_custom file and, of coarse, run "update-grub" to make it stick.

Do not change your os-prober executable permission until you have tried the custom menu entry to make sure it works.

You must remember to run;
Code:
sudo update-grub
Everytime you do anything that is to change your menu. This will overwrite your /boot/grub/grub.cfg file and thus the menu that shows up on your screen.

And finally, when posting a question on ANY bootloader, run this script and post the ENTIRE results

http://bootinfoscript.sourceforge.net/


by Larry Webb on Mon, 2011-02-21 21:52
You should submit the article to the LQ 'Tutorials'.

by Palladini on Mon, 2022-07-18 22:08
I have installed Manjaro, because I like how that Grub works on this, my Desktop Computer. This grub, unlike the ones that comes most other distros, You can do a restart from any Operating system and it will return to that Operating System. The Only time you need to change it is if you want to go to another Operating System


  



All times are GMT -5. The time now is 05:13 AM.

Main Menu
Advertisement
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration