Grand Unified Boot Loader – GRUB 2 on Linux [Basic Guide]

The Grand Unified Boot Loader – Grub 2 has been the standard boot system for Ubuntu since version 9.10 and other distributions with newer versions, especially Kernel 2.6 and 3.x. Meet the powerful GRUB 2.

Grub 2 has been rewritten
completely with the purpose of allowing great flexibility and gain of
performance. Among the various improvements, the main ones are:

  • Script support with conditional expressions and functions;
  • Loading modules dynamically;
  • Rescue Mode; Personalized Menus;
  • Theme support
  • ;

  • Graphical menu support with “splash” screen;
  • Loading ISO images from Live CDs;
  • New structure of configuration file;
  • Non-x86 platform support (e.g. PowerPC);
  • Universal UUID (Universally Unique Identifier) support — identifier used in distributed systems.

Upgrade from Grub 1 to Grub 2

The upgrade from Grub 1 to Grub 2 is relatively
easy. You must first install the Grub 2 package with the command:

# sudo apt-get install grub-pc

Once installed, Grub 2 will present a
test menu, with the kernel images found and also allows the
menu be edited.

Once the menu is defined, Grub2 can be
permanently installed with the command:

# sudo upgrade-from-grub-legacy /boot/grub/grub.cfg

Main Changes
from Grub 1 to Grub 2

It is important that you know what the changes are
important from Grub 1 to Grub 2, namely:

  • The /boot/grub/menu.lst file has been replaced by /boot/grub/grub.cfg;
  • the main configuration file is /etc/default/grub;
  • The partition numbering system has changed;
  • Searches for other operating systems are performed automatically every time update-grub is executed and are placed in the menu;

Changes
In the configuration they have no effect until the update-grub command is executed.

Normally the /boot/grub/grub.cfg should not be
edited manually because it is rewritten in updates to the Grub 2 package, when
a kernel is added or removed, or the user triggers the update-grub command.
This command remakes the load menu from other configuration files
and rewrite /boot/grub/grub.cfg.

Create a default configuration in grub

The grub-mkconfig utility
can also be used to create a configuration for Grub:

# grub-mkconfig -o /boot/grub/grub.cfg

The main menu presentation configuration file
is located in /etc/default/grub.

/etc/default/grub file

This file contains the main information for
that Grub 2 can assemble the menu. It defines what the default menu option will be,
the waiting times for a user action, if the menu will be displayed in mode
graphic or text mode, among other options.

Example from /etc/default/grub:

GRUB_DEFAULT=0

#GRUB_SAVEDEFAULT = true

#GRUB_HIDDEN_TIMEOUT =0

GRUB_HIDDEN_TIMEOUT_QUIET=true

GRUB_TIMEOUT=10 GRUB_DISTRIBUTOR=’LSB_RELEASE

-i -s 2> /dev/null || echo Debian’ GRUB_CMDLINE_LINUX_DEFAULT=

” quiet splash” GRUB_CMDLINE_LINUX_DEFAULT=” quiet splash” GRUB_CMDLINE_LINUX_DEFAULT=

” quiet splash” GRUB_CMDLINE_LINUX_DEFAULT=” quiet splash”

GRUB_CMDLINE_LINUX_DEFAULT=” quiet splash” GRUB_

#GRUB_TERMINAL =console

#GRUB_GFXMODE =640×480

#GRUB_DISABLE_LINUX_RECOVERY =” true”

#GRUB_INIT_TUNE =” 480 440 1”

Grub Configuration File

See grub’s option comment:

GRUB_DEFAULT

Defines what will be the default Grub menu option. THE
GRUB_DEFAULT parameter can assume a numeric value, the name of the option in the menu
or the word “saved”.

If the value is numeric, indicate the menu position.
at /boot/grub/grub.cfg. You can also indicate the name of the menu “Ubuntu 2.6.31”.

If the value is “saved”, the default will be set
by the grub-set-default or grub-reboot command.

GRUB_SAVEDEFAULT

If this parameter is “true”, it tells Grub
that the default menu option will always be the last operating system selected
on the menu.

GRUB_HIDDEN_TIMEOUT

This parameter defines the time in seconds that
Grub will wait for a user action until the default menu option is
chosen automatically. No menu will be displayed unless
The user presses a key (usually the ESC).

If it equals zero, the default operating system
will load automatically without waiting for any intervention.

GRUB_HIDDEN_TIMEOUT_QUIET

When this option is “true”, no counter of
The weather will be presented. If it is “false”, a countdown counter will be
presented with the time set in GRUB_HIDDEN_TIMEOUT.

GRUB_TIMEOUT

This option will only be effective if the directive
GRUB_HIDDEN_TIMEOUT is commented, or active, when the user presses
some key during the GRUB_HIDDEN_TIMEOUT wait time.

GRUB_TIMEOUT defines the menu wait time
until the user makes their choice. Otherwise, it will execute the option
standard.

If the value is -1, Grub will wait for the user
indefinitely.

GRUB_DISTRIBUTOR

Determines the description of
system that will be used in the menu. If nothing is defined, Grub will use the default
of the system, which is generally defined by the command:

# lsb_release -i -s 2> /dev/null || echo Debian

SUSE LINUX

GRUB_CMDLINE_LINUX_DEFAULT

This directive passes
parameters for the Kernel during normal system load.

GRUB_CMDLINE_LINUX

This directive passes parameters to the Kernel
during system load, either for normal kernel load or in mode
“recovery”.

GRUB_TERMINAL

This option, if uncommented, disables the menu
in graphic mode.

GRUB_GFXMODE

Defines the resolution of the menu graphic terminal.

GRUB_DISABLE_LINUX_RECOVERY

Disable Kernel emergency mode if it is
equal to “true”.

GRUB_INIT_TUNE

Defines a “sound” that grub will make before
present the menu. The format is [note tone] [length].

Example: Immediate Third Party Contacts Theme
Grade:grub_init_tune=” 480 900 2 1000 2 800 2 400 2 600 3”

The /etc/grub.d directory

The scripts in this directory are read during the
The update-grub command call and its instructions are incorporated in the file
/boot/grub/grub.cfg.

The order of the items in the grub menu is determined
by the order of the scripts in this directory. The files are read according to
number that precedes your name, in ascending order.

00_header

Configures the initial parameters, such as the mode
graphic, standard menu option. These settings are generally imported from
/etc/default/grub.

05_debian_theme

Configure the background screen, text colors, etc.

10_Hurd

Used to locate Kernels
Hurd. It is not used in most distributions.

10_Linux

Identifies the Kernels on the root device and creates
the menu items. All existing kernel images in /boot will be
placed on the menu.

20_memtest86+

Search for the image in /boot/memtest86+.bin used for testing
memory. To remove this item, you must remove the image in the directory
/boot.

30_os-prober

This script searches for Linux and other systems
existing operations on the disk and create the menu items. The variables in this
The file determines how the names will appear in the menu.

40_custom

Allows you to add customized entries to the menu of
Grub.

The settings are
usually done in the /etc/default/grub file.
It is not common to directly edit scripts from the /etc/grub.d directory.
Any change made to the /boot/grub/grub.cfg is rewritten when the command
update-grub is executed.

Load Sequence
of the System

Grub2 runs before any operating system. It will generally load the operating system directly by setting it as the default or if there is only one operating system present.

If there is more than one operating system, it will display the menu to choose from.

The default wait time for the menu is 10s. If the user doesn’t do anything, it will start loading the default menu option.

The time count can be paralyzed if any key is pressed. The user can force the menu to be displayed by pressing the SHIFT key while loading grub2.

Partition Names
In Grub 2

The partition naming system in grub2 was
simplified compared to grub1. The device count remains
starting from scratch.

An sda device will be named hd0, and an sdb device will be named hd1. However, the partitions follow the “normal” numbering, so the partition sda5 will be named hd0.5 and sda3 will be hd0.3.

Learn much more about Linux in our online course. You can register here. If you already have an account, or want to create one, just log in or create your user here.

Did you like it?

Share

Uirá Endy Ribeiro

Uirá Endy Ribeiro is a Software Developer and Cloud Computing Architect with a 23-year career. He has master's degrees in computer science and fifteen IT certifications and is the author of 11 books recognized in the IT world market. He is also Director at Universidade Salgado de Oliveira and Director of the Linux Professional Institute - LPI Director's Board.

Leave a Reply 0

Your email address will not be published. Required fields are marked *


This site uses Akismet to reduce spam. Learn how your comment data is processed.

Need help?