Manage Learn to apply best practices and optimize your operations.

Configuring GRUB 2: Tweaking the boot procedure in Ubuntu Server 9.10

Configuring the new version of GRUB in Ubuntu Server 9.10 has changed. Learn how to install, apply changes to default settings and gain insight in the configuration files in /etc/GRUB.d/*.

The Grand Unified Boot Loader (GRUB) has been around for a couple of years now. In comparison to its predecessor LILO, GRUB offered huge advantages, of which the most important was the ability to address the file system directly, from the very first moment of booting on. In recent Linux distributions, such as Ubuntu Server 9.10, the next version of GRUB is used. In this article you'll learn how to work with GRUB 2.0.

GRUB 1 was already good, yet there was room for some enhancements. Improvements in GRUB 2 include a graphical interface with support for theming, modular loading, cross-platform compatibility and more. But, another change is the way you configure it. In this article you'll learn how to set it up in Ubuntu Server 9.10.

Installing GRUB 2
To install GRUB 2, you just have to install Ubuntu Server 9.10. After installation, it shows the new GRUB configuration files in the /boot/GRUB menu. This includes many .mod files containing modules needed in GRUB 2, the GRUB.cfg file and some other configuration files. The major change from older versions of GRUB, is that you no longer are going to edit a menu.lst file, but you have to generate the GRUB.cfg file. This file is not meant to be edited.

More on GRUB
GRUB definition

Using GRUB to fix Linux boot problems

Making a GRUB backup

To apply changes to GRUB2, you go through its main configuration file, which is /etc/default/GRUB. Apart from that, there are some individual scripts as well, which are located in /etc/GRUB.d/. After making changes to these input files, you can write them to the GRUB.cfg file, using either the update-GRUB2 or the update-GRUB command. The way to apply changes is:

  1. Make the required changes to either /etc/default/GRUB or individual files in /etc/GRUB.
  2. Run the update-GRUB command to write these changes to /boot/GRUB/GRUB.cfg.

Applying changes to /etc/default/GRUB
The first file to start making changes, is the /etc/default/GRUB. If you have worked with the older versions of GRUB, this file contains generic settings that you previously found on top of the /boot/GRUB/menu.lst file. Its generic settings that affect the way that GRUB shows its boot menu and the timeouts that are used for starting GRUB.

Default contents of /etc/default/GRUB

# If you change this file, run 'update-GRUB' afterwards to update
# /boot/GRUB/GRUB.cfg
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
GRUB_CMDLINE_LINUX="find_preseed=/preseed.cfg automatic-ubiquity noprompt"
# Uncomment to disable graphical terminal (GRUB-pc only)
# The resolution used on graphical terminal
# note that you can use only modes which your graphic card supports via VBE
# you can see them in real GRUB with the command `vbeinfo'
# Uncomment if you don't want GRUB to pass "root=UUID=xxx" parameter to Linux
# Uncomment to disable generation of recovery mode menu entrys

Let's look at some of the most important lines in the First, you can see the line GRUB_DEFAULT=0. This - like in the old menu.lst - refers to the menu entry that is started as the default. To see which menu entry this is, you should have a look at the /boot/GRUB/GRUB.cfg that still contains the menu options to be used.

Next, you can see the GRUB_HIDDEN_TIMEOUT options. These are used to make sure that by default no GRUB menu is displayed if only Linux is installed. However, if another operating system is shown, it will give a menu. If you want the system to be paused before loading the kernel, without displaying a menu, give this parameter a value greater than zero. For example, GRUB_HIDDEN_TIMEOUT=5 would pause your system for five seconds before it starts loading the kernel.

Next, see the GRUB_CMDLINE_LINUX lines. Here, you specify the kernel arguments that GRUB should apply. If for example you want your server to load with the data=writeback option (which enables the fastest possible journaling mode), you can add the option rootflags=data=writeback to this line. Any other kernel option can be used also. You might recognize some common kernel options from the example lines. So if you are planning on using any specific kernel options, put them in at this point.

Understanding /etc/GRUB.d/*
Next, there are the configuration files in the directory /etc/GRUB.d that are considered when you run GRUB-update to write the new GRUB.cfg configuration file. The first of these is the file 00_header, which actually refers to the settings you've made in /etc/default/GRUB, so if you remove this file, no settings from /etc/default/GRUB will be applied.

The 05_debian_theme file is used to determine what exactly GRUB should show when loading. By default, it shows the default GRUB theme on graphical desktops, you can replace this theme with your own picture by copying a picture in .png or .tga format to the directory /usr/share/images/desktop-base.

Next, there are some files that you probably don't want to change. The 10_linux files is responsible for loading the kernel, the 20_memtest86+ file loads the memory tester and the 30_os-prober tries to find other operating systems on your computer and if it does, shows them in the GRUB menu. That means that in GRUB 2, some intelligence is added and you don't have to create a menu entry for all the operating systems on your computer.

You might however want to edit the 40_custom file. In this file, you can put lines that are quite similar to the configuration files you might have used in GRUB 1, which load additional kernels and initrd's. Below you can see an example of the contents of this file:

menuentry "Some other Linux, linux 2.6.27-6-pae" { set root=(hd0,3) linux /boot/vmlinuz-2.6.27-6-pae root=/dev/sda4 initrd /boot/initrd.img-2.6.27-6-pae }

Just insert this entry in the existing 40_custom file and make sure not to touch the lines that you already find in this file and run the update-GRUB command to write the changes to GRUB.cfg. The next time you'll boot you will find all changes you have applied in your computers GRUB menu.

At first sight, GRUB 2 looks quite different from the older GRUB versions. Looking a little bit closer, you'll find out that there are not that many differences between GRUB 2 and 1. This article has explained how to handle to modify your GRUB 2 configuration, as it is likely that you will find this GRUB version on more and more Linux distributions in the near future.

ABOUT THE AUTHOR: Sander van Vugt is an author and independent technical trainer, specializing in Linux since 1994. Vugt is also a technical consultant for high-availability (HA) clustering and performance optimization, as well as an expert on SLED 10 administration.

Dig Deeper on Linux servers