Week 1 - Boot, Init, Systemd¶
1.1 Conceptual Core¶
- A modern Linux boot is a chain of progressively more-Linux-like stages: firmware (UEFI / BIOS) → bootloader (GRUB / systemd-boot) → kernel + initramfs →
/sbin/init(systemd, mostly). - systemd is the dominant init+service manager. It is not SysV-init with
Type=simpleunits bolted on; it is a unit-graph dependency engine that supervises sockets, timers, mounts, slices, and services as first-class objects. - The unit hierarchy:
target(a runlevel-equivalent) ←service/socket/timer/mount/device/slice/path← drop-ins (/etc/systemd/system/foo.service.d/*.conf).
1.2 Mechanical Detail¶
- Boot trace:
dmesg | head -200plusjournalctl -b 0 --no-pagershows the kernel and userspace boot logs from the current boot. systemd-analyze blameandsystemd-analyze critical-chaindecompose boot time.- A unit file's anatomy:
[Unit](deps, ordering),[Service](exec, restart, security),[Install](alias, enable target). - Hardening directives:
NoNewPrivileges=yes,ProtectSystem=strict,ProtectHome=yes,PrivateTmp=yes,RestrictAddressFamilies=AF_INET AF_INET6,CapabilityBoundingSet=,SystemCallFilter=@system-service,MemoryMax=,CPUQuota=. Every long-running service should set these. systemctl edit <unit>for drop-ins; never edit/lib/systemd/system/*(overwritten by package updates).
1.3 Lab-"A Hardened Echo Service"¶
- Write a tiny C program that listens on a Unix socket and echoes input. Static-link with - static`.
- Write a
echo.socketandecho.servicepair using socket activation. - Apply every hardening directive that is plausible for an echo server. Run
systemd-analyze security echo.serviceand aim for a score under 1.0. - Verify isolation: from inside the service (debug via
systemd-run --shell --unit=echo.service), confirmProtectSystemmakes/usrread-only.
1.4 Hardening Drill¶
- Read
man systemd.execcover-to-cover. Make a one-page cheat sheet of hardening directives.
1.5 Performance Tuning Slice¶
- Capture
systemd-analyze plot > boot.svgfrom a fresh VM. Identify the longest-blocking unit and propose aBefore=/After=adjustment.