Expert · Boot, recovery and containers · topic 40 of 57 · 30 min
GRUB2, kernel arguments and the default kernel
Explanation
What GRUB2 does for you
GRUB2 (GRand Unified Bootloader, version 2) lists the installed kernels, waits a few seconds (GRUB_TIMEOUT), and boots the default one. Each menu entry knows which kernel and initramfs to load and which kernel arguments to pass. Kernel arguments are settings for the kernel and for early boot, such as root=, ro, quiet, or systemd.unit=rescue.target.
RHEL 9 uses the Boot Loader Specification (BLS): each kernel has its own small entry file in /boot/loader/entries/. The main GRUB config (/boot/grub2/grub.cfg) reads those files. On UEFI systems, /boot/efi/EFI/redhat/grub.cfg is only a small stub that points to /boot/grub2/grub.cfg.
One-time changes from the menu
1. Reboot. When the menu appears, press an arrow key to stop the countdown.
2. Select the entry and press e.
3. Find the line that starts with "linux" and move to its end (Ctrl+E).
4. Add or remove arguments, for example: systemd.unit=rescue.target
5. Press Ctrl+X to boot. The change is NOT saved.Permanent changes with grubby
# grubby --default-kernel
/boot/vmlinuz-5.14.0-427.13.1.el9_4.x86_64
# grubby --info=ALL | grep -E '^(index|kernel|args)'
index=0
kernel="/boot/vmlinuz-5.14.0-427.13.1.el9_4.x86_64"
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 rhgb quiet"
index=1
kernel="/boot/vmlinuz-5.14.0-362.8.1.el9_3.x86_64"
...
# grubby --update-kernel=ALL --args="console=ttyS0,115200" # add to every kernel
# grubby --update-kernel=ALL --remove-args="rhgb quiet" # remove
# grubby --set-default /boot/vmlinuz-5.14.0-362.8.1.el9_3.x86_64 # boot the older kernel by defaultThe other way: /etc/default/grub
# grep -E 'TIMEOUT|CMDLINE' /etc/default/grub
GRUB_TIMEOUT=5
GRUB_CMDLINE_LINUX="crashkernel=1G-4G:192M,4G-64G:256M,64G-:512M resume=/dev/mapper/rhel-swap rd.lvm.lv=rhel/root rd.lvm.lv=rhel/swap rhgb quiet"
# vim /etc/default/grub # e.g. GRUB_TIMEOUT=10
# grub2-mkconfig -o /boot/grub2/grub.cfg
Generating grub configuration file ...
doneBooting an older kernel
After a kernel update, if the server misbehaves (a driver issue, a crash), reboot and pick the previous kernel from the menu. If it works, make it the default with grubby --set-default while you report the problem. dnf keeps 3 kernels by default for exactly this reason.
Protecting GRUB
Anyone at the console can press e and boot into a root shell (next lesson). On machines in shared spaces, set a GRUB password with grub2-setpassword; then editing entries needs the password. Physical security still matters: someone with the hardware can boot from a USB stick.
Common mistakes
- Editing arguments in the menu and expecting them to stay. Menu edits are for one boot only.
- Changing GRUB_CMDLINE_LINUX and forgetting grub2-mkconfig, so nothing changes.
- Removing the only working kernel. Always keep at least one known-good kernel.
Need help?
Stuck on a word or an idea? Search this course, or every course, and jump straight to the explanation or a worked question.
Try:
Watch the lesson
GRUB2, kernel arguments and the default kernel · 1/6
GRUB2 shows the boot menu and passes kernel arguments to the chosen kernel.
Prefer a video by a teacher? Find free videos on “rhel 9 grubby kernel arguments grub2-mkconfig default kernel” on YouTube ↗
In real life: A driver bug after a kernel update at a cloud provider
A cloud provider's team in Hyderabad updates its RHEL hosts monthly. One update caused network drops on an older network card model. Instead of rolling back packages in a hurry, the on-call engineer booted the previous kernel on the affected hosts and set it as default with grubby. The fleet stayed stable while the vendor fixed the driver, and the next update restored the newest kernel as default.
# grubby --set-default /boot/vmlinuz-5.14.0-362.8.1.el9_3.x86_64
The default is /boot/loader/entries/a1b2c3...-5.14.0-362.8.1.el9_3.x86_64.conf with index 1 and kernel /boot/vmlinuz-5.14.0-362.8.1.el9_3.x86_64
# rebootPractice (0/3 done)
Which command adds an argument to all kernels permanently on RHEL 9?
Model grubby. Write update_args(cmdline, add="", remove="") that returns a new kernel command line: first drop every argument listed in remove (matching either the whole "key=value" or just the key), then append each argument in add that is not already present (if an argument with the same key exists, replace its value in place). Arguments are separated by single spaces.
On your lab VM: list the installed kernels with grubby, remove "rhgb quiet" from all kernels permanently, reboot and watch the boot messages, then put "rhgb quiet" back.
Quick quiz
Read more (free)
Related help
Before this, learn
This topic builds on these. If something here feels new, open them first.
Related topics
- Recovering a lost root passwordBoot, recovery and containers · same module
- Containers with Podman: images, run, ports and logsBoot, recovery and containers · same module
- SELinux: what it is and its modesSELinux and SSH
- Installing software with dnf and rpmSoftware and networking
- What Linux and Red Hat Enterprise Linux areLinux and the shell
- firewalld: zones, services and portsSoftware and networking
Questions people ask about this
Open a question to see the answer and why. The first ones are this topic's own quiz, so try the quiz above before you peek.
You add an argument by pressing e at the GRUB menu. How long does it last?
Answer: This one boot only
Menu edits are not saved.
Where are RHEL 9 per-kernel boot entries stored?
Answer: /boot/loader/entries/
BLS entries live in /boot/loader/entries/.
After changing GRUB_TIMEOUT in /etc/default/grub, what must you run?
Answer: grub2-mkconfig -o /boot/grub2/grub.cfg
Regenerate grub.cfg.
Which command shows the kernel that boots by default?
Answer: grubby --default-kernel
uname -r shows the running kernel, which may differ.
Which file shows the kernel arguments of the current boot?Related
Which target is the usual default on a RHEL server?Related
Answer: multi-user.target
Servers normally boot to multi-user.target.
The server boots into emergency mode because of fstab. What must you do before editing the file?Related
Answer: mount -o remount,rw /
Root is read-only in emergency mode.
Which kernel argument replaces systemd with a bash shell for one boot?Related
Answer: init=/bin/bash
init= sets the first program the kernel runs.
Pass the quiz (60% or more) or mark this topic as done when you are ready.
Your progress is saved on this device only.
Next steps
- 3 more topics in “Boot, recovery and containers” before its exam: Recovering a lost root password, Containers with Podman: images, run, ports and logs, Persistent storage and containers as systemd services.
- Module 8 exam: Boot, recovery and containers · 13 questions · 25 min, without help. 5 topics of this module still to finish first.
- Then the next module, Ansible fundamentals. 57 topics left in the course before the final exam.