447. Recovering an unbootable system
This page is the procedure for an installed KDOS machine that does not reach a working desktop: how to tell where the boot stopped, which way in each case leaves you (the recovery console, the rescue shell, single-user and emergency mode, the live medium), and how to repair the common causes from there: a failing service, a damaged filesystem, a kernel missing from the EFI system partition (ESP), a boot loader that is gone, an update that will not boot. The boot path itself is explained in Boot and init; this page gives the procedures.
Installation
Every way in ships on the image; nothing has to be installed beforehand. One thing has to be set up in advance: a root password, for single-user and emergency mode.
| Way in | Provided by | Reached |
|---|---|---|
The recovery console, a plain login on tty2 |
fs/etc/inittab, agetty from util-linux |
Ctrl+Alt+F2 from the desktop, Alt+F2 from a text console |
| The rescue shell | The initramfs init (script/phases/70_image/090_initramfs.sh) |
By itself, when the initramfs cannot find, unlock or mount the root |
| Single-user mode | sysvinit and sulogin from util-linux |
The KDOS <version> (single user) menu entry |
| Emergency mode | The same | emergency added to an entry in Limine’s editor |
| The live medium | The KDOS stick the machine was installed from, or any later one | The firmware’s boot menu |
| A memory test | memtest86plus | The Memory Test (memtest86+) menu entry, UEFI only |
The live medium carries every tool the procedures below use: cryptsetup, lvm and vgchange, mdadm, e2fsck, fsck.fat, limine, efibootmgr and kdos-bootctl.
Configuration
The consoles and single-user mode are entries of /etc/inittab, shipped from fs/etc/inittab:
# Runlevel 3 is the running system. S is single-user: sulogin on the
# console, no consoles from this file. 0 powers off and 6 reboots.
id:3:initdefault:
si::sysinit:/etc/init.d/rcS
# sulogin asks for root's password on the console. Leaving its shell
# continues to runlevel 3. The initramfs passes `single` from the kernel
# command line, and `telinit S` reaches it from a running system. -p makes
# the shell a login shell, which reads /etc/profile: init's own PATH does not
# reach /usr/local, where `kdos` and the other KDOS commands live.
~~:S:wait:/sbin/sulogin -p
# Local Console (QEMU Window / Physical) — the display manager.
#
# kdos-dm execs SDDM, whose greeter compositor takes tty1. It is started here
# and never from rcS: init reaches this line only once rcS has returned, and the
# splash stops drawing synchronously at its end (`kdos-splash handoff`), its
# settled frame left on screen for the compositor's first frame to replace, so
# the compositor's modeset never races the splash for the DRM master.
#
# A MISSING OR FAILING SDDM STILL GIVES A CONSOLE. sddm stays up across every
# login and logout, so a respawn here is sddm having exited; kdos-dm turns a
# missing binary, a missing account or three exits in a minute into a password
# prompt on tty1 through kdos-getty, never an autologin. Autologin is SDDM's
# alone, in /etc/sddm.conf.d/kde_settings.conf.
1:2345:respawn:/usr/local/sbin/kdos-dm
# Second console, a login prompt for any account. THE RECOVERY CONSOLE: it
# is a plain agetty with no --autologin, and nothing above may be allowed to
# make it one too, because it is what is left when the desktop on tty1 does
# not come up — a greeter SDDM keeps restarting included, which no respawn
# here ever sees. kdos-getty loads the console font and palette after fbcon's
# deferred take-over; doing that in rcS is futile, because the take-over resets
# every VT's font. agetty hands the name to /bin/login, util-linux's PAM login
# (/etc/pam.d/login, through system-login), so a console login is a session
# elogind knows and starts the user's services like any other.
#
# EVERY AGETTY HERE NAMES /etc/issue. agetty built against musl, which has no
# scandirat(), reads no issue file of its own accord, and without
# --issue-file the banner /etc/issue holds is never printed.
2:2345:respawn:/usr/local/sbin/kdos-getty tty2 /sbin/agetty --noclear --issue-file /etc/issue tty2 38400 linux
sulogin asks for root’s password. The installer locks root unless it was asked to set a root password (root_locked in an answer file, see The keys), and a locked root leaves single-user and emergency mode with no shell: sulogin prints Cannot open access to console, the root account is locked. and Press Enter to continue., and after Enter the boot carries on to runlevel 3. Set one while the machine works:
sudo passwd root
The service scripts are run by this loop in rcS, which writes each script’s output to a log and skips any script with a marker under /etc/service.disabled/:
INIT_DIR="/etc/init.d"
DISABLED_DIR="/etc/service.disabled"
for _script in "${INIT_DIR}"/[0-9][0-9]_*.sh; do
[ -x "$_script" ] || continue
_name=$(basename "$_script" | sed 's/^[0-9][0-9]_//;s/\.sh$//')
if [ -f "${DISABLED_DIR}/${_name}" ]; then
echo "[KDOS] Skipping disabled service: ${_name}"
continue
fi
echo "[KDOS] Running: $(basename $_script) start"
splash step "$(echo "$_name" | tr '[:lower:]' '[:upper:]')"
# Redirect to a file and print it AFTERWARDS, never through a pipe. A
# `supervise` points the supervisor and the daemon at its own log
# forwarder, so a supervised service lets go of the script's output; any
# other process a script leaves running with that output open would hold
# a pipe's write end, a `| tee` would never see EOF, and the boot would
# stop at that service. A file has no reader to wait on.
#
# Every message still reaches the console and the serial line, which is
# the only way to debug a machine that dies behind a splash — just after
# the step rather than streamed during it.
_log="/run/kdos-init.${_name}.log"
"$_script" start >"$_log" 2>&1
_rc=$?
cat "$_log"
_verdict=$(stage_verdict "$_rc" "$_log")
if [ "$_verdict" != fail ]; then
splash "$_verdict"
else
splash fail
# The reason, not just the verdict. On the live medium this output
# goes to the serial line, and the screen shows only the splash.
while IFS= read -r _l; do
splash detail "$_l"
done < <(tail -n 6 "$_log" 2>/dev/null)
unset _l
fi
unset _rc _verdict
done
fs/etc/init.d/rcS, lines 192–232
Usage
Finding where it stopped
The splash names each stage as it runs, so the last name on it says where the boot stopped.
| Stopped at | Go to |
|---|---|
| Nothing on screen, or the firmware reports no boot device | Putting the boot loader back |
| The menu appears; the chosen entry stops at once | Putting a kernel back on the ESP |
An initramfs stage, then a shell on tty1 |
The rescue shell |
ROOT FILESYSTEM HAS ERRORS - RUN e2fsck |
Repairing from the live medium, step 5 |
| A service stage marked failed, or a stage that never ends | A service that fails or hangs |
| The splash finishes; then a black screen | The desktop does not start |
| The first boot after an update | After an update |
The full table of stages and their logs is in When a boot stops.
The desktop does not start
- Press
Ctrl+Alt+F2(Alt+F2if the screen is a text console) and log in ontty2. - Run
kdos doctor, and read its Session and Desktop sections. - Read the service logs of this boot:
ls /run/kdos-init.*.log, and/run/kdos-svc.<name>.logfor a supervised daemon, elogind’s among them. - Read the display manager’s log,
/var/log/sddm.log, andsudo grep kdos-dm /var/log/messages: SDDM that cannot run leaves a text password prompt ontty1instead of a black screen. - The procedures for each stage from the greeter to the desktop are on Desktop troubleshooting.
A service that fails or hangs
A failed script does not stop the boot; its stage is marked failed, the last lines of its output are on the splash, and the whole output is in /run/kdos-init.<name>.log. A script that never returns stops the boot at its stage, and no login prompt appears, because the consoles start only after rcS finishes.
If a login prompt appears, log in on
tty2and read/run/kdos-init.<name>.log.If the boot hangs, reboot into emergency mode (below), which opens a root shell before
rcSruns.Disable the script by its name, without the number and the
.sh; for45_avahi.shthat isavahi:touch /etc/service.disabled/<name>Leave the shell, from emergency mode, or reboot.
rcSskips the script, prints[KDOS] Skipping disabled service: <name>on the console, and writes no/run/kdos-init.<name>.logfor it. On the live medium the console is the serial line; on an installed machine it is the screen, and the line does not reach/var/log/messages.Repair the service from the running system, then remove the marker to enable it again.
Single-user mode
- Stop the boot menu’s countdown and choose
KDOS <version> (single user). rcSruns as on every boot, so every enabled service starts and every mount in/etc/fstab, the ESP included, is made.suloginasks for root’s password on the console:Enter root password for system maintenanceand(or press Control-D to continue):. A root login shell opens, with/usr/local/binand sokdoson itsPATH, no getty on any console and no desktop;runlevelprintsN S.- Leaving the shell continues to the running system: init prints
INIT: Entering runlevel: 3and the consoles start.
From a running system, sudo telinit S reaches the same state after ending the consoles and the session.
Emergency mode
- Stop the countdown, highlight
KDOS, and pressE. - Add
emergencyto thecmdline:line, and pressF10to boot it. The editor is described in Adding a parameter for one boot. suloginruns beforercS, with the same prompt as single-user mode: only the initramfs’s mounts exist, which are the root,/proc,/sys,/devwith/dev/ptsand/dev/shm, and no service has run (/run/kdos-init.*.logdoes not exist yet;runlevelprintsunknown). The initramfs has stopped the splash, so the prompt is on the screen as well as on the serial line. The shell keeps init’sPATH, which does not reach/usr/local/bin: runkdosas/usr/local/bin/kdos, orexec bash -lfirst.- Leaving the shell continues the boot with
rcS, and from there as on any boot.
The rescue shell
The initramfs opens it when it cannot find the root, cannot unlock its container, or finds no /sbin/init on it; the reason is printed above the prompt. What each reason means, the tools the shell has and how to restart from it are on The initramfs and the rescue shell. The two facts to keep in mind: leaving the shell with exit panics the kernel, and sync; echo b > /proc/sysrq-trigger restarts the machine.
Repairing from the live medium
This is the way in that needs no password on the machine and works whatever state the installed system is in. Steps 3 and 4 apply only to a root that is encrypted or on LVM; skip the ones that do not match your disk.
Boot the KDOS stick and open a terminal. On the live medium root’s password is
kdos, and thekdosaccount can usesudowith its own password, which is alsokdos.Find the disk and its partitions:
lsblk -f, orsudo blkid.Open an encrypted root under the name the initramfs uses:
sudo cryptsetup open /dev/sdX2 kdosrootActivate any volume groups:
sudo vgchange -aay. On a machine installed with two slots on LVM it reports2 logical volume(s) in volume group "kdos" now active.Check the filesystems while they are not mounted:
sudo e2fsck -f <root device>for an ext root,sudo fsck.fat -a <esp device>for the ESP. btrfs, xfs and f2fs check themselves at mount time.Mount the root and its ESP:
sudo mkdir -p /mnt/target sudo mount <root device> /mnt/target sudo mount <esp device> /mnt/target/boot/efiRepair what the logs point at: read
/mnt/target/var/log/messages, disable a service withsudo touch /mnt/target/etc/service.disabled/<name>, or follow the two procedures below.Flush and unmount:
sync, thensudo umount /mnt/target/boot/efi /mnt/target, andsudo cryptsetup close kdosrootif you opened one. Reboot without the stick.
Putting a kernel back on the ESP
Each slot boots the kernel in EFI/kdos/<slot>/ on the ESP, copied from that root’s /boot. With the root and its ESP mounted as above, kdos-bootctl can be pointed at them through KDOS_BOOTSTATE, from which it also takes the ESP and limine.conf:
sudo KDOS_BOOTSTATE=/mnt/target/boot/efi/EFI/kdos/bootstate kdos-bootctl deploy /mnt/target a
It prints slot a boots 7.2.11 from EFI/kdos/a and regenerates the /KDOS entries of the ESP’s limine.conf. With KDOS_BOOTSTATE redirected and KDOS_EFIVARS unset, it writes no firmware variable. It refuses, and writes nothing, when the ESP has no room for both files or the initramfs carries no modules for the kernel.
When the boot state itself is gone, the same variable recreates it: kdos-bootctl status reports no boot state at … and exits 1 (the ESP is not mounted at … when the target’s ESP is not mounted, which is mounted first), and set-slot a <filesystem-uuid> writes a fresh state with slot A active (set-slot b <uuid> then records a second slot). Run each with the same KDOS_BOOTSTATE= prefix as the deploy above. sudo blkid <root device> prints the filesystem UUID. For an encrypted root, give the LUKS container’s UUID as a third word (sudo blkid /dev/sdX2); kdos-bootctl crypt <fs-uuid> prints it once the container is open.
Putting the boot loader back
With the ESP mounted at /mnt/target/boot/efi, and the whole disk as /dev/sdX:
The UEFI loaders, at the path the firmware falls back to:
sudo mkdir -p /mnt/target/boot/efi/EFI/BOOT sudo cp /usr/share/limine/BOOTX64.EFI /usr/share/limine/BOOTIA32.EFI /mnt/target/boot/efi/EFI/BOOT/The BIOS second stage, at the root of the ESP, and the BIOS boot code:
sudo cp /usr/share/limine/limine-bios.sys /mnt/target/boot/efi/ sudo limine bios-install /dev/sdX 2The
2is the BIOS boot partition, partition 2 of the layout the installer’s erase plan writes, where Limine’s stage goes on a GPT disk. Without the number Limine finds a BIOS boot partition by its type itself (Autodetected partition 2 as BIOS boot partition.), and on a dos (MBR) disk it needs none. A GPT disk with no BIOS boot partition getserror: Installing to a GPT device, but no BIOS boot partition specified or detected., the command undoes its work, and the disk starts only through UEFI.On a UEFI machine, the firmware entry the installer writes, naming the ESP’s partition number:
sudo efibootmgr --create --disk /dev/sdX --part <n> --loader '\EFI\BOOT\BOOTX64.EFI' --label KDOSThe firmware’s removable-media fallback starts
EFI/BOOT/BOOTX64.EFIwithout an entry.limine.confitself must still be at the root of the ESP. If it is gone, no tool writes it from nothing; its shape is on Boot menu and kernel parameters. Writing the three/KDOSentries by hand, with the rightkdos_slot=,bootstate=UUID=androot=UUID=words, is enough: the nextkdos-bootctlwrite (aset-slot, adeploy, themark-goodthat confirms a boot) regenerates the other entries, and, once the machine runs again,kdos theme <accent>(orsudo kdos-bootctl theme <accent>) puts the theme keys back.
These are the installer’s own steps (src/system/kinstall-core/install.c), run by hand. Steps 1, 3 and 4 make the disk start through UEFI; step 2 makes it start on a BIOS machine.
After an update
An A/B update that does not finish booting rolls itself back. To leave it sooner, pick the confirmed slot’s KDOS <version> (slot <x>) entry; see A/B slots and rollback. An update applied with --in-place has no second slot to fall back to: boot the live medium and repair the root as above.
Tips
tty2is a plainagettywith no automatic login, and nothing on the desktop’s path can change that, so it is there wheneverrcShas finished.- With a root password set, most repairs can be made in single-user or emergency mode without the live medium. Set one before you need it.
- The machine’s own boot logs under
/runare gone at every reboot;/var/log/messageskeeps the system log across boots. - The initramfs ignores
init=: there is noinit=/bin/shshortcut. Emergency mode is the nearest equivalent. - Random crashes and a filesystem that keeps acquiring errors are a reason to run the memory test before anything else.
Troubleshooting
sulogin says the root account is locked. Root has no password. Boot the live medium, mount the root as in Repairing from the live medium, give it the live system’s devices, and set one inside it:
sudo mount --bind /dev /mnt/target/dev
sudo chroot /mnt/target passwd root
sudo umount /mnt/target/dev
passwd asks New password: and Re-enter new password: on the terminal and prints passwd: password changed.; sudo chroot /mnt/target passwd -S root reads root L … before and root P … after. Single-user and emergency mode then ask for that password and open a root shell.
The KDOS <version> (single user) entry boots straight to the normal system. sulogin gave up for the reason above, and after Enter init printed INIT: Entering runlevel: 3 and carried on.
The machine powers on, and the firmware says there is no bootable device. On UEFI, check that Secure Boot is off; Limine’s loader is unsigned. Otherwise put the boot loader back.
The menu appears and every entry fails at once. The kernel or initramfs the entry names is missing from EFI/kdos/<slot>/. Mount the ESP from the live medium and look; then put a kernel back.
fsck: errors left uncorrected on the splash. A filesystem other than the root has errors; the report is in /run/kdos-fsck.log. On the ESP, repair it with fsck.fat from the live medium.
The power button turns the machine off at a text console. That is the setting outside a desktop session: elogind’s HandlePowerKey=poweroff in /etc/elogind/logind.conf.d/50-kdos.conf applies at the login screen and on a console login, and inside a Plasma session the power button opens the logout screen instead. In emergency mode elogind has not started, and the button does nothing. To shut down from a prompt on purpose, use sudo poweroff.
Known gaps
- Secure Boot is not supported
- A disk-encryption key is typed, not sealed in the TPM
- A root filesystem on LVM has been booted in one shape only
- Per-slot kernels have been booted on virtual firmware only
See also
- When a boot stops and Single-user and emergency mode
- Diagnosing and Services
- What the installer writes
- The initramfs and the rescue shell: the rescue shell’s messages and what each one means
- A/B slots and rollback: rolling an update back and booting the other slot once
- Boot menu and kernel parameters: reaching the menu and adding a parameter for one boot
- Live persistence: booting the live medium past its persistence store
- Init and runlevels:
/etc/inittab, the recovery console and single-user mode - Services: finding out why a service did not start, and keeping one from starting
- Logs: what a boot printed, and the system log across boots
- Encrypted root: opening an encrypted root by hand from the live medium