Installing and configuring a boot manager

Installing and configuring GRUB: where its files live, why you never edit the generated configuration by hand, and how the BIOS and UEFI installs differ.

Lesson 2 of 6 in objective 102. Linux installation and package management, part of LPIC-1 Exam 101-500.

You edit the first file; the third is generated from it. In order: /etc/default/grub (default entry, timeout, kernel command line), then grub-mkconfig -o (grub2-mkconfig on Red Hat; update-grub on Debian), then /boot/grub/grub.cfg (never hand-edited: a kernel update rewrites it), then The boot menu. /etc/default/grub default entry, timeout, kernel command line grub-mkconfig -o grub2-mkconfig on Red Hat; update-grub on Debian /boot/grub/grub.cfg never hand-edited: a kernel update rewrites it The boot menu
You edit the first file; the third is generated from it.

GRUB 2, and the legacy it replaced

GRUB Legacy read a single hand-edited file, /boot/grub/menu.lst, and that was the whole configuration. GRUB 2 generates its configuration instead: /boot/grub/grub.cfg (or /boot/grub2/grub.cfg on Red Hat family systems) is written by grub-mkconfig — spelled grub2-mkconfig on Red Hat — from the settings in /etc/default/grub and the scripts in /etc/grub.d/. Editing grub.cfg by hand works exactly until the next kernel update regenerates it.

So the workflow is: change /etc/default/grub for things like the default entry, the timeout and the kernel command line, drop a script in /etc/grub.d/ for a custom entry, then regenerate. Debian family systems wrap the regeneration in update-grub; Red Hat family systems run grub2-mkconfig -o /boot/grub2/grub.cfg.

The generator is an administrative tool, so it lives with the others in /usr/sbin/usr/sbin/grub-mkconfig, with /sbin/grub-mkconfig as the same file on distributions that still keep the two directories apart. update-grub is a two-line shell script in the same place that calls it. That matters in one situation and it is the one the exam picks: a rescue shell where /usr/sbin is not on PATH, and the command has to be typed in full.

Four names to type, and the one generator every one of them reaches. Left column, The name you type; right column, What actually runs. /usr/sbin/grub-mkconfig, /sbin/grub-mkconfig and grub2-mkconfig all point at The generator (The two paths are one file, and the 2 is only the Red Hat spelling). update-grub points at A two-line shell script (The Debian family wrapper, in /usr/sbin beside the generator), which in turn reaches The same generator, which the script calls (A rescue shell may not have /usr/sbin on PATH, so type the full path). The name you type What actually runs /usr/sbin/grub-mkconfig /sbin/grub-mkconfig grub2-mkconfig The generator The two paths are one file, and the 2 is only the Red Hat spelling update-grub A two-line shell script The Debian family wrapper, in /usr/sbin beside the generator The same generator, which the script calls A rescue shell may not have /usr/sbin on PATH, so type the full path
Four names to type, and the one generator every one of them reaches.
grep GRUB_TIMEOUT /etc/default/grubGRUB_TIMEOUT=5edit that file, never grub.cfg/usr/sbin/grub-mkconfig -o /boot/grub/grub.cfgGenerating grub configuration file ...Found linux image: /boot/vmlinuz-6.1.0-18-amd64done
The whole workflow: edit the source file, regenerate, check.

Installing the loader itself

On a BIOS machine, grub-install writes the boot code into the MBR of a named disk — grub-install /dev/sda — and the rest of GRUB into /boot/grub. On a UEFI machine there is no MBR stage: the loader is a file on the EFI system partition, registered with the firmware's boot manager, and grub-install places it there. efibootmgr is the tool that lists and reorders those firmware entries.

Chainloading is GRUB handing control to another boot loader rather than loading a kernel itself, which is how a dual-boot menu offers Windows. On the exam it is the answer to "how does GRUB boot an operating system it knows nothing about".

The same grub-install command writes to a different place on each kind of firmware. BIOS machine — Where grub-install writes: The MBR of a named disk; An MBR stage: Yes; The firmware entry list: No such list. UEFI machine — Where grub-install writes: A file on the EFI partition; An MBR stage: No such stage; The firmware entry list: efibootmgr reorders it BIOS machine UEFI machine Where grub-install writes The MBR of a named disk A file on the EFI partition An MBR stage Yes No such stage The firmware entry list No such list efibootmgr reorders it
The same grub-install command writes to a different place on each kind of firmware.

Worth carrying in

/etc/default/grub
The settings you edit: default entry, timeout, GRUB_CMDLINE_LINUX.
/usr/sbin/grub-mkconfig -o
Generate grub.cfg. grub2-mkconfig on Red Hat family systems.
update-grub
Debian wrapper around the same regeneration.
grub-install /dev/sda
Write the boot loader to a disk (BIOS) or the EFI partition (UEFI).
/boot/grub/grub.cfg
Generated. Never hand-edited — a kernel update overwrites it.
efibootmgr
List and reorder the firmware boot entries on a UEFI machine.
menu.lst
GRUB Legacy's single configuration file. Present only on old systems.

What the exam does with this

Objective
102. Linux installation and package management
Share of the exam
18.33% (the whole objective)
Questions in this lesson
10
Signed for by a person
0

Partly checked. None of the 10 questions here has been read against the cited source by a person. 10 questions have been checked against their cited clause by an automated pass — which is not the same thing, and is not a signature.

Only questions a person has signed for are used in mock exams here. That is the whole difference between the two kinds of checking above.

How these questions are written — where each question comes from, what the verification ledger records, and what happens when one is found wrong.

Drill this lesson

A lesson is one sitting: the trainer draws a short run from these questions alone and spaces the ones you get wrong.

Practise Installing and configuring a boot manager

Questions in this lesson

Practise Installing and configuring a boot manager

The rest of objective 102