The boot process, GRUB, targets
This lesson is open to everyone. The other lessons open with a package: sign in or sign up, then choose a package.
Key points
- The order is the same: UEFI → GRUB2 → kernel + initramfs (dracut) → systemd → target.
- RHEL's tool for kernel parameters is grubby:
grubby --update-kernel=ALL --args="...",grubby --info=DEFAULT,grubby --set-default. - When changing
/etc/default/grub:grub2-mkconfig -o /boot/grub2/grub.cfg(on RHEL 9 this path is used for UEFI too). - For one boot:
ein the GRUB menu,systemd.unit=rescue.targetoremergency.targetat the end of thelinuxline,Ctrl+X. - Rebuilding the initramfs:
dracut -f; boot time:systemd-analyze blame.
RHEL tools
| Job | Ubuntu | RHEL |
|---|---|---|
| Regenerate the GRUB configuration | update-grub | grub2-mkconfig -o /boot/grub2/grub.cfg |
| Change a kernel parameter | /etc/default/grub + update-grub | grubby (recommended) |
| initramfs | update-initramfs -u | dracut -f |
| Default kernel | GRUB_DEFAULT | grubby --set-default |
RHEL 9 uses BLS (the Boot Loader Specification): each kernel's menu entry is in a /boot/loader/entries/*.conf file, and grubby edits these files.
Kernels and the default entry
[ali@srv-web01 ~]$ sudo grubby --info=ALL | grep -E "^(index|kernel|title)" index=0 kernel="/boot/vmlinuz-5.14.0-427.13.1.el9_4.x86_64" title="Red Hat Enterprise Linux (5.14.0-427.13.1.el9_4.x86_64) 9.4 (Plow)" index=1 kernel="/boot/vmlinuz-5.14.0-362.24.1.el9_3.x86_64" title="Red Hat Enterprise Linux (5.14.0-362.24.1.el9_3.x86_64) 9.3 (Plow)" index=2 kernel="/boot/vmlinuz-0-rescue-4b1c0e2a9d7f4e3c8a6b5d2e1f0a9c8b" title="Red Hat Enterprise Linux (0-rescue-4b1c0e2a9d7f4e3c8a6b5d2e1f0a9c8b) 9.4 (Plow)" [ali@srv-web01 ~]$ sudo grubby --default-kernel /boot/vmlinuz-5.14.0-427.13.1.el9_4.x86_64
RHEL keeps the last 3 kernels with dnf (installonly_limit=3 in /etc/dnf/dnf.conf), plus a rescue entry — a generic kernel that boots on any hardware.
If a new kernel causes problems, make the old one the default:
[ali@srv-web01 ~]$ sudo grubby --set-default /boot/vmlinuz-5.14.0-362.24.1.el9_3.x86_64 The default is /boot/loader/entries/4b1c0e2a9d7f4e3c8a6b5d2e1f0a9c8b-5.14.0-362.24.1.el9_3.x86_64.conf with index 1 and kernel /boot/vmlinuz-5.14.0-362.24.1.el9_3.x86_64
Changing kernel parameters permanently
[ali@srv-web01 ~]$ cat /proc/cmdline BOOT_IMAGE=(hd0,gpt2)/vmlinuz-5.14.0-427.13.1.el9_4.x86_64 root=/dev/mapper/rhel-root ro crashkernel=1G-4G:192M,4G-64G:256M,64G-:512M resume=/dev/mapper/rhel-swap rd.lvm.lv=rhel/root rd.lvm.lv=rhel/swap [ali@srv-web01 ~]$ sudo grubby --update-kernel=ALL --args="audit=1 audit_backlog_limit=8192" [ali@srv-web01 ~]$ sudo grubby --info=DEFAULT | grep args args="ro crashkernel=1G-4G:192M,4G-64G:256M,64G-:512M resume=/dev/mapper/rhel-swap rd.lvm.lv=rhel/root rd.lvm.lv=rhel/swap audit=1 audit_backlog_limit=8192" [ali@srv-web01 ~]$ sudo grubby --update-kernel=ALL --remove-args="audit_backlog_limit=8192"
| Parameter | What it does |
|---|---|
rd.lvm.lv=rhel/root | The initramfs activates this LV (the root) |
crashkernel=... | Reserves memory for kdump — a dump is written when the kernel crashes |
audit=1 | Start auditing from boot (unit 11) |
systemd.unit=... | Which target to boot into |
rd.break | Stop in the initramfs (next lesson) |
If you change GRUB_CMDLINE_LINUX in /etc/default/grub, grub2-mkconfig -o /boot/grub2/grub.cfg is needed — but grubby is more direct and safer.
Targets and recovery modes
| Target | What comes up | When |
|---|---|---|
emergency.target | Root read-only, no services, no network | An fstab mistake, a file system problem |
rescue.target | Local file systems, basic services, no network | A service breaks the boot |
multi-user.target | The full server | Normal |
To enter once — in the GRUB menu:
- Select the kernel, press
e. - Add
systemd.unit=rescue.targetat the end of the line starting withlinux. Ctrl+X.
From a running system: systemctl isolate rescue.target (SSH will drop — from the console only).
In emergency mode the root is read-only:
[root@srv-web01 ~]# mount -o remount,rw / [root@srv-web01 ~]# vi /etc/fstab [root@srv-web01 ~]# systemctl daemon-reload && mount -a [root@srv-web01 ~]# systemctl default
systemctl default switches to the default target (multi-user) — no reboot needed.
dracut: the initramfs
[ali@srv-web01 ~]$ lsinitrd /boot/initramfs-$(uname -r).img | grep -c lvm 37 [ali@srv-web01 ~]$ sudo dracut -f
The initramfs is rebuilt after a new storage driver, encryption or a change of the root file system. lsinitrd shows what is inside.
Lab: a kernel parameter and recovery mode
On your own VM (the GRUB menu needs a console):
- Find the kernels and the default with
grubby --info=ALL. - Add the
audit=1parameter permanently to all kernels, reboot and see it in/proc/cmdline. - In the GRUB menu, press
e, addsystemd.unit=rescue.target, enter rescue mode, and leave withsystemctl default. - (In the simulator) look at the traces of the boot with
cat /proc/cmdline,systemctl get-defaultandls /boot.
[ali@srv-web01 ~]$ sudo grubby --update-kernel=ALL --args="audit=1" [ali@srv-web01 ~]$ sudo reboot [ali@srv-web01 ~]$ grep -o "audit=1" /proc/cmdline audit=1
Check: after a reboot /proc/cmdline contains audit=1.
Check yourself
5 questions · answers are shown instantly · 3 correct answers complete the lesson
1Which command is recommended on RHEL to add a permanent parameter to all kernels?
2What is run on RHEL after changing /etc/default/grub?
3Which command rebuilds the initramfs on RHEL?
4The server does not boot because of an fstab mistake. Which mode does it drop into, and what is the first step?
5How do you switch from recovery mode to normal mode without rebooting?
Comments
Sign in to comment.