Linux Boot Process

The boot process with the system's firmware initializes the hardware and loads the bootloader. 🧳

The bootloader will load the Linux Kernel. It's the menu we have to select which OS we are booting on. πŸͺ§

The kernel will initialize some hardware components, mount the filesystem and delegate the initialization process which will start processes and services until the system becomes fully operational. πŸ—ƒοΈ

The initialization process is commonly handled by systemd daemon, which is a modern replacement for the traditional init system. This daemon process is the parent of every process and has the PID 1. πŸͺ΄

Some of the well-known ones are:

  • System firmware 🧳: BIOS or UEFI
  • Bootloaders πŸͺ§: GRUB or U-Boot
  • Initialization πŸͺ΄: systemd or launchd

Systemd

Systemd is a system and service manager for Linux operating systems. It is responsible for starting, stopping, and managing system services.

$ ls -la /etc/systemd/system/   # target + enabled services
$ ls -la /lib/systemd/system/   # services

systemctl command

The systemctl allows us to interact with the systemd daemon. Note that you can create all files manually without the systemctl command.

$ systemctl list-units --type=service # list all services
$ systemctl show xxx      # show information, use -p to filter
$ systemctl status xxx    # status of the service
$ systemctl start xxx     # start a service
$ systemctl reload xxx    # reload the configuration
$ systemctl daemon-reload # reload systemd configuration
$ systemctl restart xxx   # stop+start a service
$ systemctl stop xxx      # stop a service
$ systemctl enable xxx    # enable a service at boot
$ systemctl enable --now xxx # enable it now
$ systemctl disable xxx   # disable a service at boot
$ systemctl link xxx      # create a link in systemd files

➑️ You can use -f to force an operation.


journalctl command

We can use journalctl to access the system logs.

$ journalctl            # all logs
$ journalctl -b         # since last boot
$ journalctl -f         # real-time
$ journalctl -u xxx     # for a specific service

Systemd Targets

Systemd has a concept of targets to group services. The goal of the initialization often is to reach the multi-user.target which means the user can interact with the system and most services are active.

$ ls /lib/systemd/system/*.target
$ cat my_target.target
[Unit]
Description=Some Description
Requires=multi-user.target
Conflicts=rescue.service rescue.target
After=multi-user.target rescue.service rescue.target
AllowIsolate=yes

➑️ See also: How to create a systemd target?


Systemd service

Services support a lot of options, especially when we need to define dependencies between services or targets.

$ ls /lib/systemd/system/*.service
$ cat my_service.service
[Service]
Type=oneshot
ExecStart=/bin/echo "Hello, World!"

[Install]
WantedBy=my_target.target

➑️ See also: WorkingDirectory, Restart, RestartSec, StandardOutput, StandardError, SyslogIdentifier, Environment, User, etc.


Grub

oh_my_grub

GRUB (GRand Unified Bootloader) is a widely used bootloader on Linux. It allow users to select which operating system or kernel to boot. It automatically boots using the first one after 5 seconds.

πŸ“š It worth noting that a file system is just a file. If we have access to an image such as a .vmdk, we can read its content without booting it.

If the GRUB configuration is not password protected and insecurely configured, we may be able to edit it during boot ⚠️.

  • Press Esc to cancel the automatic selection
  • Press E to edit GRUB configuration
  • Look for a line linux [...]
  • Edit it to your liking

You may remove quiet and add init=/bin/bash to start the system with a bash as root with no password.

  • Press CTRL+X or F10

πŸ‘» To-do πŸ‘»

Stuff that I found, but never read/used yet.

  • Systemd Timers: using systemd for task scheduling. xxx.timer files.