How to boot into rescue mode¶
A system doesn't boot normally: it stops at "You are in emergency mode", a service hangs the boot, a bad /etc/fstab line or a broken configuration file keeps it from reaching a login prompt, or you've lost the root password.
This guide gets you a root shell with as little of the system running as possible, so you can repair it and boot normally again.
Work down the options in order. Each one depends on less of the system than the one before; why that matters is explained in The Linux boot process.
| Option | Use it when |
|---|---|
| Switch a running system to rescue mode | You can still log in, but need the system quiet to work on it |
| Rescue target | Boot fails or hangs while starting services |
| Emergency target | Boot fails while mounting filesystems, or rescue mode fails too |
| Break into the initramfs | The installed system's init can't start, or you've lost the root password |
init=/bin/bash |
Last resort when nothing else gives you a shell |
What has been verified
The preparation steps, the commands in Repair the system that also work on a running system, and the final checks were run on Debian 13, Ubuntu 26.04, AlmaLinux 10, Rocky Linux 10, Arch and Gentoo with OpenRC.
The boot-time procedures (editing the kernel command line in the GRUB menu for the rescue and emergency targets, the initramfs breaks, init=/bin/bash and OpenRC's single-user mode) and the commands run inside those shells have not been verified by running them: the verification labs are driven over SSH and can't yet operate a console while the machine boots.
Before you begin¶
- You need console access: a physical keyboard and screen, a remote console (IPMI, iDRAC, iLO), or your hypervisor's or cloud provider's serial or VNC console. Rescue and emergency mode don't start the network, so you can't use SSH.
- The rescue and emergency shells ask for the root password. Many cloud images ship with the root account locked. On systemd, adding
SYSTEMD_SULOGIN_FORCE=1to the kernel command line makes these shells start without a password when root is locked; otherwise use the initramfs orinit=/bin/bash.
While the system still works, prepare it:
-
Check whether root has a usable password. In the second field,
Lmeans the account is locked,NPthat it has no password, andPthat it has a usable password:To set one, run
sudo passwd root.Warning
A root password is a credential that can log in on the console and, depending on your SSH configuration, over the network. Use a strong one and store it where your team keeps emergency credentials.
-
Check that the rescue and emergency modes are available, and what the system boots into normally:
With OpenRC, list the runlevels and check which one sysvinit starts by default (
3, which/etc/inittabmaps to OpenRC'sdefaultrunlevel), and that runlevelSrunsopenrc singleandsulogin:$ ls /etc/runlevels/ boot default nonetwork shutdown sysinit $ grep -E 'initdefault|^l[12]:|^su' /etc/inittab id:3:initdefault: l1:1:wait:/sbin/openrc single l2:2:wait:/sbin/openrc nonetwork su0:S:wait:/sbin/openrc single su1:S:wait:/sbin/suloginRunlevel
1only runsopenrc single; runlevelSalso startssulogin, which gives you the root shell. With a systemd profile, use the commands from the other tabs (systemd profile, not verified).On systemd, both targets ship in
/usr/lib/systemd/system/.rescue.targetpulls insysinit.targetandrescue.service, andemergency.targetpulls in onlyemergency.service; both services runsystemd-sulogin-shell, which asks for the root password.systemctl get-defaultprints the normal target, usuallymulti-user.targeton servers orgraphical.targeton desktops. -
Make sure the GRUB menu appears at boot. With a timeout of
0, GRUB boots straight away and you never get the chance to edit an entry.Settings in
/etc/default/grub.d/*.cfgoverride/etc/default/grub, and cloud images use them: Debian 13's cloud image setsGRUB_TIMEOUT=0in15_timeout.cfg, Ubuntu 26.04's sets it in50-cloudimg-settings.cfg.$ grep -sE '^GRUB_(TIMEOUT|TIMEOUT_STYLE|CMDLINE_LINUX|CMDLINE_LINUX_DEFAULT)=' /etc/default/grub /etc/default/grub.d/*.cfg /etc/default/grub:GRUB_TIMEOUT=5 /etc/default/grub:GRUB_CMDLINE_LINUX_DEFAULT="" /etc/default/grub:GRUB_CMDLINE_LINUX="console=tty0 console=ttyS0,115200 earlyprintk=ttyS0,115200 consoleblank=0" /etc/default/grub.d/15_timeout.cfg:GRUB_TIMEOUT=0The last value read wins, so this Debian 13 system boots without showing the menu. Add a file that's read last and regenerate
/boot/grub/grub.cfg:GRUB reads one Boot Loader Specification entry per kernel from
/boot/loader/entries/;grubbyshows and changes them:$ grep -E '^GRUB_(TIMEOUT|CMDLINE_LINUX|CMDLINE_LINUX_DEFAULT|ENABLE_BLSCFG)=' /etc/default/grub GRUB_TIMEOUT=0 GRUB_CMDLINE_LINUX="console=tty0 console=ttyS0,115200n8 no_timer_check biosdevname=0 net.ifnames=0" GRUB_ENABLE_BLSCFG=true $ sudo ls /boot/loader/entries/ $ sudo grubby --info=DEFAULTSet a timeout, make sure the menu isn't automatically hidden, and regenerate
/boot/grub2/grub.cfg:$ grep -E '^GRUB_(TIMEOUT|TIMEOUT_STYLE|CMDLINE_LINUX|CMDLINE_LINUX_DEFAULT)=' /etc/default/grub GRUB_TIMEOUT=1 GRUB_CMDLINE_LINUX_DEFAULT="rootflags=compress=zstd:1 console=tty0 console=ttyS0,115200" GRUB_CMDLINE_LINUX="net.ifnames=0" GRUB_TIMEOUT_STYLE=menuGive yourself enough time to press a key, and regenerate
/boot/grub/grub.cfg:sudo sed -i 's/^GRUB_TIMEOUT=.*/GRUB_TIMEOUT=5/' /etc/default/grub sudo grub-mkconfig -o /boot/grub/grub.cfgWith systemd-boot instead of GRUB, set
timeout 5inloader/loader.confon the EFI system partition; press e on an entry in its menu to edit its parameters for one boot.$ grep -E '^#?GRUB_(TIMEOUT|TIMEOUT_STYLE|CMDLINE_LINUX)=' /etc/default/grub #GRUB_TIMEOUT=5 #GRUB_TIMEOUT_STYLE=menu GRUB_CMDLINE_LINUX="console=ttyS0 console=tty0"Gentoo's
/etc/default/grubships with most settings commented out, and GRUB's built-in default is a 5-second menu. To make that explicit, so a later change elsewhere can't hide the menu, set it and regenerate/boot/grub/grub.cfg:If you can't change the timeout in advance, hold Shift (BIOS) or press Esc (UEFI) repeatedly as GRUB starts; whether that works depends on the firmware and on how quickly GRUB starts.
-
Make sure the log of a failed boot will still be there after you reboot to repair it:
The directory exists, so the journal of each boot is kept on disk.
Some images, such as the AlmaLinux 10 cloud image, have no
/var/log/journal/, so the journal is kept only in memory and lost at every reboot. Make it persistent, and move the current boot's log to disk:The directory exists, so the journal of each boot is kept on disk.
-
Note how the root filesystem is mounted when everything works, so you can compare later:
Switch a running system to rescue mode¶
If you can still log in on the console, switch to rescue mode without rebooting. All services except a minimal set are stopped, including networking and SSH, and a root shell starts on the console.
Warning
This ends every SSH session and stops all network services. Only do it from a console.
When you've finished, return with systemctl default (from the rescue shell) or reboot.
Warning
This ends every SSH session and stops all network services. Only do it from a console.
When you've finished, return with systemctl default (from the rescue shell) or reboot.
Warning
This ends every SSH session and stops all network services. Only do it from a console.
When you've finished, return with systemctl default (from the rescue shell) or reboot.
With OpenRC, where sysvinit is PID 1, switch to single-user mode, runlevel S.
This stops the services in the default runlevel and starts sulogin on the console.
Warning
This ends every SSH session and stops all network services. Only do it from a console.
Return with telinit 3 from the single-user shell, or reboot.
Edit the kernel command line for one boot¶
The following options are one-time changes to the kernel command line, made in the GRUB menu. They aren't saved: the next boot is normal again.
- Reboot and wait for the GRUB menu.
- Select the entry you normally boot, and press e. If GRUB asks for a user name and password, the menu is password-protected and you need those credentials.
- Find the line that starts with
linux(orlinuxefi). It ends with parameters such asro quietorrw console=ttyS0. - Move to the end of that line and add the parameter, separated by a space.
- Press Ctrl+X or F10 to boot with the change.
An edited linux line looks like this:
linux /vmlinuz-6.12.0-211.el10.x86_64 root=UUID=<ROOT-UUID> ro console=ttyS0,115200n8 systemd.unit=rescue.target
<ROOT-UUID> stands for whatever your entry already contains; change nothing but the end of the line.
Remove quiet and rhgb or splash while you're there, to see the boot messages.
Boot into the rescue target¶
On systemd, add:
systemd mounts the local filesystems, starts no services or network, and asks for the root password.
Add SYSTEMD_SULOGIN_FORCE=1 as well if the root account is locked.
Debian's GRUB menu has "(recovery mode)" entries under "Advanced options"; they add single, which systemd treats the same as systemd.unit=rescue.target.
Ubuntu's recovery entry is different: it adds recovery nomodeset dis_ucode_ldr and starts Ubuntu's recovery menu (friendly-recovery), from which the root option opens a root shell.
To reach rescue.target on Ubuntu, add systemd.unit=rescue.target yourself.
There's no recovery entry: GRUB_DISABLE_RECOVERY="true" is set.
An entry whose title contains 0-rescue, where present, boots a kernel with a generic initramfs for hardware changes; it starts the normal target, not rescue mode.
There's no recovery entry (GRUB_DISABLE_RECOVERY=true in the default configuration).
With OpenRC, add single instead.
sysvinit enters runlevel S, which runs openrc single and then sulogin; GRUB's "(recovery mode)" entry under "Advanced options" adds the same parameter.
Two other OpenRC options help when one service breaks the boot:
softlevel=<RUNLEVEL>boots into the named runlevel instead ofdefault.<RUNLEVEL>is the name of a directory in/etc/runlevels/: one you created without the problem service, or the stocknonetworkrunlevel, which contains onlylocal.- With
rc_interactive="YES"in/etc/rc.conf(set before the problem happens), pressing I early in the boot makes OpenRC ask before starting each service, so you can skip the broken one.
Boot into the emergency target¶
If rescue mode fails, usually because a filesystem in /etc/fstab can't be mounted, use the emergency target.
Only a root shell starts.
The root filesystem is mounted, often read-only, and nothing else from /etc/fstab is.
A system that drops to "You are in emergency mode" by itself is already in this state.
Add systemd.unit=emergency.target instead.
Add systemd.unit=emergency.target instead.
Add systemd.unit=emergency.target instead.
OpenRC has no separate emergency level.
Use init=/bin/bash.
Break into the initramfs¶
This stops the boot inside the initramfs, before the installed system's init runs.
With dracut's rd.break and initramfs-tools' break=, you don't need a password.
On Ubuntu 26.04, whose initramfs is built with dracut, add rd.break.
You get a switch_root:/# prompt, with the installed root filesystem mounted read-only at /sysroot.
Make it writable, make /proc, /sys and /dev available inside it (needed by tools such as grub-mkconfig and update-initramfs), and change into it:
mount -o remount,rw /sysroot
for d in proc sys dev; do mount --rbind /$d /sysroot/$d; done
chroot /sysroot
On Debian 13, whose initramfs is built with initramfs-tools, add break=bottom.
You get an (initramfs) prompt after the root filesystem has been mounted read-only at /root:
Make your fix (see Repair the system), then type exit twice: once to leave the chroot, once to let the boot continue.
Add rd.break.
You get a switch_root:/# prompt, with the installed root filesystem mounted read-only at /sysroot.
Make it writable, make /proc, /sys and /dev available inside it, and change into it:
mount -o remount,rw /sysroot
for d in proc sys dev; do mount --rbind /$d /sysroot/$d; done
chroot /sysroot
Make your fix (see Repair the system).
No SELinux policy is loaded at this point, so files you create or change get no SELinux label or the wrong one; a changed /etc/shadow, for example, then stops every login.
Whenever you've changed any file, schedule a relabel before leaving:
Then type exit twice: once to leave the chroot, once to let the boot continue.
The next boot relabels the filesystem, which takes a few minutes, and reboots once more.
rd.break is a dracut option and doesn't apply to mkinitcpio images.
The default mkinitcpio configuration runs systemd in the initramfs, so add:
mkinitcpio's systemd hook puts a locked root account into the initramfs, so the emergency shell would refuse to start even if your root account has a password; SYSTEMD_SULOGIN_FORCE=1 tells it to start anyway.
The root filesystem isn't mounted yet.
Mount it at /sysroot, read-write, and change into it:
mount -o rw <ROOT-DEVICE> /sysroot
for d in proc sys dev; do mount --rbind /$d /sysroot/$d; done
chroot /sysroot
<ROOT-DEVICE> is the full path of the root device, for example /dev/vda3 or /dev/mapper/vg-root, or a UUID=… value as in the root= kernel parameter.
On Btrfs, add the subvolume option the system normally uses, for example -o rw,subvol=@.
Make your fix, then exit and reboot with systemctl reboot --force.
With an older busybox-based image (base and udev hooks instead of systemd), add break=postmount instead: you get a shell after root has been mounted at /new_root.
Otherwise use init=/bin/bash.
If the initramfs was built with dracut, the common case, add rd.break.
You get a switch_root:/# prompt, with the installed root filesystem mounted read-only at /sysroot:
mount -o remount,rw /sysroot
for d in proc sys dev; do mount --rbind /$d /sysroot/$d; done
chroot /sysroot
Make your fix (see Repair the system), then type exit twice.
If you use a different initramfs generator, or none, use init=/bin/bash.
Start a shell instead of init¶
As a last resort, replace the init system with a shell. Add:
The kernel starts bash as PID 1: no services, no other mounts, no password prompt, and usually a read-only root filesystem.
Because bash is PID 1, the normal reboot and poweroff commands don't work, and exiting the shell makes the kernel panic.
On RHEL, AlmaLinux and Rocky Linux, no SELinux policy is loaded in this shell either: whenever you change a file, run touch /.autorelabel before leaving, as after rd.break.
Leave this mode as described at the end of Repair the system.
Warning
Anyone with console access can do this, unless the GRUB menu is password-protected or the disk is encrypted. That's a reason to protect consoles, not a reason to avoid the technique in an emergency.
Repair the system¶
In a rescue or emergency shell, or after init=/bin/bash, you're root.
After an initramfs break, you're root inside the chroot, and the root filesystem is already writable.
-
Check how the root filesystem is mounted.
roin the options means you can't change anything yet: -
Make it writable:
In emergency mode, mount any other filesystem you need, for example
mount /boot, ormount -aonce/etc/fstabis fixed. -
Find the cause.
Read the errors from the boot that failed, and list the units that failed:
-b -1is the previous boot; use-bfor the current one if the failing boot dropped you into emergency mode by itself.Read the errors from the boot that failed, and list the units that failed:
-b -1is the previous boot; use-bfor the current one if the failing boot dropped you into emergency mode by itself.Read the errors from the boot that failed, and list the units that failed:
-b -1is the previous boot; use-bfor the current one if the failing boot dropped you into emergency mode by itself.With OpenRC, read the system log (
/var/log/messageswithsysklogdand most other syslog daemons), OpenRC's own log if you enabledrc_logger, and list services that died:rc-status --crashedlists services that died; when there are none, it prints nothing and exits with status 1: -
Fix it. Common repairs:
- A bad
/etc/fstabline: correct it, or addnofailto its options so a missing filesystem doesn't stop the boot. Check the file withfindmnt --verify, and on systemd runsystemctl daemon-reloadafterwards. - A service that hangs or breaks the boot:
systemctl disable <SERVICE>, orrc-update del <SERVICE> defaulton OpenRC.<SERVICE>is the service name. - A lost root password:
passwd root. On RHEL, AlmaLinux and Rocky Linux, afterrd.breakorinit=/bin/bash, alsotouch /.autorelabel.
- A bad
-
Return to a normal boot.
After
init=/bin/bash, there's no init to hand back to. Write everything to disk, make the root filesystem read-only again, and force a reboot:Alternatively,
exec /sbin/initstarts the normal init system from the shell, continuing the boot.
Verify¶
After the system boots normally, check that nothing failed and that root is mounted read-write:
$ systemctl --failed --no-pager
UNIT LOAD ACTIVE SUB DESCRIPTION
0 loaded units listed.
$ findmnt -no OPTIONS /
rw,relatime,errors=remount-ro
systemctl is-system-running --wait waits for the boot to finish and then prints running; degraded instead means the system booted, but at least one unit failed, which systemctl --failed lists.
$ systemctl --failed --no-pager
UNIT LOAD ACTIVE SUB DESCRIPTION
0 loaded units listed.
$ findmnt -no OPTIONS /
rw,relatime,errors=remount-ro
systemctl is-system-running --wait waits for the boot to finish and then prints running; degraded instead means the system booted, but at least one unit failed, which systemctl --failed lists.
$ systemctl --failed --no-pager
UNIT LOAD ACTIVE SUB DESCRIPTION
0 loaded units listed.
$ findmnt -no OPTIONS /
rw,relatime,errors=remount-ro
systemctl is-system-running --wait waits for the boot to finish and then prints running; degraded instead means the system booted, but at least one unit failed, which systemctl --failed lists.
Troubleshooting¶
"Cannot open access to console, the root account is locked."
The rescue and emergency shells need a root password.
On systemd, boot again with SYSTEMD_SULOGIN_FORCE=1 added to the kernel command line, or use an initramfs break or init=/bin/bash; then set a root password with passwd root.
On Arch, the emergency shell inside the initramfs always needs SYSTEMD_SULOGIN_FORCE=1, because the initramfs has its own locked root account.
The edited parameter has no effect.
Check that you added it to the line starting with linux, not to the initrd line, and that the line didn't wrap into a new line.
On a system booting a unified kernel image or with Secure Boot and a locked command line, the parameters can't be changed at boot; boot from installation or rescue media instead, mount the root filesystem and chroot into it.
mount -o remount,rw / fails with "cannot remount … read-write, is write-protected" or a filesystem error.
The filesystem needs checking, and that has to happen while it isn't mounted.
In rescue and emergency mode the root filesystem is mounted, and xfs_repair refuses to work on a mounted filesystem.
Boot from rescue media, or with dracut stop before root is mounted with rd.break=pre-mount, and check the device with the tool for its filesystem (fsck for ext4, xfs_repair for XFS, btrfs check for Btrfs), read-only first.
The system drops back into emergency mode on every boot.
A unit the boot depends on keeps failing, most often a filesystem in /etc/fstab.
journalctl -xb in the emergency shell shows which unit failed and why.
Related¶
- Explanation: The Linux boot process
- Explanation: OpenRC and other init systems
- Reference: systemd unit directives
- How-to: How to run a script as a service