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.
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.
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
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".
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-mkconfigon 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
grub.cfgis generated and/etc/default/grubis edited. A question that asks where you change the timeout is testing exactly this.- Know the two spellings:
grub-mkconfig/update-grubon Debian,grub2-mkconfigon Red Hat. - Chainloading means handing off to another boot loader, not loading another kernel.
- 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
- Which file is the configuration file that GRUB 2 generates, and which administrators are told not to edit by hand on a typical Linux distribution? machine-checked
- You replaced the boot disk in a BIOS/MBR system and need to write the GRUB 2 boot loader into the master boot record of /dev/sda, installing the required GRUB modules under /boot. Which command does that? machine-checked
- On a GRUB 2 system whose configuration file is /boot/grub/grub.cfg, type the grub-mkconfig command — including the option and its argument — that regenerates that file. machine-checked
- A GRUB menu entry ends with the directives 'set root=(hd0,3)' followed by 'chainloader +1'. What is GRUB doing? machine-checked
- You want every future boot of a GRUB 2 system to pass an extra kernel parameter, and you want the change to survive the next kernel update. Which file do you edit before regenerating the configuration? machine-checked
- You are asked to adjust the boot menu on an old system that still runs GRUB Legacy. Which file holds its menu entries? machine-checked
- On a BIOS system you run grub-install /dev/sda. Besides writing boot code to the disk, which directory does the command populate with GRUB's runtime modules and its generated core image? machine-checked
- You need to add a hand-written menu entry that chainloads another operating system, and it must still be present after the next kernel update regenerates the GRUB 2 configuration. Where should the entry be written? machine-checked
- On a UEFI machine you run grub-install without naming a disk device and the command succeeds. What has it done? machine-checked
- Which TWO statements about GRUB 2 are correct? machine-checked
Practise Installing and configuring a boot manager
The rest of objective 102
- Planning a disk layout
- Installing and configuring a boot manager — you are here
- Shared libraries and the dynamic linker
- Debian package management
- RPM and DNF package management, and virtual guests
- Running Linux as a virtualization guest