banner
Previous Page
PCLinuxOS Magazine
PCLinuxOS
Article List
Disclaimer
Next Page

How To Create Sub Menus In GRUB

by agmg (Antonis Komis)

I'm pretty sure you've all heard about GRUB. GRUB (complete name GNU GRUB - short for GNU GRand Unified Bootloader) is the default bootloader used by PCLinuxOS. It is the first software program that runs when your computer starts. It is responsible for loading and transferring control to the kernel software which, in turn, initializes the rest of the operating system. It allows you to boot, not only to your PCLinuxOS installation, but also to other operating systems on your hard disk, including multiple PCLinuxOS installations. You can also have multiple kernels installed on your system and boot to each one of them using GRUB.

This is probably what your GRUB will look like after installing and updating PCLinuxOS:



Pretty tidy, huh? Let's say you have two more PCLinuxOS (or any other Linux) installations, one more for Windows and three or four different kernels for your current install. How would GRUB look in that case?



Wow! Pretty long list! Wouldn't it be better if you had all these entries organized in sub menus with distinct names, to help you navigate between them?



Much better, huh? Let's see what's under the "Other Kernels" entry:



All the kernels for the current installation are gathered under this entry and you can select which one to boot. Selecting "Previous Menu", takes you back to the main list. Let's select another entry, "Testing":



This entry could very well be named "Other Operating Systems" and contain other Linux distributions or Windows installed on your hard disk. You can customize the entries to suit your needs.

Sounds interesting? Keep on reading ...

GRUB can be configured by editing the file menu.lst which is located under /boot/grub. The menu.lst file from the first screenshot (a typical installation of PCLinuxOS) would look like this:

timeout 10
color black/cyan yellow/cyan
gfxmenu (hd0,0)/boot/gfxmenu
default 0

title linux
kernel (hd0,0)/boot/vmlinuz BOOT_IMAGE=linux root=UUID=9cfa42bb-
d4b9-459e-a044-bd9dd8f6be7a quiet vmalloc=256M acpi=on
resume=UUID=f1d0f361-8058-4232-a34c-a111b26eece4 splash=silent vga=788 initrd (hd0,0)/boot/initrd.img title linux-nonfb kernel (hd0,0)/boot/vmlinuz BOOT_IMAGE=linux-nonfb
root=UUID=9cfa42bb-d4b9-459e-a044-bd9dd8f6be7a quiet vmalloc=256M
acpi=on resume=UUID=f1d0f361-8058-4232-a34c-a111b26eece4
initrd (hd0,0)/boot/initrd.img title failsafe kernel (hd0,0)/boot/vmlinuz BOOT_IMAGE=failsafe root=UUID=9cfa42bb-
4b9-459e-a044-bd9dd8f6be7a failsafe vmalloc=256M
initrd (hd0,0)/boot/initrd.img title memtest-4.20 kernel (hd0,0)/boot/memtest-4.20 BOOT_IMAGE=memtest-4.20

The first section specifies some options related to GRUB itself, such as the time it will display on the screen (timeout), the entry that will be the default to boot (0 is the first one) or its background.

The following sections are entries for booting PCLinuxOS with different options and the last one launches the memtest program for testing your computer's memory (RAM). If you had Windows installed on your disk and decided to keep it alongside PCLinuxOS, you should have one more entry allowing to boot to Windows, similar to this:

title Microsoft Windows
rootnoverify (hd1,0)
make active
chainloader +1

You may have a lot more entries like the above and new entries might be added later on if you decide to make new installations on your hard disk or try different kernels on your existing ones. It can become quite a long list, believe me.

GRUB has a nice feature, the configfile command. It is possible to create sub menus by using the configfile command, followed by the filename of the configuration file you want to load.

Example:

timeout 10
color black/cyan yellow/cyan
gfxmenu (hd0,0)/boot/gfxmenu
default 0

title other kernels
configfile /boot/grub/submenu.lst

This entry will load the configuration file called submenu.lst. This config file is in the same folder as menu.lst (/boot/grub/) and follows the same format as menu.lst. A new menu colour scheme can be specified, default boot entry can be set, etc. Adding an option to return to the previous menu is recommended, to avoid being "stuck" in the submenu.

Example:

timeout 10
color black/cyan yellow/cyan
gfxmenu (hd0,0)/boot/gfxmenu
default 0

title 2.6.38.8-pclos3.bfs
kernel (hd0,0)/boot/vmlinuz-2.6.38.8-pclos3.bfs BOOT_IMAGE=2.6.38.8-
pclos3.bfs root=UUID=9cfa42bb-d4b9-459e-a044-bd9dd8f6be7a quiet
vmalloc=256M acpi=on resume=UUID=f1d0f361-8058-4232-a34c-a111b26eece4
splash=silent vga=788
initrd (hd0,0)/boot/initrd-2.6.38.8-pclos3.bfs.img title Previous Menu configfile /boot/grub/menu.lst

Before proceeding with changes to the menu.lst you should make a backup, in case something goes wrong in the way.

Open your favourite terminal emulator and type:

su (your root password)
cp /boot/grub/menu.lst /boot/grub/menu.lst.bak

Next step is to create new .lst files under /boot/grub/ that correspond to the entries you would like to have on the main boot menu. Each entry you want to create must have its own configfile. The best way to do this, is to make additional copies of menu.lst and rename them according to your needs. This way you will have the formatting and all the entries of the main list in each one of the new .lst files. Then, you can easily remove the ones you don't want, by simply editing the .lst file with your favourite text editor (with root privileges, off course). Remember that the first section of the file must not be removed and you should also add an entry in every sub-menu file for returning to the main boot menu.

I created three new files in my case:

su (your root password)
cp /boot/grub/menu.lst /boot/grub/kernels.lst
cp /boot/grub/menu.lst /boot/grub/testing.lst
cp /boot/grub/menu.lst /boot/grub/options.lst

Let's have a look at my kernels.lst file after I have edited it to only contain the entries I want:


timeout 10
color black/cyan yellow/cyan
gfxmenu (hd0,0)/boot/gfxmenu
default 0

title 3.4.11-pclos1.bfs
kernel (hd0,0)/boot/vmlinuz-3.4.11-pclos1.bfs BOOT_IMAGE=3.4.11-pclos1.bfs
root=UUID=9cfa42bb-d4b9-459e-a044-bd9dd8f6be7a quiet
vmalloc=256M acpi=on resume=UUID=f1d0f361-8058-4232-a34c-a111b26eece4
splash=silent vga=788 initrd (hd0,0)/boot/initrd-3.4.11-pclos1.bfs.img title 3.2.18-pclos2.pae.bfs kernel (hd0,0)/boot/vmlinuz-3.2.18-pclos2.pae.bfs BOOT_IMAGE=3.2.18-pclos2.pae.bfs root=UUID=9cfa42bb-d4b9-459e-a044-bd9dd8f6be7a quiet vmalloc=256M acpi=on resume=UUID=f1d0f361-8058-4232-a34c-a111b26eece4 splash=silent vga=788 initrd (hd0,0)/boot/initrd-3.2.18-pclos2.pae.bfs.img title 2.6.38.8-pclos3.pae.bfs kernel (hd0,0)/boot/vmlinuz-2.6.38.8-pclos3.pae.bfs BOOT_IMAGE=2.6.38.8-pclos3.pae.bfs root=UUID=9cfa42bb-d4b9-459e-a044-bd9dd8f6be7a quiet vmalloc=256M acpi=on resume=UUID=f1d0f361-8058-4232-a34c-a111b26eece4 splash=silent vga=788 initrd (hd0,0)/boot/initrd-2.6.38.8-pclos3.pae.bfs.img title 2.6.38.8-pclos3.bfs kernel (hd0,0)/boot/vmlinuz-2.6.38.8-pclos3.bfs BOOT_IMAGE=2.6.38.8-pclos3.bfs root=UUID=9cfa42bb-d4b9-459e-a044-bd9dd8f6be7a quiet vmalloc=256M acpi=on resume=UUID=f1d0f361-8058-4232-a34c-a111b26eece4 splash=silent vga=788 initrd (hd0,0)/boot/initrd-2.6.38.8-pclos3.bfs.img title Previous Menu configfile /boot/grub/menu.lst

My file contains only the extra kernels of my installation. I have not removed the first section (options for GRUB) but I could change the settings i.e. the timeout. Also, I have added a section in the end of the file that will allow me to return to the main list.

A similar procedure has to be followed for every entry you would like to have on your main list. For each entry, you must create a separate .lst file and edit it accordingly.

In this article, I have covered only one of the many features of GRUB. Hope you will find it useful and it will help you tidy up your boot menu.

There are many more ways you can customize GRUB so it better suits your needs. For example, you could add an entry that reboots the computer, like this:


title Reboot
reboot

If you would like to further experiment and get to know GRUB, you should begin by reading the manual:

http://www.gnu.org/software/grub/manual/legacy/grub.html


Previous Page              Top              Next Page
Copyright (c) 2013, The PCLinuxOS Magazine. All Rights Reserved.