Chapter 3. GRUB
OBJECTIVES
- Explain what the role of GRUB is
- Understand the differences between the GRUB1 and GRUB2 versions
- Be familiar with the interactive selections you can make at boot
- Know how to install GRUB
- Explain how the configuration files that GRUB needs are used and modified
WHAT IS GRUB
GRand Unified Bootloader, this application is the one that loads the operating system that is about to run within the machine.
INSTALLING GRUB
The word installing can have several different meanings with respect to GRUB:
- Installing the grub program and associated utilities in their proper locations. In GRUB 1 there is actually a program just called grub, but in GRUB 2 there are a bunch of utilities with names like grub2-* or grub-*; how they are packaged is rather distribution-dependent.
- Installing the files GRUB needs to operate at boot time, under either /boot/grub or /boot/grub2. This is separate than the files the Linux kernel needs (vmlinuz-*, initramfs-*) which will need to be in the /boot directory as well.
- Installing GRUB as the boot loader in the system; usually this is done at the front of the entire hard disk, but can also be done in a partition and accessed via chainloading from one GRUB to another.
$ sudo grub2-install /dev/sda
GRUB 1 installation procedure
For Version 1 the relevant utility is grub-install. It can also be done by just typing grub at the command line and then entering into an interactive program. For example:
$ sudo grub > root (hd0,0) > setup (hd0) > exit $
which would say install grub on the first drive and the boot files are on the first partition.
In both GRUB versions, the first hard drive is denoted as hd0, the second as hd1, etc. However, in version 1, partitions start counting from 0 and in version 2 from 1:
- sda1 is (hd0,1) in GRUB 2 but (hd0,0) in GRUB 1.
Customizing the GRUB Configuration File
- /etc/default/grub
$ cat /etc/default/grub GRUB_TIMEOUT=5 GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)" GRUB_DEFAULT=saved GRUB_DISABLE_SUBMENU=true GRUB_TERMINAL_OUTPUT="console" GRUB_CMDLINE_LINUX="vconsole.keymap=us crashkernel=auto vconsole.font=latarcyrheb-sun16 rhgb quiet" GRUB_DISABLE_RECOVERY="true"
- /etc/grub.d
$ ls -l /etc/grub.d -rwxr-xr-x 1 root root 9424 Sep 8 17:35 00_header -rwxr-xr-x 1 root root 6058 Sep 8 17:35 05_debian_theme -rwxr-xr-x 1 root root 11608 Sep 8 17:35 10_linux -rwxr-xr-x 1 root root 10412 Sep 8 17:35 20_linux_xen -rwxr-xr-x 1 root root 1992 Sep 8 17:35 20_linux_xen -rwxr-xr-x 1 root root 11692 Sep 8 17:35 30_os-prober -rwxr-xr-x 1 root root 1416 Sep 8 17:35 30_uefi-firmware -rwxr-xr-x 1 root root 214 Sep 8 17:35 40_custom -rwxr-xr-x 1 root root 216 Sep 8 17:35 41_custom -rw-r--r-- 1 root root 483 Sep 8 17:35 README
LABORATORY
1. Reboot your machine and go into the GRUB interactive shell by hitting e (or whatever other key is required as listed on your screen.)
2. Make your system boot into non-graphical mode. How you do this depends on the system.
- On traditional systems that respect runlevels (which we will talk about in the next section) you can append a 3 to the kernel command line in the specific entry you pick from the GRUB menu of choices.
- On some other systems (including Ubuntu) you need to append text instead.
3. Hit the proper key to make system continue booting.
Ctrl-x
4. After the system is fully operational in non-graphical mode, bring it up to graphical mode. Depending on your system, one of the following commands should do it:
$ sudo telinit 5