Tuesday, January 27, 2015

Customizing GRUB

GRUB Documentation

This section documents how I have customized and how I use GRUB version 2 to boot my Notebook PC from several operating systems. The information given here is specific to my own computer but may be useful for other machines too.

Picture: The GRUB Menu on my HP Laptop.
Picture: The GRUB Menu on my HP Laptop.

On my Notebook PC, I have three operating systems

  1. Ubuntu 12.10
    Booting from the partition /dev/sda5, an ext4 / (root) partition containing the booting image /boot/initrd.img-3.5.0-17-generic.
    The users are on /dev/sda7, another ext4 partition named /home.
  2. Kubuntu 12.10
    Booting from the partition /dev/sda6, an ext4 / (root) partition containing the booting image /boot/initrd.img-3.5.0-17-generic.
    The users are on /dev/sda7, another ext4 partition named /home.
  3. Windows 7
    Windows boots from the partition /dev/sda1. That is an NTFS type of partition.
To be able to boot anyone of these operating systems, I use GRUB version 2.
I have done some customizations with my GRUB.

Removing memtest from the menu

In the directory /etc/grub.d

If you do not want to have the memtest entries included, simply chmod -x the “20_memtest*” scripts. It will no longer be executable and won't be read into the grub.cfg file the next time you update GRUB.

Changing the GRUB Theme or boot background image of GRUB

To change the boot image when grub2 starts, add a (.png) image of size 1366 X 768 in the directory /boot/grub and regenerate GRUB.

Adding a Boot Tune

You have to modify the file /etc/default/grub. Toward the end, add the tune following the rules explained here:

# Uncomment to get a beep at grub start
#GRUB_INIT_TUNE="480 440 1"
# MLC: Close Encounter of the Third Kind
# MLC: Tempo [[Pitch Duration] ...]
#GRUB_INIT_TUNE="480 900 2 1000 2 800 2 400 2 600 3"
#GRUB_INIT_TUNE="200 900 2 1000 2 800 2 400 2 600 4"
# MLC: Tune tone lowered by 40%.
GRUB_INIT_TUNE="200 540 2 600 2 480 2 240 2 360 4"

CAVEAT
The screen will be be blank the whole time the tune will play.

Creating the grub.cfg File

Once you have made changes to the files, you have to become root and execute the command update-grub:

# update-grub

By the way, if you have installed new operating systems, they will be detected and added to the list of choices in the grub menu.

Making the Last Operating System the Default Choice

With GRUB, you choose an operating system and decide to boot your computer using that operating system. It is very nice if the next time you boot your machine the same operating system is selected by default.

The solution is to edit the file /etc/default/grub and within the file to change the value of the GRUB_DEFAULT variable to “saved”.  It is also very important to define the variable GRUB_SAVEDEFAULT and to set it to "true".
GRUB_DEFAULT=0 specifies the default entry. It counts from 0, like any geeky menu. Changeto anything you like. If you set the entryto GRUB_DEFAULT=saved, it will boot the lastselected option from the previous boot.
Finally, this is en excerpt from my /etc/default/grub file showing the two variables needed to make GRUB remember the last GRUB menu option selected:
Picture: GRUB Remembers the last OS.
Picture: GRUB Remembers the last OS.

Updating and Installing GRUB

After changes have been made to the file /etc/default/grub or if new theme image have been changed in the /boot/grub directory, the GRUB must be regenerated and re-installed.
Acquire the root privileges and execute these two commands:
Regenerate the grub.cfg file.
# update-grub 
Installing GRUB on the MBR (Master Boot Record) of the first SATA hard disk.
# grub-install /dev/sda

More information about GRUB and GRUB 2

Click here for the manual page of GRUB.

From Dedoimedo

GRUB 2 bootloader - Full tutorial

GRUB bootloader - Full tutorial

No comments:

Post a Comment