,

Contents · Boot process and init systems (systemd)


From power-on to userspace

  1. Power-on reset → firmware initializes hardware.
  2. Firmware locates boot device and loads bootloader.
  3. Bootloader selects and loads kernel (+ initramfs) and passes cmdline.
  4. Kernel initializes subsystems, mounts rootfs, executes PID 1 (init/systemd).

Firmware: BIOS vs UEFI, Secure Boot

  • UEFI replaces legacy BIOS with a standardized environment and GPT partitioning.
  • Secure Boot validates boot chain signatures to prevent unauthorized loaders.
  • NVRAM variables store boot entries; ESP (EFI System Partition) holds loaders.

Bootloaders: GRUB, systemd-boot

  • GRUB: flexible, modules for filesystems, menus, rescue shell.
  • systemd-boot: simple UEFI loader reading entry files from ESP.
  • Kernel command line controls early boot (e.g., root=, quiet, systemd.unit=, rd.luks.name=).
// Parse kernel cmdline (conceptual)
function parseCmdline(cmd){
  return Object.fromEntries(cmd.split(/\s+/).map(kv=>kv.split('=')));
}

Kernel early boot and initramfs

  • Initramfs is a cpio archive containing minimal userspace to assemble rootfs (LVM, RAID, LUKS).
  • udev populates /dev; early mounts of /proc and /sys; switch_root to final rootfs.
  • panic/recovery paths: dracut/emergency shell for diagnostics.

systemd architecture and units

  • PID 1 manages processes via declarative unit files: service, socket, mount, automount, timer, target, slice, etc.
  • cgroups v2 integration: each unit gets a cgroup subtree for resource control and accounting.
  • journald provides structured logs; logind manages sessions; networkd/resolved optional.
# Example: /etc/systemd/system/myapp.service
[Unit]
Description=My App
After=network-online.target
Wants=network-online.target

[Service]
ExecStart=/usr/local/bin/myapp --port=8080
Restart=on-failure
User=myapp
Group=myapp

[Install]
WantedBy=multi-user.target

Targets, dependencies, and ordering

  • Targets group units (e.g., basic.target, multi-user.target, graphical.target).
  • Ordering vs requirement edges: After/Before vs Requires/Wants; avoid cycles.
  • Activation: socket, path, device, and timer units start services on demand.
# Timer + service pair
# myjob.timer
[Timer]
OnCalendar=*:0/5
Unit=myjob.service

# myjob.service
[Service]
Type=oneshot
ExecStart=/usr/local/bin/myjob

Troubleshooting boot and services

  • Use systemd.unit=rescue.target or emergency.target for recovery.
  • journalctl -b, -u, and -k for boot and service logs; systemctl list-dependencies for graphs.
  • Kernel params: systemd.log_level=debug, systemd.mask=UNIT to isolate issues.

Exercises

  1. Create a systemd service + timer that runs a maintenance job and logs output to journal.
  2. Build a minimal initramfs (dracut or mkinitcpio) and boot a VM from it; add an emergency shell.
  3. Switch default target and trace boot ordering with systemd-analyze blame/critical-chain.
A reliable boot = trusted firmware, correct loader, proper kernel cmdline, valid initramfs, and well-ordered systemd units.