From 1d0689f177487bbd9b2576d62fb848935216e5a7 Mon Sep 17 00:00:00 2001 From: jgrogan Date: Sat, 4 Jan 2025 19:08:46 +0000 Subject: [PATCH] Add some linux notes --- src/articles/computer_networking.md | 59 ++++++++ src/articles/linux_internals.md | 210 ++++++++++++++++++++++++++++ 2 files changed, 269 insertions(+) create mode 100644 src/articles/computer_networking.md create mode 100644 src/articles/linux_internals.md diff --git a/src/articles/computer_networking.md b/src/articles/computer_networking.md new file mode 100644 index 0000000..e4c517d --- /dev/null +++ b/src/articles/computer_networking.md @@ -0,0 +1,59 @@ +This is a work in progress article I'm using to build up my understanding of computer networking. + + +# Standards # + +## [OSI model](https://en.wikipedia.org/wiki/OSI_model) ## + +The Open Systems Interconnection model is a basis for standards development in systems interconnection. + +### Physical Layer ### + +Converts digital bits into electrical, radio or optical signals + +* NIC: Network Interface Controller +* Ethernet hub +* Network switch +* Physical transmission media + +Standards at this layer include Bluetooth, Ethernet, USB + +### Data link layer ### + +* Medium Access Control Address (MAC) https://en.wikipedia.org/wiki/MAC_address +* Logical link control (LLC) + +### Others ### + +* network +* transport +* session +* presentation +* application + + +## [IEEE 802](https://en.wikipedia.org/wiki/IEEE_802) ## + +Family of standards for local area networks (LANs) and other types. + +# Terms # + + + +# Internet Protocol Suite # + +* RFC 1122 +* RFC 1123 + + +## Link Layer ## + +* Address Resolution Procotol (ARP) https://en.wikipedia.org/wiki/Address_Resolution_Protocol + + +## Transport Layer ## + +* TCP +* UDP +* QUIC + diff --git a/src/articles/linux_internals.md b/src/articles/linux_internals.md new file mode 100644 index 0000000..a84353b --- /dev/null +++ b/src/articles/linux_internals.md @@ -0,0 +1,210 @@ +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](https://www.kernel.org/doc/html/v4.13/index.html) 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: + +* graphics +* audio +* memory +* cpu +* gpu +* network +* keyboard and mouse +* storage and i/o peripherals + +with the kernel handling control messages including power messages for associated devices. + +As part of its resource management the kernel includes: + +* filesystems and virtual file management +* memory management functionality +* process scheduling and interprocess communication +* networking +* security +* media support + +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: + +* an init system - often `systemd` and previously collections of 'sysvinit scripts' or niche alternatives like `shepherd`. +* system daemons for administrative services +* a graphics system - oten `wayland` now replacing `x org` +* an audo or multimedia system - `pipewire` is becoming a common replacement for `pulseaudio` and others +* a terminal emulator and shell +* network interface management, such as ethernet or wifi +* a package manager +* a bootloader + + +# APIs # + +https://en.wikipedia.org/wiki/Linux_kernel_interfaces#Linux_API + +The kernel tries to follow the [Portable Operating System Interface (POSIX)](https://en.wikipedia.org/wiki/POSIX) and [Single Unix Specification](https://en.wikipedia.org/wiki/Single_UNIX_Specification) where applicable. + +## File Based ## + +Device drivers are interacted with in directories: + +* `/dev` https://en.wikipedia.org/wiki/Device_file#DEVFS +* `/sys` + +Processes are interacted with in: + +* `/proc` +* `/proc/sys` + +## System calls and similar ## + +https://en.wikipedia.org/wiki/System_call + +`ioctl` (input/output control) is a system call for device specific io operations. + +* `sysctl` (system control) +* `ioctl` (io control) +* `fcntl` (file control) + +Other communication mechanisms include [netlink](https://en.wikipedia.org/wiki/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: + +* `systemctl` +* `journalctl` +* `notify` +* `loginctl` +* `systemd-boot` + +Important daemons: + +* `systemd` +* `journald` +* `resolved` +* `networkd` +* `logind` +* `user-session` +* `udevd` + +Important libraries: + +* `libnotify` +* `libudev` + + + + + +## Devices ## + +Devices are managed in user space with the `udev` utility - which has the following parts: + +* libudev which can be used as a library for device info +* udevd daemon for managing the `/dev` virtual file hierarchy +* the `udevadm` command line utility for admin and diagnostics + + +## 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 ruls in the Linux kernel firewal, which are implemented as netfiler modules. + +[avahi](https://en.wikipedia.org/wiki/Avahi_(software)) 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). + +## Other ## + +* avahi +* dbus +* udisks +* cgroups +* autofs +* kdbus +* Plokit (Policy Kit) https://en.wikipedia.org/wiki/Polkit +* Pluggable Authentication Module (PAM) https://en.wikipedia.org/wiki/Pluggable_Authentication_Module +* Name Service Switch (NSS) https://en.wikipedia.org/wiki/Name_Service_Switch +* procfs https://en.wikipedia.org/wiki/Procfs +* sysfs https://en.wikipedia.org/wiki/Sysfs + +# Kernel Space # + + +## Input events ## + +* evdev +* `/dev/input` + +## Filesystems ## + +* ext4 +* btrfs +* xfs +* jfs +* fat32 + +* FUSE + +## Storage ## + +* SCSI +* libATA + +## Virtualization ## + +* KVM +* Xen + +## Process Management ## + +* `clone(2)` and `clone3(2)` +* `futex(7)` and `futex(2)` +* Completely Fair Scheduler +* https://en.wikipedia.org/wiki/Earliest_eligible_virtual_deadline_first_scheduling +* Native Posix Thread Library (NPTL) is kernel side of pthreads + +## Security ## + +* Linux Security Modules +* SELinux +* AppArmor +* POSIX ACLs + +## Memory ## + +* DMA buffers + +## Audio ## + +* Advanced Linux Sound Architecture (ALSA) + + +## Graphics ## + +* Direct Rendering Manager (DRM) +* Kernel Mode Setting (KMS) + + +## Network ## + +* New API +* mac80211 +* [Netfiler](https://en.wikipedia.org/wiki/Netfilter) + + +## Power and Control ## + +* ACPI https://en.wikipedia.org/wiki/ACPI + +