Targets, runlevels, and what the kernel found
Objective 101.3 is runlevels and boot targets, and on a current machine the honest answer is that runlevels are a compatibility layer over systemd targets. This guide shows the target the machine boots to - and the surprise that the file supposedly defining it does not exist - then uses /proc and /sys to inventory the hardware without installing anything.
101: System Architecture Guide 5 of 33 Beginner
- OSUbuntu 26.04 LTS
- Kernel7.0.0-30-generic
- systemd259
- TimeAbout 17 min
| Server Name | IP Address | OS | Roles | CPU | RAM | HDD |
|---|---|---|---|---|---|---|
| LPIC1-A01 | 192.168.0.76 | Ubuntu 26.04 LTS | Debian-family host - dpkg and apt, which objective 102.4 names | 2 Core | 4 GB | 50 GB |
This guide includes
Use this for the runlevels objective on a machine that no longer has them. This matters because the compatibility layer answers some of these questions and not others - and the file the objective describes is not there at all.
- reading the default target, with nothing configured
- using the runlevel compatibility layer, and finding its limits
- reading hardware from files that are not on any disk
Before you start
- boot-firmware-and-what-the-kernel-was-told
-
The default target, and the file that is not there
get-defaultanswers even with nothing configured.bash Example session systemctl get-default; echo "---"; ls -l /etc/systemd/system/default.targetgraphical.target---ls: cannot access '/etc/systemd/system/default.target': No such file or directory[exit 2]systemctl list-units --type=target --state=active --no-pager | head -6 UNIT LOAD ACTIVE SUB DESCRIPTION basic.target loaded active active Basic System boot-complete.target loaded active active Boot Completion Check cryptsetup.target loaded active active Local Encrypted Volumes getty-pre.target loaded active active Preparation for Logins getty.target loaded active active Login PromptsExpected result
graphical.target- and thenls: cannot access '/etc/systemd/system/default.target': No such file or directory, followed by the targets currently active.Success conditionYou know where a default comes from when nobody has set one.
-
Runlevels, and why the command is missing
The compatibility layer, and its limits.
zsh Example session systemctl list-dependencies multi-user.target --no-pager 2>/dev/null | head -6multi-user.target● ├─apport.service● ├─chrony.service● ├─console-setup.service● ├─cron.service● ├─dbus.servicerunlevel; who -r; echo "--- the old interface, still answered for compatibility"zsh:2: command not found: runlevel--- the old interface, still answered for compatibilityExpected resultThe services
multi-user.targetpulls in - chrony, cron, dbus - and thenzsh: command not found: runlevel.Success conditionYou can answer a runlevel question on a machine that has no runlevels.
-
Hardware, from files that are not on a disk
/procand/sysare generated when you read them.bash Example session lscpu | grep -E '^(Architecture|CPU\(s\)|Model name|Hypervisor vendor|Virtualization)'Architecture: x86_64CPU(s): 2Model name: Intel(R) Core(TM) i9-14900KHypervisor vendor: MicrosoftVirtualization type: fulllsblk -d -o NAME,SIZE,ROTA,TYPE | head -6; echo "--- ROTA 1 = spinning, 0 = solid state"NAME SIZE ROTA TYPEfd0 4K 1 disksda 5G 1 disksdb 5G 1 disksdc 5G 1 disksdd 5G 1 disk--- ROTA 1 = spinning, 0 = solid statedf -h /proc /sys | tail -2; echo "--- size 0: they are generated on read"proc 0 0 0 - /procsysfs 0 0 0 - /sys--- size 0: they are generated on readExpected resultx86-64, 2 CPUs, an i9-14900K under a Microsoft hypervisor; the disks with
ROTA 1; and/procand/sysreporting size 0.Success conditionYou can inventory a machine without installing a single tool.
Troubleshooting
systemctl get-defaultanswers, but/etc/systemd/system/default.targetdoes not exist.Why: When no local override has been set, systemd falls back to the distribution default and there is no symlink in /etc to see.
Fix:Trust
systemctl get-default. Runningsystemctl set-default <target>is what creates the symlink; before that, nothing in /etc records the choice.runlevelortelinitis not found.Why: These are SysV compatibility commands. On a systemd-only installation the package that provides them may not be installed at all.
Fix:Use the systemd equivalents:
systemctl get-default,systemctl list-units --type=target --state=active, andsystemctl isolate <target>instead oftelinit.lshw,dmidecodeorlspciis unavailable and hardware still has to be identified.Why: Those are separate packages. The kernel already exposes the same information through generated filesystems.
Fix:Read
/proc/cpuinfo,/proc/meminfoand/sys/class/dmi/id/*. They are generated on read, exist on every machine, and need no package.