Startup and Boot FailuresLesson 3 of 4
The initramfs, rd.break and recovering root access
Inspect and rebuild the initramfs with dracut, stop boot with rd.break, and reset a lost root password with a correct SELinux relabel.
dracutdracut -flsinitrdlsinitrd -frd.breakrd.lvm.lvmount -o remount,rw /sysrootchroot /sysrootpasswdtouch /.autorelabelrestorecon/run/initramfs/rdsosreport.txt
After this lesson you can
- Explain what the initramfs contains and why a missing driver or LVM setting stops boot.
- List and rebuild an initramfs for a kernel, including adding a module.
- Reset the root password with rd.break, with the correct mount, chroot and relabel steps, and verify it.
The idea
The kernel cannot mount the real root file system until it can read the device that holds it. That device may sit on LVM, behind LUKS encryption, on RAID, on NVMe, or on a network. None of that code is built into the kernel in a distribution kernel, so the boot loader hands the kernel a small helper root file system, the initramfs (“initial RAM file system”), which contains just enough to assemble storage, find the real root and switch to it.
On RHEL the initramfs is generated by dracut:
kernel starts -> unpacks initramfs into RAM -> runs systemd (a small copy)
-> loads storage drivers -> activates LVM / unlocks LUKS / assembles RAID
-> mounts root at /sysroot -> switches root to /sysroot -> real systemd starts
A failure here shows as a dracut message, a timeout in dracut-initqueue, and an emergency shell with the prompt dracut:/#, or switch_root:/# at a break point.
What is inside, and why it matters
| Content | Why |
|---|---|
Kernel modules for disk controllers, file systems (xfs), device mapper | Without the module, the device or file system does not exist |
lvm, cryptsetup, mdadm tools and config | To activate the storage stack |
/etc/fstab (not included) | Only the root device is known, from the kernel command line (root=, rd.lvm.lv=) |
A copy of /etc/crypttab, /etc/lvm, /etc/mdadm.conf when needed | The initramfs has its own snapshot, taken when it was built |
The last row is the source of many surprises. The initramfs knows about storage as it was at build time. If you change root storage later (new VG name, new UUID, move to a different controller) and do not rebuild it, the next boot looks for the old layout and fails. That is why you run dracut -f after such changes.
Tools
lsinitrd # contents of the default kernel's image (also: lsinitrd IMAGE)
lsinitrd -f etc/fstab # print one file inside it
sudo dracut -f # rebuild for the running kernel, overwrite
sudo dracut -f --kver 6.12.0-55.el10.x86_64
Configuration lives in /etc/dracut.conf.d/*.conf; the /usr/lib/dracut/dracut.conf.d/ files belong to packages. Typical lines: add_drivers+=" nvme ", omit_dracutmodules+=" plymouth ", hostonly="yes" (include only what this machine needs; the default) or hostonly="no" (a generic image that boots anywhere, larger).
Breaking in on purpose: rd.break
rd.break stops the initramfs after it has found the real root and before it switches to it. You get a shell with root privileges and no login, because nothing from the real system is running. That is why anybody with console access and the ability to edit the GRUB line can set the root password, and why the GRUB menu and the machine room door are part of the security model.
At the prompt:
| Step | Command | Why |
|---|---|---|
| 1 | mount -o remount,rw /sysroot | The real root is mounted read-only here |
| 2 | chroot /sysroot | Make the installed system your / so tools and /etc/shadow are the real ones |
| 3 | passwd root | Change the password |
| 4 | touch /.autorelabel | Request a full SELinux relabel on the next boot |
| 5 | exit, exit | Leave the chroot, then continue the boot |
Step 4 is not optional. The shell you are in has no SELinux policy loaded, so the new /etc/shadow that passwd writes gets no proper label. With the default enforcing mode, the next login can fail with “Authentication failure” even though the password is right. The relabel fixes the label; it takes minutes on a big file system and the console shows the progress. You can instead run restorecon /etc/shadow inside the chroot, but .autorelabel is the dependable habit.
Try it
sudo lsinitrd | sed -n 1,6p
sudo lsinitrd | grep -E 'xfs.ko|bin/lvm'
Image: /boot/initramfs-6.12.0-55.el10.x86_64.img: 34M
========================================================================
Early CPIO image
========================================================================
drwxr-xr-x 3 root root 0 Nov 4 10:15 .
-rw-r--r-- 1 root root 2 Nov 4 10:15 early_cpio
usr/lib/modules/6.12.0-55.el10.x86_64/kernel/fs/xfs/xfs.ko.xz
usr/sbin/lvm
echo 'add_drivers+=" nvme "' | sudo tee /etc/dracut.conf.d/90-nvme.conf
sudo cp -p /boot/initramfs-$(uname -r).img{,.bak}
sudo dracut -f --kver $(uname -r)
sudo lsinitrd | grep nvme | head -3
If the new image fails to boot, choose another kernel in the GRUB menu, boot, and restore the copy (cp -p ...img.bak ...img). That is why you keep a .bak until a reboot succeeds.
Recovering from a missing root device
At a dracut:/# prompt after a timeout, the evidence is in the shell itself:
cat /run/initramfs/rdsosreport.txt | less # the log and a storage summary
lsblk; blkid # what the kernel found
cat /proc/cmdline # root=, rd.lvm.lv=, rd.luks.uuid=
lvm vgscan; lvm vgchange -ay # can LVM see the VG?
Typical causes and their repairs:
rdsosreport or screen says | Meaning | Repair |
|---|---|---|
Warning: /dev/mapper/rhel-root does not exist and no disks in lsblk | Storage driver or controller missing in the image | Boot the old kernel, add the driver, dracut -f |
Disk visible, lvm vgscan finds nothing | LVM filter or devices file excludes the disk | Boot rescue, fix /etc/lvm/devices/system.devices, dracut -f |
rd.lvm.lv=oldvg/root in /proc/cmdline but VG is now newvg | Renamed VG, stale command line | Edit the GRUB line for one boot, then grubby --update-kernel=ALL --args=... --remove-args=... and dracut -f |
UUID in root= not found | Root file system re-created with a new UUID | Same, with the new UUID from blkid |
| Encrypted root: no passphrase prompt | rd.luks.* argument or crypttab copy missing | Rebuild with the crypt module and correct /etc/crypttab |
Going further
Rescue media or rd.break? If you can edit GRUB, rd.break is the shortest path to a shell. If you cannot (GRUB password, no console access), the installation media’s rescue mode gives the same result with the installed system mounted under /mnt/sysroot. Beyond the exam: rd.shell, rd.debug and rd.retry control how the initramfs behaves when it fails, and systemd.debug_shell adds a root shell on tty9 during a normal boot, a debugging aid you must never leave enabled.
Practice
0 of 3 done
Do these on your own system. They get harder. Check each result, then tick it off.
- Warm-up
What is inside?
For the running kernel, list the initramfs contents and answer: is the
xfskernel module included, is the LVM toollvmincluded, and whichdracutmodules were used to build it? Do not unpack it onto the disk.Check your result
sudo lsinitrd | grep -E 'xfs.ko|bin/lvm'shows both (the exact path differs).sudo lsinitrd | sed -n '/dracut modules/,/^$/p'lists the module names (lvm,crypt,systemd, ...).
Hint
lsinitrdwith no argument shows the default kernel's image.lsinitrd /boot/initramfs-VERSION.imgselects one.-f pathprints one file from inside it.Solution
sudo lsinitrd | sed -n 1,12p sudo lsinitrd | grep -E 'xfs.ko|bin/lvm' sudo lsinitrd | sed -n '/dracut modules/,/^$/p' | head -20 - Practice
Rebuild it, safely
Make a backup copy of the current initramfs, rebuild it for the running kernel, and add the
nvmedriver explicitly through a drop-in file (so it survives future kernel updates). Prove the driver is inside the new image. Keep the backup until the machine has rebooted successfully.Check your result
ls -l /boot/initramfs-$(uname -r).img*shows the image and your.bakcopy.sudo lsinitrd | grep -c nvmeis greater than 0.cat /etc/dracut.conf.d/nvme.confcontainsadd_drivers+=" nvme ".- The system reboots normally.
Hint
Put settings in
/etc/dracut.conf.d/NAME.conf, never in/usr/lib/dracut/dracut.conf.d/(the package owns that). Note the space inside the quotes:add_drivers+=" nvme ". Rebuild withdracut -f --kver VERSION.Solution
sudo cp -p /boot/initramfs-$(uname -r).img /boot/initramfs-$(uname -r).img.bak echo 'add_drivers+=" nvme "' | sudo tee /etc/dracut.conf.d/90-nvme.conf sudo dracut -f --kver $(uname -r) sudo lsinitrd | grep nvme | head -3 sudo systemctl reboot - Challenge
Reset the root password
Setup (lab VM): set a root password you will not use (
echo 'root:Unknown-Pass-1' | sudo chpasswd), then reboot. Pretend you do not know it. Get a root shell without logging in, set the root password toLab-Recovered-2and make sure SELinux does not break the login afterwards. Verify by logging in as root on the console or withsu -from a user that knows it, and check that/etc/shadowhas the correct SELinux label.Check your result
su -withLab-Recovered-2works.ls -Z /etc/shadowshowsshadow_t.ls /.autorelabeldoes not exist after the boot (the relabel ran and removed it).getenforceprintsEnforcing.
Hint
Append
rd.breakto thelinuxline. At theswitch_root:/#prompt the real root is at/sysroot, mounted read-only: remount it read-write,chroot /sysroot, runpasswd, thentouch /.autorelabel, exit twice. The relabel makes the new/etc/shadowget its label back.Solution
GRUB: e -> add rd.break to the linux line -> Ctrl+xmount -o remount,rw /sysroot chroot /sysroot passwd root touch /.autorelabel exit exit# after the relabel boot su - ls -Z /etc/shadow getenforce