A complete rescue mode session

Rescue mode is the repair bench of a rented machine. This walkthrough takes one session from the console button back to a running system.

When should I use rescue mode?

Whenever the installed system cannot be reached or should not be running while you work on it. Typical reasons are a boot loader that no longer starts, a broken /etc/fstab, a lost key or password, a firewall rule that shuts you out, a filesystem that needs checking unmounted, or copying data off a machine you suspect was compromised. Because rescue mode runs entirely in memory from the network, nothing on your drives changes unless you change it.

How do I start a rescue session?

Open the server page in your account and choose Boot in rescue mode. The machine restarts into the network system, the status shows Rescue mode, and the console displays a root password for the session. Give it three to five minutes, then connect over SSH to the usual IPv4 address. Your SSH client will warn that the host key changed; that is expected, because a different system answers. Remove the old entry for the session rather than ignoring the warning in general.

ssh-keygen -R 192.0.2.40
ssh -o UserKnownHostsFile=/dev/null root@192.0.2.40

How do I find my drives and arrays?

List block devices with their filesystems, then let mdadm assemble any software RAID it finds. The rescue system does not start your arrays by itself, so this step comes first on every mirrored model.

lsblk -o NAME,SIZE,TYPE,FSTYPE,LABEL
mdadm --assemble --scan
cat /proc/mdstat
vgchange -ay     # only if you use LVM

Arrays may come up under names like md126 and md127 instead of the names your system uses; the filesystem types and sizes tell you which is root. If an array assembles degraded, write that down for later: it may be the reason the machine stopped booting.

How do I check a filesystem?

Run the checker on the unmounted device, which is exactly what rescue mode makes possible. Use the tool that matches the filesystem type.

fsck.ext4 -f /dev/md126
xfs_repair -n /dev/md127     # -n reports only; drop it to repair

On XFS, a log that cannot be replayed makes xfs_repair refuse to run. Mounting and unmounting the filesystem once replays the log; use -L, which discards it, only as a last resort.

How do I work inside my installed system?

Mount root, then boot and EFI partitions, bind the kernel filesystems and enter with chroot. From there, commands run as if the system had booted: the package manager, passwd, update-grub and systemctl enable all act on your installation.

mount /dev/md127 /mnt
mount /dev/md126 /mnt/boot
mount /dev/nvme0n1p1 /mnt/boot/efi
for fs in dev dev/pts proc sys run; do mount --bind /$fs /mnt/$fs; done
chroot /mnt /bin/bash

Check the order of mounts against /mnt/etc/fstab once root is mounted. If DNS does not work inside the chroot, copy the rescue system's /etc/resolv.conf in temporarily so the package manager can reach its mirrors.

Which repairs come up most?

FaultRepair inside the chroot
Boot loader missing or brokengrub-install to each disk or EFI partition, then update-grub or grub2-mkconfig -o /boot/grub2/grub.cfg
Wrong UUID in /etc/fstabCompare with blkid, correct the line, add nofail to data mounts
Kernel or initramfs failsRebuild with update-initramfs -u -k all or dracut -f --regenerate-all
Lost password or keypasswd, or append to authorized_keys
Network config typoFix netplan, ifupdown or NetworkManager files in /etc

Can I copy data off the machine from rescue mode?

Yes, and it is often the first thing worth doing when a disk is failing. Mount the filesystem read-only and send it to another server with rsync or a tar stream over SSH. The port speed is the same as in normal operation, so a 1 Gbps machine moves around 350 GB an hour. For a database, see Rescue a database from a dead system, which covers getting a consistent dump out of a server that cannot start.

mount -o ro /dev/md127 /mnt
rsync -aHAX --info=progress2 /mnt/srv/ backup@198.51.100.9:/vault/fra1-srv/

How do I end the session?

Leave the chroot, unmount in reverse order and choose Boot from hard disk in the console. The machine restarts from its drives. If it still does not answer after ten minutes, boot rescue mode again and read the journal of the failed boot from /mnt/var/log/journal with journalctl -D, which usually names the problem.

exit
umount -R /mnt
journalctl -D /mnt/var/log/journal -b -1 -p err   # on a later visit, after mounting again

Rescue mode is the out-of-band path on our machines in place of a remote screen; IPMI and rescue mode explains how the two compare, and How a dedicated server boots describes each stage of a normal start.

Related pages

IPMI and rescue mode

What out-of-band management is, and how console power control, reinstall and rescue boot cover the same needs on our machines.

Read more

How a dedicated server boots

From power on to login prompt: firmware, boot loader, kernel, initramfs and systemd, and how disk boot differs from rescue boot.

Read more

Recover lost SSH access

Lost your private key or locked yourself out with a bad SSH setting? Add a new key or fix the configuration from rescue mode.

Read more

Rescue a database from a dead system

Get a consistent MariaDB, MySQL or PostgreSQL dump out of a server whose operating system no longer starts, working entirely from rescue mode.

Read more

Questions and answers

Does rescue mode change anything on my drives?

No. It runs from the network and in memory. Your drives change only when you mount and write to them.

Why does SSH warn about a changed host key in rescue mode?

A different system answers on the same address. Remove the old entry for the session with ssh-keygen -R and reconnect.

Why are my RAID arrays missing in rescue mode?

The rescue system does not start them automatically. Run mdadm --assemble --scan and check /proc/mdstat.

Can I reinstall the boot loader from rescue mode?

Yes. Mount the system, bind dev, proc, sys and run, chroot in and run grub-install and the configuration update for your distribution.

How do I leave rescue mode?

Choose Boot from hard disk in the console. The next restart uses the installed system on your drives.