Linux › Section E · How the Linux kernel boots › Topic E.1
Startup messages
Every boot leaves a detailed record of what the kernel found and did, even when a splash screen hides it. Reading that record is the first step in diagnosing hardware problems, missing disks and slow or failed boots.
The boot in outline
A Linux boot is a relay. The firmware (BIOS or UEFI) starts a boot loader; the boot loader loads the kernel into memory and starts it with a set of parameters; the kernel detects hardware, loads drivers and mounts the root filesystem; then it starts the first user-space process, init, with process ID 1, which on most current distributions is systemd. init starts services and finally a login prompt. This section follows the kernel's part of the relay. The topic "Introduction to init" picks up from PID 1. Knowing which stage you are in tells you where to look when a boot goes wrong.
Why you rarely see the messages
Older systems scrolled pages of text during boot. Today the kernel starts so quickly, and most distributions add quiet to its parameters and show a graphical splash screen (usually Plymouth), so you see a logo instead. The messages are still produced and kept. On many systems pressing Esc during the splash switches to the text view, and removing quiet and splash from the kernel parameters for one boot shows everything; the next topics explain how to change parameters. For most diagnosis, though, the easiest method is to let the machine finish booting, log in and read the stored messages.
The kernel ring buffer and dmesg
The kernel writes its messages into a ring buffer in memory: a fixed-size store in which the newest messages eventually overwrite the oldest. dmesg prints the buffer. Useful options are -H for readable, paged output, -T for wall-clock times instead of seconds since boot (which can be inaccurate after a suspend and resume), -l err,warn to show only chosen levels and -w to follow new messages as they arrive. On many distributions an ordinary user gets a permission error, because the kernel setting dmesg_restrict limits the buffer to administrators, so use sudo dmesg. Because the buffer is finite, messages from very early in a long-running system may already be gone.
The journal: journalctl -k
On systemd systems the journal stores kernel messages alongside everything else. journalctl -k shows kernel messages from the current boot. journalctl -k -b -1 shows the previous boot, -b -2 the one before, and journalctl --list-boots lists the boots the journal holds with their numbers and time ranges. Older boots are available only if the journal is kept on disk in /var/log/journal; with volatile storage under /run it is lost at shutdown. Add -p err to show only messages of priority err and more severe. Systems that also run rsyslog may copy kernel messages to a text file, such as /var/log/kern.log on Debian-family systems; the topic "System logging: the journal and syslog" covers both.
Reading a kernel message line
In dmesg output each line begins with a timestamp in square brackets, the seconds since the kernel started, such as [ 2.481003]. Next usually comes the subsystem or driver that wrote it, then the message. Some typical prefixes: sd 0:0:0:0: is the SCSI disk driver talking about the device at that SCSI address; EXT4-fs (nvme0n1p2): is the ext4 code reporting on one filesystem; usb 1-2: is the USB core describing a port; and systemd[1]: is PID 1 writing into the kernel log. Messages also carry a priority level, which dmesg -x shows as a prefix and journalctl uses for colour and filtering.
Milestones in a normal boot
The order of a kernel log is predictable, though every line varies between machines. Early on comes a Linux version banner naming the kernel release and the compiler that built it, followed on x86 by a Command line: line repeating the parameters the boot loader passed. Then come the firmware memory map, CPU and memory details, buses such as PCI, and the storage, USB and network drivers with the devices they find. Disks report their size, and a line such as sda: sda1 sda2 lists the partitions the kernel read. Near the end, the kernel frees memory used only during start-up, reports Run /init as init process (or /sbin/init), and the initramfs mounts the real root filesystem and hands over to systemd.
Worked example: a disk in the log
A new disk is plugged in and the log shows (illustrative): sd 2:0:0:0: [sdb] 1953525168 512-byte logical blocks: (1.00 TB/932 GiB), then sdb: sdb1. 1. The device name the kernel assigned is sdb, at SCSI address 2:0:0:0. 2. Size in bytes: \(1{,}953{,}525{,}168 \times 512 = 1{,}000{,}204{,}886{,}016\). 3. In decimal units that is about 1.00 TB, the figure on the box. 4. In binary units, \(1{,}000{,}204{,}886{,}016 \div 2^{30} \approx 931.5\), shown rounded as 932 GiB. 5. The line sdb: sdb1 means the kernel read a partition table with one partition. If a disk you expected never appears at all, the problem lies below the filesystem: cable, power, firmware or driver.
Worked example: what failed last time?
A server rebooted unexpectedly overnight, and its journal is stored on disk. 1. Run journalctl --list-boots; the entry numbered -1 is the boot that ended overnight. 2. Run journalctl -k -b -1 -p err to see only serious kernel messages from that boot. 3. Suppose it shows (illustrative) EXT4-fs error (device sdb1): ext4_find_entry: reading directory lblock 0. The filesystem on sdb1 hit a read error. 4. Next steps: check the disk's health, unmount the filesystem and check it with e2fsck, as in "Filesystem types, creating, and checking filesystems". 5. If the list shows only boot 0, the journal is volatile; create /var/log/journal or set Storage=persistent in journald.conf so the next incident leaves evidence.
After the kernel: user-space messages
Once systemd starts, services produce their own start-up messages. Traditional init scripts printed them to the console, where they vanished after boot. systemd instead captures the output of every unit in the journal, so journalctl -b shows the whole boot, kernel and services together, and journalctl -b -u ssh.service narrows it to one unit (the service is called sshd.service on Fedora and RHEL). To see where boot time went, systemd-analyze prints the time spent in kernel and user space (plus firmware and boot loader where the loader reports them), and systemd-analyze blame lists units by how long they took to start.
Common mistakes to avoid
First, concluding nothing was logged because the boot showed only a logo: the messages are in dmesg and the journal. Second, expecting journalctl -b -1 to work on a system with a volatile journal. Third, treating dmesg timestamps as clock times: by default they are seconds since boot, and -T times can drift after suspend. Fourth, reading one alarming line out of context; many drivers print harmless warnings, so compare with a healthy machine. Fifth, mixing up disk sizes: the kernel prints both TB and GiB, and they differ by about 7%.
Key takeaways
Booting runs firmware, boot loader, kernel, then init (PID 1). quiet and a splash screen hide boot text, but it is kept. dmesg reads the kernel ring buffer (-H, -T, -l, -w; often needs sudo); journalctl -k shows kernel messages for this boot, -b -1 for the previous one if the journal is persistent, and --list-boots lists boots. Lines start with seconds since boot and a subsystem prefix. Key milestones: the Linux version banner, the command line, device and partition detection, Run /init as init process and the root mount. journalctl -b and systemd-analyze cover the user-space part.
Flashcards
Flashcard
Firmware, boot loader, kernel, init (PID 1), services, login
Test your understanding
Question 1 of 5
Which command shows the kernel messages from the boot before the current one?
Question 2 of 5
journalctl --list-boots shows only one entry, boot 0, on a machine that has rebooted many times. Why?
Question 3 of 5
A log line says a disk has 3907029168 512-byte logical blocks. About how large is it?
Question 4 of 5
In dmesg output, what does the number in [ 12.734210] at the start of a line mean by default?
Question 5 of 5
A desktop shows only a logo while booting. How can you best read what the kernel reported?
