Boot process, targets & root recovery
Explain the boot sequence, switch targets and reset a lost root password.
By Invicly Tech, , in Linux Administration (RHCSA-style). About 10 minutes to read.
In short
Booting goes from firmware to the GRUB2 boot loader, to the kernel and initramfs, and then to systemd, which brings the system up to the default target. Targets such as multi-user and graphical replace the old runlevels. Knowing how to interrupt the boot lets you reach rescue mode or reset a lost root password, a classic RHCSA task.
Explained simply
When you press the power button, several programs run one after another, each handing over to the next. Firmware (BIOS or UEFI) checks the hardware and starts the boot loader. The boot loader, GRUB2, loads the Linux kernel. The kernel starts systemd, and systemd starts everything else.
systemd brings the machine to a goal called a target. A server normally boots to multi-user.target: networking, services and text logins. A desktop boots to graphical.target, which adds the graphical login. Targets replaced the numbered runlevels of older systems.
Sometimes you need the machine in a special state: rescue.target for repairs with minimal services, or emergency.target when even the normal file systems are broken. You can also stop the boot very early to reset a forgotten root password.
These skills feel rare until the day a server will not boot. Practise them on a lab VM with a snapshot, so that on a real outage you already know every step.
Press Play on a diagram to walk through it one step at a time.
- 1Firmware
BIOS or UEFI finds the boot device.
- 2GRUB2
Shows the menu, loads kernel and initramfs; press e to edit.
- 3Kernel and initramfs
Load drivers, find and mount the root file system.
- 4systemd (PID 1)
Starts units in parallel.
- 5default.target
Usually multi-user.target on servers.
- 6Login
getty on consoles and sshd for remote access.
- 1Interrupt GRUB
Press e on the kernel entry
- 2Add rd.break
End of the linux line, then Ctrl-X
- 3Make /sysroot writable
mount -o remount,rw /sysroot
- 4chroot and passwd
chroot /sysroot, then passwd root
- 5Request a relabel
touch /.autorelabel
- 6Exit twice
Boot continues and relabels
In depth
From firmware to the kernel
On older BIOS machines the firmware runs boot code from the first sector of the disk. On UEFI machines it reads a small FAT partition called the EFI system partition, mounted at /boot/efi, and starts a boot program from it. With Secure Boot this is a signed shim that then starts GRUB2.
GRUB2 loads two files from /boot: the kernel (vmlinuz) and the initramfs, a small compressed file system with the drivers needed to find the real root disk, such as for LVM, RAID or encryption. The kernel unpacks the initramfs, mounts the real root file system and starts /sbin/init, which is systemd.
The kernel command line, the arguments GRUB passes, controls a lot of this; cat /proc/cmdline shows the current one. If the initramfs lacks a driver, rebuild it with dracut -f on RHEL or update-initramfs -u on Ubuntu.
- Kernel entries: /boot/loader/entries
- Change arguments: grubby
- Rebuild config: grub2-mkconfig -o /boot/grub2/grub.cfg
- Rebuild initramfs: dracut -f
- Settings: /etc/default/grub
- Change arguments: edit GRUB_CMDLINE_LINUX
- Rebuild config: update-grub
- Rebuild initramfs: update-initramfs -u
Targets, isolate and one-off boots
default.target is a symlink to the target the system boots into. systemctl get-default reads it and set-default multi-user.target changes it. To switch right now, systemctl isolate multi-user.target stops everything the new target does not need, so isolating from graphical to multi-user closes the desktop.
Old runlevel names still work as aliases: runlevel3.target is multi-user.target and runlevel5.target is graphical.target.
To pick a different target for one boot only, edit the kernel line in GRUB (press e), add systemd.unit=rescue.target or systemd.unit=emergency.target, and press Ctrl-X. rescue.target mounts all local file systems from /etc/fstab and starts a root shell with very few services. emergency.target mounts only the root file system, read-only, which is what you need when a bad fstab line stops the boot. Both ask for the root password.
- Local file systems mounted
- Root shell, few services
- Needs the root password
- For service or config problems
- Only / mounted, read-only
- Almost nothing started
- Needs the root password
- For broken fstab or disks
- Stops inside the initramfs
- Real root at /sysroot, read-only
- No root password needed
- For a lost root password
Why the rd.break root reset works
rd.break tells the initramfs to stop and open a shell just before it hands over to the real system. At that moment the real root file system is mounted read-only at /sysroot and no password check exists yet, so anyone at the console can reach it. This is why physical and console access must be protected, for example with a GRUB password.
The steps follow from that state. mount -o remount,rw /sysroot makes it writable. chroot /sysroot makes it the root so passwd edits the right /etc/shadow. Because SELinux is not loaded yet, the new shadow file gets no proper label, so touch /.autorelabel asks for a full relabel on the next boot. That relabel can take several minutes and the machine reboots once more by itself; do not interrupt it.
On Ubuntu, the GRUB recovery mode entry offers a root shell instead; remount / read-write there before running passwd.
Changing kernel arguments for good
Edits made with e in the GRUB menu last for one boot only. On RHEL-family systems, grubby changes the boot entries permanently. grubby --info=ALL lists every kernel and its arguments, grubby --default-kernel shows which one boots, and grubby --update-kernel=ALL --args="console=ttyS0" adds an argument to every installed kernel. --remove-args removes one, and grubby --set-default picks another kernel.
On Ubuntu, edit GRUB_CMDLINE_LINUX in /etc/default/grub and run sudo update-grub. In both cases, reboot and check /proc/cmdline to confirm.
After the change, systemd-analyze shows how long firmware, loader, kernel and user space took, and systemd-analyze critical-chain shows the chain of units that delayed reaching the default target.
- grubby --update-kernel=ALL --remove-args="rhgb quiet" shows boot messages
- GRUB_TIMEOUT in /etc/default/grub sets how long the menu waits
- cat /proc/cmdline shows the arguments of the running kernel
Learn it in 5 short steps
About 40m each. Track them with a timer in your plan.
- 1Trace firmware, GRUB, kernel, systemd~40m
- 2Set the default target~40m
- 3Boot into rescue or emergency target~40m
- 4Reset the root password via rd.break~40m
- 5Change kernel arguments with grubby~40m
Key points
- systemctl get-default and set-default show and change the boot target.
- rescue.target gives single-user mode with most file systems mounted; emergency.target mounts almost nothing.
- To reset root: add rd.break to the kernel line, remount /sysroot read-write, chroot, passwd, then touch /.autorelabel.
- grubby --update-kernel=ALL --args changes kernel arguments persistently.
Key terms
Tap a card to flip it. 0/5 known
Examples
systemctl get-default
sudo systemctl set-default multi-user.target
# Root password reset: in GRUB press e, append rd.break to the linux line, Ctrl-X
mount -o remount,rw /sysroot
chroot /sysroot
passwd root
touch /.autorelabel
exit; exitChange the default target and reset root from the initramfs shell.
Recover from a typo in /etc/fstab
After adding a new disk to /etc/fstab, the server stops at boot and drops into emergency mode, or hangs waiting for a device. Step 1: in GRUB, add systemd.unit=emergency.target if it does not go there on its own, and log in as root. Step 2: remount the root file system read-write. Step 3: fix or comment out the bad line. Step 4: test the whole file with mount -a and findmnt --verify before rebooting.
# at the emergency shell, logged in as root
mount -o remount,rw /
vi /etc/fstab # fix the UUID or add nofail
systemctl daemon-reload
findmnt --verify
mount -a && echo fstab OK
systemctl default # continue to the default targetBoot to text mode and show boot messages
A VM was installed with a desktop, but it should run as a server, and you want to see boot messages instead of a splash screen. Step 1: check the current default target. Step 2: set multi-user.target as the default and switch to it now. Step 3: remove rhgb and quiet from every kernel's arguments with grubby. Step 4: reboot and confirm both changes.
systemctl get-default # graphical.target
sudo systemctl set-default multi-user.target
sudo systemctl isolate multi-user.target
sudo grubby --update-kernel=ALL --remove-args="rhgb quiet"
sudo grubby --info=DEFAULT | grep args
sudo reboot
# after the reboot:
cat /proc/cmdline; systemctl get-defaultQuick reference
- systemctl get-default and systemctl set-default multi-user.target
- systemctl isolate rescue.target switches state right now
- Add systemd.unit=rescue.target to the kernel line for a one-off rescue boot
- emergency.target mounts only / read-only; remount with mount -o remount,rw /
- rd.break: remount,rw /sysroot, chroot /sysroot, passwd, touch /.autorelabel
- grubby --update-kernel=ALL --args="ARG" changes kernel arguments for good
- cat /proc/cmdline shows the arguments the running kernel booted with
- systemd-analyze critical-chain shows what slowed the boot
Common mistakes
- Skipping touch /.autorelabel, so SELinux blocks logins after the reset.
- Forgetting to remount /sysroot read-write, so passwd cannot save the change.
Quick quiz
Pick an answer to see if you're right and why.
Practice exercises
Try each one yourself first. Use the hint if you get stuck, then compare with the solution.
- Exercise 1easy
Show the current default target, the list of available target units, and the kernel arguments of the running kernel.
- Exercise 2medium
On a lab VM with a snapshot, boot once into rescue.target from the GRUB menu, check which file systems are mounted, and continue to the normal target without rebooting.
- Exercise 3hard
On a lab VM (take a snapshot first), reset the root password using rd.break, then confirm after boot that the SELinux label on /etc/shadow is correct.
Check yourself
Answer in your head, reveal, then be honest with yourself.
Feel confident about this topic?
Frequently asked questions
- What replaced runlevels?
- systemd targets. multi-user.target is roughly runlevel 3 and graphical.target is runlevel 5, and the runlevelN.target names still exist as aliases.
- Is it a security hole that rd.break needs no password?
- It requires console access, which usually means full control anyway. Protect it with a GRUB password, disk encryption and physical or hypervisor console security.
- Why does the system reboot again after touch /.autorelabel?
- On that boot SELinux relabels every file, which can take several minutes, and then reboots once more so everything starts with correct labels.
- How do I see the GRUB menu if it is hidden?
- Hold Shift during boot on BIOS systems or press Esc repeatedly on UEFI systems. You can also set a longer GRUB_TIMEOUT in /etc/default/grub.