Module 1 · Lesson 45 of 103

From power to initramfs

Trace boot control from firmware through the loader and kernel, read the kernel command line, and explain how initramfs reaches the real root filesystem.

  • Beginner to advanced
  • 10 min read
  • 2 min lab
What you will need

Ubuntu 24.04 VM with systemd, sudo and console access; an optional ARM board with a recoverable boot image

Your place in the module
By the end you can 3 objectives
  • Identify each boot stage and explain its handoff to the next stage.
  • Explain kernel command-line options and the role of an initramfs.
  • Inspect PID 1 and /proc/cmdline to identify the current boot environment.
Video coming soonFrom power to initramfs
The video for this lesson is being recorded. Read the lesson below in the meantime.
Recall first from Reclaim and disk images
  • Swappiness balances reclaim costs rather than setting a memory usage threshold.
  • Overwriting logical blocks does not guarantee sanitization of flash storage.
  • zram stores compressed swap in RAM as a block device; zswap caches compressed pages in front of a backing swap area.
01

From power to the first userspace process

5 min read

Before any service can run, firmware, a loader, the kernel and early userspace must each pass control to the next. This lesson answers how the board gets from power-on, through the kernel command line and initramfs, to the first userspace process.

Your board reaches a login prompt only after several programs have run. If it prints nothing, Linux may not have started at all. First ask which component has control. Not every boot failure comes from a service.

For example, a PC may use BIOS, the Basic Input/Output System, or UEFI, the Unified Extensible Firmware Interface. Their boot interfaces differ. BIOS commonly starts disk boot code. UEFI can load an EFI executable from an EFI System Partition, a specially identified FAT partition. EFI executables follow that firmware interface. UEFI also provides boot services before the operating system takes over.

For example, Ubuntu PCs commonly use GRUB. UEFI systems can also use systemd-boot. When enabled and configured correctly, Secure Boot verifies permitted boot components. It does not check whether your filesystem or service configuration is valid.

The kernel must prepare memory management and drivers before the installed system can use storage. It initializes processors and interrupts too. Interrupts notify processors of events; drivers are kernel components that operate hardware. The kernel starts early userspace if provided, reaches the real root filesystem, then runs init, the system's first process. Userspace means programs outside the kernel. Even the privileged service manager runs there.

A process identifier, or PID, identifies a process. A PID namespace gives processes their own view of those identifiers. On a normal Ubuntu host boot, systemd is PID 1. It manages init and services. It also reaps adopted children, collecting their exit status so the kernel can release their bookkeeping.

A deliberately configured embedded system can omit the early userspace image called initramfs. The diagram shows the common staged path that includes it. A kernel with an EFI stub can also start directly through UEFI without a separate interactive loader. The stub is an entry point that lets the kernel run as an EFI executable.

In the common staged boot with initramfs, firmware launches the loader, the loader starts the kernel, and the kernel runs early userspace; after storage preparation and the root handoff, the installed systemd executes with PID 1 retained.

  • states: [{"id": "firmware", "label": "Firmware"}, {"id": "loader", "label": "Loader"}, {"id": "kernel", "label": "Kernel"}, {"id": "early-userspace", "label": "Early userspace"}, {"id": "root-handoff", "label": "Root handoff (PID 1 retained)"}, {"id": "system-manager", "label": "System manager (systemd)"}]
  • transitions: [{"from": "firmware", "to": "loader", "event": "Launch the bootloader"}, {"from": "loader", "to": "kernel", "event": "Start the selected kernel"}, {"from": "kernel", "to": "early-userspace", "event": "Unpack initramfs and execute /init"}, {"from": "early-userspace", "to": "root-handoff", "event": "Prepare storage and mount the real root"}, {"from": "root-handoff", "to": "system-manager", "event": "Switch root and execute installed init"}]
The common boot chainFirmwarePreparehardwareLoaderKernel,image,commandlineKernelInitializeand unpackEarlyuserspaceLocate andmount rootInstalledinitRetain PID1ServicesReachrequiredoperatingstateFirmwarePreparehardwareLoaderKernel,image,commandlineKernelInitializeand unpackEarlyuserspaceLocate andmount rootInstalledinitRetain PID1ServicesReachrequiredoperatingstate
The common boot chain and the boundary between the kernel and userspace.
Step by stepFollow control through a normal boot
  1. Firmware: Prepare enough hardware to find and launch a boot entry.

  2. Loader: Select a kernel, optional early filesystem image and command line.

  3. Kernel: Initialize core parts of the system and unpack any initramfs image.

  4. Early userspace: Run initramfs init to find and mount the real root.

  5. Root handoff: Replace early userspace with installed init, keeping PID 1.

  6. System manager: Activate the units needed for the chosen operating state.

An ARM system-on-chip contains processors and peripherals in one chip. Its unchanging boot ROM may start a small loader to initialize RAM. U-Boot and Linux can follow. Board firmware, trusted firmware and device trees differ across platforms. Trusted firmware handles platform security duties. A device tree describes hardware to the kernel. Do not assume your ARM board uses GRUB, UEFI or PC serial device names.

Before using systemctl, inspect PID 1 and the boot command line to identify your learning environment:

bash
ps -p 1 -o pid=,comm=,args=
cat /proc/cmdline
Identify PID 1, the boot command line and the running kernel
learner@embeddex:~/lab$ # Show PID 1, the first userspace process
learner@embeddex:~/lab$ ps -p 1 -o pid=,comm=,args=
      1 systemd         /sbin/init

learner@embeddex:~/lab$ # Read the kernel command line used for this boot
learner@embeddex:~/lab$ cat /proc/cmdline
BOOT_IMAGE=/boot/kernel init=/initd loglevel=1 rootfstype=iso9660 console=tty0 linuxkit.unified_
cgroup_hierarchy=1 vsyscall=emulate panic=0 ibt=off eth0.dhcp eth1.dhcp vpnkit.connect=connect:/
/2/1999 root=/dev/sr0 text

learner@embeddex:~/lab$ # uname -r names the running kernel
learner@embeddex:~/lab$ uname -r
7.0.14-linuxkit

learner@embeddex:~/lab$

WSL uses a host-managed Linux startup path. A container normally shares the host kernel and may run one application as PID 1. Neither reproduces a PC's firmware-to-GRUB boot. A BusyBox image may instead use BusyBox init with /etc/inittab, its init configuration file. It may have no systemd tools.

02

Choosing a kernel and reading its command line

4 min read

Directly editing /boot/grub/grub.cfg on Ubuntu may work until the next regeneration overwrites it. GRUB separates its installed executable from menu configuration. Ubuntu generates that menu from /etc/default/grub and scripts under /etc/grub.d/. Inspect the generated file to diagnose the selected boot. Put persistent local settings in the supported inputs, then run sudo update-grub.

1Choose a known working entry

After a failed update, choose an older known working kernel from GRUB's advanced-options submenu. Ubuntu usually lists installed kernels and recovery entries there. Keep the working kernel's matching modules and initramfs until the replacement passes a real boot test. A file in /boot does not prove the menu references it correctly.

2Make a temporary diagnostic edit

On a normal unrestricted GRUB menu, select an entry and press e. Find the kernel invocation line, commonly beginning with linux, and edit its parameters. Follow the displayed boot keys, typically Ctrl-X or F10. The edit affects only this boot. A locked menu or security policy may restrict editing.

For example, /proc/cmdline shows the text used for this boot. GRUB's disk notation and root-search commands are separate from Linux's root= setting. The loader's root need not be the filesystem that becomes Linux's /.

Parameter Meaning and diagnostic use
root=UUID=... Identify the real root filesystem; distribution initramfs scripts commonly resolve filesystem UUIDs.
root=PARTUUID=... Identify a partition by partition identifier; useful when device enumeration changes.
ro / rw Request initial read-only or read-write root mounting; later boot policy may remount it.
console=tty0 Send kernel console output to the virtual-terminal console where supported.
console=ttyS0,115200n8 Configure a supported serial console with explicit baud and framing.
quiet / splash Reduce messages or request a distribution splash screen; remove them to expose progress.
single A compatibility request interpreted by systemd as rescue mode.
recovery An Ubuntu recovery-entry option consumed by distribution recovery tooling, not a universal kernel recovery mode.
systemd.unit=emergency.target Ask systemd to enter a minimal recovery target on the real system.

root=/dev/sda2 may select the wrong device when enumeration order changes. The table's ellipses are placeholders, not usable values. Resolving a filesystem UUID needs suitable early userspace support. Do not assume every kernel without initramfs recognizes every root-identifier form.

3Capture messages at the correct console

You may send kernel messages to both a screen and a serial port using multiple console= parameters. Their order also affects the preferred /dev/console. A console carrying messages does not guarantee a login prompt. A login service called a getty must run there too. For a board, check the UART, or Universal Asynchronous Receiver/Transmitter, serial controller. Also check pins, electrical voltage and baud rate, which sets communication speed. ttyAMA0 and ttyS0 are not interchangeable names.

Three configuration responsibilitiesLoader selectionGRUB menu or UEFI entryKernel parametersroot, console, ro or rwUserspace policyRecovery target and servicesEach stage interprets its own settingsLoader selectionGRUB menu or UEFI entryKernel parametersroot, console, ro or rwUserspace policyRecovery target and servicesEach stage interprets its ownsettings
Separate loader selection, kernel parameters and userspace policy.

Editing /etc/default/grub does nothing when your boot path uses systemd-boot. This loader uses UEFI entries and the Boot Loader Specification, which defines boot-entry layout. Configuration may use text entries under loader/entries/ on the appropriate boot partition. It may instead use unified kernel images under EFI/Linux/. A unified kernel image bundles the kernel and related boot data into an EFI executable. Its embedded command line and signature rules can limit how you change parameters.

Recovery requires a usable console

Practice recovery in a disposable VM with console access. A recovery target can require the root password; installations with a locked root account may reject that path. Changing parameters is not a substitute for an established recovery procedure.

03

Reaching the root filesystem through initramfs

4 min read

For example, a file named with initrd may actually contain initramfs. The name means initial RAM filesystem. Images commonly use compressed cpio archives, which store files and metadata. The older initrd mechanism used a RAM block device. It is technically different.

Consider root on an encrypted logical volume. First, Linux needs the storage-controller driver to find the disk. Then it needs cryptographic setup to unlock the encrypted mapping and LVM tools to activate the volume. Only then can it mount the filesystem containing the installed copies of those tools. Initramfs supplies them earlier, breaking this circular dependency.

A driver stored only on inaccessible root cannot help you reach root. Required drivers must be built into the kernel or supplied as loadable modules in early userspace. Modules are kernel components stored as files and loaded when needed. Filesystem support is necessary too. A small embedded system can omit external initramfs if root is directly accessible and essential drivers are built in. Network or encrypted root usually needs more early preparation.

1Unpack and execute early init

An /init script needs both a valid interpreter line and that interpreter inside the image. The kernel unpacks the archive into rootfs, its initial root filesystem, then runs /init if present. Init may be a script, compiled executable or systemd configured for initramfs. ELF is the usual Linux executable format. An ELF program needs the right architecture and, when used, matching dynamic loader, which loads its shared libraries.

2Discover and prepare storage

rootwait can help when direct kernel mounting needs a device that appears later. Early init loads modules, waits for devices, creates mappings and mounts the intended root. Initramfs implementations have their own wait and timeout rules. An endless wait may hide a wrong identifier. Compare the expected root identifier with the actual storage first.

3Hand off without creating a new init identity

Early init can remain PID 1 while becoming the installed system's init program. It moves necessary mounts such as /proc, /sys and /dev, then switches to the real root. These paths expose kernel information and devices. Executing installed init replaces the process's program without assigning a new PID. Early init and the system manager can therefore have PID 1 at different times.

Prepare the real rootRun earlyinitLoadstoragesupportUnlockstorageWhenencryptionisconfiguredActivatevolumesWhen LVM isconfiguredMount realrootSwitch andexecInstalledinitretains PID1Run earlyinitLoadstoragesupportUnlockstorageWhenencryptionisconfiguredActivatevolumesWhen LVM isconfiguredMount realrootSwitch andexecInstalledinitretains PID1
Early userspace prepares storage before switching to the installed system.

On Ubuntu, use its initramfs generator; other distributions may use different tools. These examples rebuild images on different systems. Do not run them as a sequence on one host:

bash
# Ubuntu/Debian using initramfs-tools: update the running kernel's image.
sudo update-initramfs -u -k "$(uname -r)"
# A dracut-based distribution: regenerate its default selected image.
sudo dracut --force
# Arch Linux using mkinitcpio: rebuild configured presets.
sudo mkinitcpio -P

uname -r names your running kernel, not necessarily the kernel you are preparing. For an offline target or newly installed kernel, select the intended version using the distribution's documented options. On Ubuntu, lsinitramfs /boot/initrd.img-$(uname -r) lists contents without booting the image. Check free /boot space before rebuilding. Keep a working recovery entry.

Going deeperFollow the source-level boundary

To trace unpacking into rootfs, read init/initramfs.c in Linux source. init/main.c contains the path that tries to execute init. When early /init does not take over, init/do_mounts.c helps mount root directly in the kernel. A root-mount panic and an initramfs recovery shell therefore point to different failing layers. A panic means the kernel cannot continue. Neither failure may reach the installed journal because persistent logging is not available yet.

An x86 helper copied into an ARM initramfs is present but unusable. Cross-compilation builds software on one architecture for another. Pair the ARM kernel with matching modules and the correct device tree. If an early helper cannot run, check architecture, required shared libraries and executable permissions.

Key takeaways

  • Firmware, loaders, the kernel and early userspace have different responsibilities.
  • An initramfs supplies the tools and drivers needed to reach the real root filesystem.
  • The kernel command line configures the kernel and early userspace; the loader's own root selection is separate from Linux's root= setting.
  • Early init can stay PID 1 while executing the installed init, so the process changes without changing the PID.
Reflect
  1. Explain to a colleague, in two sentences: identify each boot stage and explain its handoff to the next stage.
  2. Which objective are you least sure about? Re-read that section, then do its exercise in the practice pack.
  3. What surprised you when you ran the commands yourself?
On a real board

Repeat the key commands on your Raspberry Pi or lab board over SSH or the serial console. Note anything that behaves differently from your PC, such as missing tools, a BusyBox shell or a read-only filesystem.

References and further reading

Find your next step

↑ ↓ to move · Enter to open · Esc to close