brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: systemd.unit=rescue.target on the kernel command line boots into a rescue shell

Systemd
~/tips/tip-kernel-cmdline-systemd-unit-rescue

systemd.unit=rescue.target

Adds one option to the kernel command line for a single boot, to land in rescue or emergency mode.

A server that stalls during boot is a good moment to remember that the kernel command line can pick the systemd target. One option gets you a shell with the basics running.

In the GRUB menu, press e on an entry to edit it. Add this at the end of the line that starts the kernel (the linux line), then press Ctrl-x to boot the edited entry:

systemd.unit=rescue.target

The systemd man page says systemd.unit= overrides the unit to activate on boot, which defaults to default.target, and that it may be used to temporarily boot into a different unit. The rescue.target pulls in the base system including the mounts, and spawns a rescue shell. It is single-user mode with all file systems mounted and only the most basic services running.

The shorter spellings are documented as equivalents: rescue, single and 1 mean systemd.unit=rescue.target. The word emergency means systemd.unit=emergency.target, which is much more minimal: it starts a shell on the main console and does not pull in other services or mounts. 3 and 5 select multi-user.target and graphical.target.

The caveats: the prefix rd. (as in rd.systemd.unit=) is only honored inside the initrd, while the unprefixed option is honored only in the main system. In the GRUB editor, ESC aborts all your changes and returns to the menu. And a GRUB menu protected by a password only lets you choose an entry, so the editor is not available then.

Without a monitor, you need a serial or remote console to reach this at all.

Further reading: systemd man page: kernel command line, kernel-command-line man page

More Systemd tips [Service] sudo mkdir -p /etc/systemd/system/service.d [Service] printf 'hunter2' | sudo systemd-creds encrypt --name=dbpass – dbpass.cred systemd-analyze timespan 1h30min All Systemd tips (88) All topics

Link