5.2 Kernel Initialization and Boot Options
Upon startup, the Linux kernel initializes in this general order:
- CPU inspection
- Memory inspection
- Device bus discovery
- Device discovery
- Auxiliary kernel subsystem setup (networking and the like)
- Root filesystem mount
- User space start
The first two steps aren’t too remarkable, but when the kernel gets to devices, the question of dependencies arises. For example, the disk device drivers may depend on bus support and SCSI subsystem support, as you saw in Chapter 3. Then, later in the initialization process, the kernel must mount a root filesystem before starting init. In general, you won’t have to worry about the dependencies, except that some necessary components may be loadable kernel modules rather than part of the main kernel. Some machines may need to load these kernel modules before the true root filesystem is mounted. We’ll cover this problem and its initial RAM filesystem (initrd) workaround solutions in Section 6.7.
The kernel emits certain kinds of messages indicating that it’s getting ready to start its first user process:
Freeing unused kernel memory: 2408K
Write protecting the kernel read-only data: 20480k
Freeing unused kernel memory: 2008K
Freeing unused kernel memory: 1892K
Here, not only is the kernel cleaning up some unused memory, but it’s also protecting its own data. Then, if you’re running a new enough kernel, you’ll see the kernel start the first user-space process as init:
Run /init as init process
with arguments:
--snip--
Later on, you should be able to see the root filesystem being mounted and systemd starting up, sending a few messages of its own to the kernel log:
EXT4-fs (sda1): mounted filesystem with ordered data mode. Opts: (null)
systemd[1]: systemd 237 running in system mode. (+PAM +AUDIT +SELINUX +IMA
+APPARMOR +SMACK +SYSVINIT +UTMP +LIBCRYPTSETUP +GCRYPT +GNUTLS +ACL +XZ +LZ4
+SECCOMP +BLKID +ELFUTILS +KMOD -IDN2 +IDN -PCRE2 default-hierarchy=hybrid)
systemd[1]: Detected architecture x86-64.
systemd[1]: Set hostname to <duplex>.
At this point, you definitely know that user space has started.