Linux Internals

This article is my attempt to explain Linux internals to myself and act as a structured way of keeping notes.

Linux is an operating system kernel - which is distinct from the user-space where user applications will run. The kernel directly interfaces with hardware via its firmware and associated drivers. It also manages resources for sharing by user applications. Other open-source kernels that may be of interest are those based on BSD and the GNU Hurd microkernel.

The Linux kernel can be interacted with or controlled from user space by means of a File based API or a C API which aim to be POSIX compatible.

The types of hardware interfaced in the kernel include:

with the kernel handling control messages including power messages for associated devices.

As part of its resource management the kernel includes:

In the user-space of operating systems that use the Linux kernel (will controversially refer to as Linux distros for brevity) some foundational elements and applications are:

APIs

https://en.wikipedia.org/wiki/Linux_kernel_interfaces#Linux_API

The kernel tries to follow the Portable Operating System Interface (POSIX) and Single Unix Specification where applicable.

File Based

Device drivers are interacted with in directories:

Processes are interacted with in:

System calls and similar

https://en.wikipedia.org/wiki/System_call

ioctl (input/output control) is a system call for device specific io operations.

Other communication mechanisms include netlink sockets which allow IPC between both kernel and userspace programs. It is designed to be a more flexible successor to ioctl.

User Space

Init Systems

Systemd

Important utilities:

Important daemons:

Important libraries:

Devices

Devices are managed in user space with the udev utility - which has the following parts:

Window management and device input events

Wayland and X are the two most common display servers on Linux systems. They both follow a client-server approach, where the latter in Wayland can be part of the compositor.

Display servers can react to device input events via the libinput library, which in turn uses libevdev to handle evdev ioctls from the kernel.

Network

iptables allows configuration of IP packet filter rules in the Linux kernel firewall, which are implemented as netfilter modules. nftables is a newer userspace utility that replaces iptables and similar.

netfilter operates by providing hooks to be called at different stages of packet processing, allowing decisions to be made on the fate of the packet. The user-space side of iptables has the concept of 'tables' - which define some function to perform on a packet and 'chains' which correspond to when the functions will be applied, mapping to the netfiler hooks. Chains has a priority controlling their order of application on the netfilter hooks.

The following are the netfilter hooks and corresponding built-in iptable chains:

The following are the available iptable tables:

iptable rules are placed in a specific chain of a specific table. Rules have a 'matching' component and a 'target' component, which gives an action. The actions can be terminating which stops chain evaluation or non-terminating.

avahi is a zero-configuration networking implementation (allows network service use by freshly networked computers or peripherals) including multicast DNS and DNS service discovery. Apples' Bonjour and Systemd's systemd-resolved are other implementations.

The Desktop-Bus (DBus) is a user space middleware allowing communication between multiple processes (e.g. IPC).

Audio

ALSA (Advanced Linux Sounds Architecture) - has both kernel and user-space elements, the later with alsa-lib.

Pipewire is a new low-level multimedia framework.

Power Managemenr

UPower (previously DeviceKit-power) is a power manement middleware - it spawns upowerd.

Systemd has some session and power management through its logind. The elogind is a standalone fork of this logind.

The systemctl suspend analogue for elogind is loginctl suspend.

Other

Kernel Space

Input events

Filesystems

Storage

Virtualization

Process Management

Security

Memory

Audio

Graphics

Network

Power and Control

PAM and Login