Linux › Section E · How the Linux kernel boots › Topic E.2
Kernel initialization and parameters
Between being loaded and starting init, the kernel works through a fixed sequence of set-up steps, guided by a short line of text from the boot loader. That line, the kernel command line, decides where the root filesystem is, how chatty the boot is, and much more.
What the kernel does first
Once the boot loader jumps into it, the kernel decompresses itself and initialises in a broadly fixed order. 1. It inspects the CPU and its features. 2. It finds out how much memory there is and sets up memory management. 3. It discovers buses such as PCI. 4. It finds devices on those buses and binds drivers to them. 5. It starts other subsystems, such as networking. 6. It mounts the root filesystem. 7. It starts user space by running init as process 1. Steps 4 and 6 depend on each other: the kernel cannot mount the root filesystem until the driver for its disk, and perhaps for encryption or LVM, is available.
Built-in drivers and modules
Distribution kernels keep most drivers as loadable modules, files ending in .ko under /lib/modules/ in a directory named after the release that uname -r prints, such as 6.8.0-45-generic: version 6.8.0 plus a distribution suffix. Mainline versions appear about every nine or ten weeks, and long-term support (LTS) series get fixes for years. Modules keep the kernel small, but they create a puzzle: the module for the root disk lives on the root disk. The usual answer is an initial RAM filesystem, loaded by the boot loader alongside the kernel, which carries the needed modules and mounts the real root; the topic "The initial RAM filesystem" explains it. A kernel built for one machine can instead compile those drivers in. The kernel logs Run /init as init process when the initramfs takes over.
The kernel command line
The boot loader hands the kernel a single line of text: the kernel parameters, or command line. You can read the line the running kernel received in /proc/cmdline. An illustrative example: BOOT_IMAGE=/boot/vmlinuz-6.8.0-45-generic root=UUID=2f6c...e91a ro quiet splash. Each word is either a flag, such as ro or quiet, or a key=value pair, such as root=UUID=... Values containing spaces can be protected with double quotes, and in parameter names dashes and underscores are equivalent. The manual page bootparam(7) introduces the common parameters, and the kernel's own documentation file, kernel-parameters, lists them all.
root= and ro
root= is the one parameter that cannot be left wrong: it tells the kernel which device holds the root filesystem. It may be a device name, root=/dev/sda2; a logical volume, root=/dev/mapper/vg0-root; or an identifier, root=UUID=... or root=PARTUUID=..., which do not depend on detection order and are preferred. rootwait makes the kernel wait for slow devices such as USB or SD cards. ro mounts the root filesystem read-only at first, so it can be checked safely with fsck; systemd later remounts it read-write according to /etc/fstab. rw mounts it writable from the start; with neither, the kernel mounts it read-only.
Other common parameters
quiet suppresses most kernel messages on the console. loglevel=N prints only messages more important than level N, where 0 is emergency and 7 is debug, so loglevel=8 shows everything. splash is read by the splash-screen program, not by the kernel. init=/bin/bash runs a shell instead of the normal init, a last-resort recovery method covered in "Emergency booting and single-user mode". nomodeset stops graphics drivers changing the display mode, useful when a new graphics card gives a black screen. console=ttyS0,115200 sends kernel output to a serial port, common on servers and virtual machines. panic=10 reboots ten seconds after a kernel panic instead of hanging.
Parameters the kernel passes on
The kernel does not reject parameters it does not recognise. One whose name contains a dot, such as usbcore.autosuspend=-1, is treated as a module parameter: module name, dot, parameter. Other unknown parameters go to init: those with = become environment variables, the rest become command-line arguments, and everything after a lone -- is passed to init as arguments. Current kernels log a notice listing unknown parameters that will be passed to user space. systemd reads its own options, such as systemd.unit=rescue.target, straight from /proc/cmdline, and initramfs tools read options beginning rd. the same way.
Worked example: reading /proc/cmdline
A server's /proc/cmdline reads (illustrative): BOOT_IMAGE=/vmlinuz-6.8.0-45-generic root=/dev/mapper/vg0-root ro loglevel=3 usbcore.autosuspend=-1 systemd.unit=multi-user.target. Classify each part. 1. BOOT_IMAGE= was added by GRUB to record the kernel file; the kernel does not use it. 2. root=/dev/mapper/vg0-root: the root filesystem is the logical volume root in volume group vg0. 3. ro: mount root read-only until it has been checked. 4. loglevel=3: the console shows only messages more important than level 3, that is levels 0 to 2. 5. usbcore.autosuspend=-1: a parameter for the usbcore module, here disabling USB autosuspend. 6. systemd.unit=multi-user.target: read by systemd, which boots to a text-mode multi-user state instead of the graphical default.
Worked example: changing a parameter
Task: a machine shows a black screen after boot, and you suspect the graphics driver. 1. Test first, for one boot only: at the boot menu, edit the entry and add nomodeset to the kernel line (the next topic shows how). 2. After booting, confirm it took effect: cat /proc/cmdline should now include nomodeset. 3. If it helps, make it permanent. On Debian or Ubuntu, add it to GRUB_CMDLINE_LINUX_DEFAULT in /etc/default/grub and run update-grub. On Fedora or RHEL, run grubby --update-kernel=ALL --args="nomodeset". 4. Reboot and check /proc/cmdline again. Testing once before saving means a bad parameter costs only one reboot, not a broken boot every time.
Boot-time versus run-time settings
The command line is read once, at boot. Many settings can also be changed while the system runs. Kernel tunables under /proc/sys, such as vm.swappiness, are read and written with sysctl and made permanent with files in /etc/sysctl.d/. Module options can go in /etc/modprobe.d/ as lines like options usbcore autosuspend=-1, applied whenever the module loads, and a loaded module's current values appear under /sys/module/<name>/parameters/. Use the command line for what must be decided before user space exists, such as root=, init= and console=; use sysctl and modprobe.d for the rest.
When parameters go wrong
A wrong root= is the classic failure. The kernel cannot find or mount the root filesystem and stops with a panic message such as VFS: Unable to mount root fs on unknown-block(0,0) (illustrative), or the initramfs waits for a device that never appears and then drops to a shell. Causes include a mistyped UUID, a replaced disk, or a missing storage driver. A bad init= ends in a panic reporting that the requested init failed. A panic halts the system; an oops is a serious kernel error it may survive, and kdump, which reserves memory with crashkernel=, can capture a crash dump. In each case the fix is to edit the parameters for one boot at the boot menu, start the system, then correct the configuration permanently.
Common mistakes to avoid
First, editing /proc/cmdline: it only reports what the kernel received; changes belong in the boot loader configuration. Second, using root=/dev/sdb2 on a machine with several disks, where names can change. Third, making a parameter permanent before testing it for one boot. Fourth, confusing loglevel with journal priorities: loglevel affects the console, not what is stored. Fifth, putting a sysctl tunable on the command line, or a boot-only option in /etc/sysctl.d/. Sixth, forgetting that splash, systemd.* and rd.* options are read by user-space programs, not by the kernel.
Key takeaways
The kernel inspects the CPU and memory, discovers buses and devices, starts subsystems, mounts root and runs init as PID 1; drivers for the root disk often come from the initramfs. The boot loader passes the kernel command line, visible in /proc/cmdline, of flags and key=value pairs. root= names the root filesystem, best by UUID or LV path; ro mounts it read-only for checking. module.param=value sets module options; unknown parameters go to init, and systemd reads systemd.* itself. Test changes for one boot, then make them permanent in the boot loader configuration.
Flashcards
Flashcard
CPU, memory, buses, devices, subsystems, root mount, init
Test your understanding
Question 1 of 5
Where can you see the exact parameters the running kernel was booted with?
Question 2 of 5
Which root= setting stays correct if a new disk changes the order of device names?
Question 3 of 5
The command line contains usbcore.autosuspend=-1. What does the kernel do with it?
Question 4 of 5
Why do many systems boot with the ro parameter?
Question 5 of 5
You want nomodeset on every boot of a Debian system. What should you do after testing it once?
