Linux Startup: Firmware to Desktop
I thought I would next give a shot at writing about the boot process. Ever wondered what the various steps are that take a computer from powered down to full graphical user interaces?
Well the typical order goes something like
Firmware -> Boot loader -> Kernel -> initramfs -> Root Filesystem -> init -> Login/session management -> Desktop
So the first piece of this process is firmware. Firmware is embedded in the computer, and in most circumstances is invisible to an average user. Implementations vary, but its main responsibility is to handle the power on signal and start the bootloader.
Bootloaders are an interesting area of programming and come in many shapes and sizes. For desktop linux, the most common options are things like grub, which gives you a nice menu to choose your kernel and other launch options. Like many other bootloaders grub is installed into an area of memory accessible to most firmware. Grub has to know where the kernel and everything is, so it also keeps a configuration you can manage through grubmkconfig If you like project boards, you'll probably end up more familiar with uBoot which is a less resource intensive loader used in embedded. The bootloader is responsible for finding the Kernel and loading it into memory, along with passing in any needed arguments. This means it has storage drivers and is often reading info out of your /boot folder.
Now we get to the Linux kernel, the heart of our operating system. The kernel is responsible for setting up the root filesystem and creating the framework to run your userspace. The kernel also creates many volatile file structures that don't persist across boots. /proc /sys and /dev being some of the major ones. The kernel is composed of a variety of modules that can be loaded and unloaded for managing different systems and hardware. You can see what is being used on your system with the lsmod command. modprobe and insmod can be used to change some of the configurations currently loaded.
On desktop the most common setup is to use initramfs to begin the next step. That is a shortening of init RAM filesystem. This is a compressed file system that contains utilities for probing hardware and discovering hardware layout that are too complex to handle without specialized programs like RAID filesystems. Initrsmfs is common, but also not entirely necessary. If the kernel can find and understand the root filesystem it can mount it on its own. Even more complex systems can be launched without initramfs, typically through the use of a flattened device tree specifying much of the physical layout of the electronics and the settings needed to bring them up safely on a System on Chip.
Once it is prepared, the kernel or initramfs accesses the root file system and launches init. This program is a part of systemd on most systems, and it follows a tree of dependencies to choose what to start on your system and when. It is responsible for determining when a program is ready and its dependencies are available.
Next up is login/session management. Here is where I will do my best, because I am less certain of some of the terms here. Linux logins are generally shell based. A shell is a program that acts as an interpreter for commands for the kernel. Shells can be interactive or not, and will use different configurations for each. Getty is the classic program for starting shells, and stands for "Get TTY" Once a shell is started it will ask for authentication if it is a login shell, and then run through the commands in .profile to setup variables. Most users won't see this unless they open a terminal, instead entering their authentication into a graphical login like LightDM (Light display manager). That display manager will then start your graphical session!
A graphical session is similar to a login on Windows. When you select a user and enter a password on Windows you are starting "explorer.exe" under your user. On Linux on many new systems this is Wayland, with a compositor like Sway. KDE Plasma uses one called KWin instead, but they have similar responsibilities. On older systems the display is managed by XOrg, with different desktop environments and compositors on top of that. The display manager starts a "session" of your desktop environment, which then sets up your UI and hotkeys. Some desktop environments restore programs opened during your last session, but not all are as feature-full. The variety of desktop experiences offered in Linux is enormous and ranges from desktops similar to Windows with things like Cinnamon, to tiling managers like DWM, and bare bones options like Openbox.
From there you are in your graphical session, and are ready to use your computer! Learning which tools your PC uses can help you figure out where you want to tweak it for different tasks. For many daemons or system services, systemd is the right place to configure. For user programs you can use systemd with userctrl, or your desktop environment. Enjoy tweaking your configuration :)
EDIT: Mint -> Cinnamon, Mint is the distro, cinnamon is the DE
No replies yet