notes

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit 10c911eb1884a775642705f423ef6a4b4ecaa598
parent c0815b9be09d0cab30ac4a1798e78c82f1fa2440
Author: Andrew Laack <andrew@laack.co>
Date:   Sun,  8 Mar 2026 22:34:35 -0500

Linux notes

Diffstat:
Mdocs/ComputerScience.md | 2+-
Ddocs/FreeSoftware.md | 17-----------------
Adocs/Initramfs.md | 7+++++++
Adocs/Interrupt.md | 13+++++++++++++
Mdocs/Linux.md | 4++++
Ddocs/LinuxStuff.md | 19-------------------
Mdocs/Mutex.md | 6++++++
Mdocs/OperatingSystems.md | 3++-
Adocs/QEMU.md | 33+++++++++++++++++++++++++++++++++
Adocs/Signal.md | 33+++++++++++++++++++++++++++++++++
Adocs/Software.md | 48++++++++++++++++++++++++++++++++++++++++++++++++
Adocs/Systemd.md | 39+++++++++++++++++++++++++++++++++++++++
12 files changed, 186 insertions(+), 38 deletions(-)

diff --git a/docs/ComputerScience.md b/docs/ComputerScience.md @@ -25,7 +25,7 @@ This is the index for my Computer Science related notes. - [Developer Tooling](DeveloperTooling.md) - [Software Licenses](SoftwareLicenses.md) - [Haskell](Haskell.md) -- [Free Software](FreeSoftware.md) +- [Software](Software.md) - [Code Verification](CodeVerification.md) - [Beam Search](BeamSearch.md) diff --git a/docs/FreeSoftware.md b/docs/FreeSoftware.md @@ -1,17 +0,0 @@ -# Free Software - -## Distribution Approaches - -- [Flatpak](Flatpak.md) -- [Homebrew](Homebrew.md) - -## Note Taking - -### Graphical - -- Emacs -- [QOwnNotes](QOwnNotes.md) - -### Terminal - -- VIM / VI diff --git a/docs/Initramfs.md b/docs/Initramfs.md @@ -0,0 +1,7 @@ +# initramfs + +**Source:** [https://wiki.archlinux.org/title/Arch_boot_process#initramfs](https://wiki.archlinux.org/title/Arch_boot_process#initramfs) + +**Definition:** initramfs (initial RAM file system) is an image that provides necessary files for early userspace to start late userspace. + +initramfs is unpacked by the kernel into `/` at startup as a temporary root file system. diff --git a/docs/Interrupt.md b/docs/Interrupt.md @@ -0,0 +1,13 @@ +# Interrupt + +**Source:** CS 6200 + +**Chapter:** P2L4 + +**Definition:** An interrupt is an event generated by an external component from the CPU (e.g. I/O devices, timers, other CPUs). These events are generated asynchronously. + +Interrupts can be masked on the basis of a given CPU to suspend or disable the corresponding notification. This masking is done by a string of bits, one bit per interrupt. + +## Handling + +When an interrupt is received by the CPU, the CPU looks up the correct handler for the given interrupt using the interrupt handler table, based on the interrupt number for of the device (this is often sent over PCIE to the CPU). The CPU then places the PC at the starting address of the handler associated with the current interrupt. This all happens within the same thread context. diff --git a/docs/Linux.md b/docs/Linux.md @@ -33,3 +33,7 @@ The kernel is made up of the following components: - Signal handling, process / thread creation, scheduler This differs from the MacOS X architecture because MacOS X has a [Microkernel](Microkernel.md) called Mach, and then implements a BSD CLI interface for BSD compatability and POSIX API support. This BSD CLI interface is what user processes interface with. + +## Startup + +See [initramfs](Initramfs.md) diff --git a/docs/LinuxStuff.md b/docs/LinuxStuff.md @@ -1,19 +0,0 @@ -# Linux Stuff - -These are links to linux stuff that I want to remember, but sometimes forget. Consider, I am starting this on 24/04/16 so I will not include any basic things as I already know them well. - - -# Utilities - -- [rsync](rsync.md) -- [Git](Git.md) - -# File Systems - -- [BTRFS](BTRFS.md) -- [ZFS](ZFS.md) -- [Ext4](Ext4.md) - -# Storage Concepts - -- [RAID](RAID.md) diff --git a/docs/Mutex.md b/docs/Mutex.md @@ -13,3 +13,9 @@ Operating Systems and threading libraries support mutexes, which work as a lock. A common data structure to represent mutexes is locked (boolean), the owner, and blocked threads (not necessarily ordered). When a thread tries to acquire a lock it will be blocked until the lock is released by the owner. Additionally, a thread must unlock the lock after exiting the critical section otherwise all waiting threads will be blocked indefinitely. The code section protected by the lock is called the **critical section**. This code should correspond to code can only safely be executed by one thread at a time. + +## Adaptive Mutexes + +On multi-core systems (and only on multi-core systems), it can sometimes makes sense to spin instead of blocking when trying to acquire a mutex. This is because the cost of context switching and adding a thread to a mutex queue can sometimes be greater than burning a few cycles spinning. + +This motivates adaptive mutexes, which adapt the blocking / spinning behavior contextually, based on what is expected to be most efficient. diff --git a/docs/OperatingSystems.md b/docs/OperatingSystems.md @@ -25,7 +25,6 @@ - [OS Mechanisms](OSMechanisms.md) - Operate on abstractions - [OS Policies](OSPolicies.md) - - [Kernel Mode](KernelMode.md) - [Trap Instruction](TrapInstruction.md) - [System Call](SystemCall.md) @@ -52,3 +51,5 @@ - [ConditionVariables](ConditionVariables.md) - [Pthread](Pthread.md) - [POSIX](POSIX.md) +- [Interrupt](Interrupt.md) +- [Signal](Signal.md) diff --git a/docs/QEMU.md b/docs/QEMU.md @@ -0,0 +1,33 @@ +# QEMU + +## Usage + +### Create disk-image + +Create a disk image: + +`qemu-img create -f qcow2 debian.qcow 20G` + +Boot with: + +`qemu-system-x86_64 -hda debian.qcow -cdrom {ISO_PATH} -boot d -m 4096` + +### Run disk image + +Running a qemu disk image: + +`qemu-system-x86_64 {image}` + +Specify host CPU model, 4 cores, 4G ram: + +`qemu-system-x86_64 debian.qcow -cpu host -enable-kvm -smp 4 -m 4G` + +NOTE: Get your mouse out with ctrl+alt+g. Apparently this is only for the GTK version, the other uses ctrl+alt on the left side for both. + +### SSH Access + +By default, the VM can SSH **out** to any host on the local network (by private IP), but you can't SSH into the VM. + +### Backups + +Just copy the disk image. diff --git a/docs/Signal.md b/docs/Signal.md @@ -0,0 +1,33 @@ +# Signal + +**Source:** CS 6200 + +**Chapter:** P2L4 + +**Definition:** A signal is an event triggered by a process or a CPU. Signals are dictated by the OS. + +Signals can be masked on the basis of a given process to disable / suspend the signal's notification. This can be useful in specific contexts to solve potential deadlock situations where the handler would try to acquire a mutex that has been locked but not yet unlocked by the current thread. Signals that arrive while masked are set as pending and will result in the handler being invoked once they are unmasked. + +This masking is done by a string of bits, one bit per signal (0 is masked, 1 is unmasked). + +## Signal Types + +### (Standard) One-Shot Signals + +In the case of one-shot signals, sending multiple signals of this type while being masked will result in only one invocation of the appropriate handler once they are unmasked + +### Real-Time Signals + +In the case of real time signals, sending multiple signals of this type while being masked will result in an equal number of invocations of the appropriate handler once they are unmasked. + +## Signal Handling + +If a process tries to access illegal memory, it will be sent the sigsegv signal from the OS. The OS maintains the signal handler table for each process, so once this signal is sent, it will lookup the handler's memory address and set the PC to that address for execution. + +The OS specifies some default actions for different signals. Some defaults could be termination / ignoring the signal. + +For most, but not all, signals a process can define its own signal handlers. + +## Deadlock Resolution + +Mentioned above, signals (and interrupts) can result in deadlocks when their handlers require a mutex that has already been locked by the thread it is executing on. This can be resolved by masking the signal in the critical section, or by not using the same mutexes in threads and handlers, but another way, implemented by SunOS, is to allow signals / interrupts to become their own threads when they are executing blocking operations (dynamic determination). diff --git a/docs/Software.md b/docs/Software.md @@ -0,0 +1,48 @@ +# Software + +Software and software related concepts. Focused on free software and primitives. + +## Distribution Approaches + +- [Flatpak](Flatpak.md) +- [Homebrew](Homebrew.md) + +## Note Taking + +### Graphical + +- Emacs +- [QOwnNotes](QOwnNotes.md) + +### Terminal + +- VIM / VI + +## Isolation + +- Virtualization + - [QEMU](QEMU.md) +- Containerization + - Podman + - Docker + - Cgroups + - Namespaces + +## Utilities + +- [rsync](rsync.md) +- [Git](Git.md) +- [systemd](Systemd.md) +- cpio + +## Data Storage + +### File Systems + +- [BTRFS](BTRFS.md) +- [ZFS](ZFS.md) +- [Ext4](Ext4.md) + +### Storage Concepts + +- [RAID](RAID.md) diff --git a/docs/Systemd.md b/docs/Systemd.md @@ -0,0 +1,39 @@ +# systemd + +**Source:** [https://wiki.archlinux.org/title/Systemd](https://wiki.archlinux.org/title/Systemd) + +**Definition:** Systemd is a suite of services used for managing services on select Linux-based operating systems. + +## Terms + +**Units:** .service, .mount, .device, .socket, etc. files + +## Details + +`systemsctl` has an implied `--system`, meaning you are acting upon system level units by default. Additionally, specifying something like `systemctl status sshd` is referring to the `sshd.service`. Explicitly, this is `systemctl --system status sshd.service`. + +## Defining Units + +systemd unit file syntax is inspired by XDG desktop entry specifications for .desktop files. + +## Examples + +1. `systemctl` + +Lists all running units. + +2. `systemctl --failed` + +Lists all failed units. + +3. `systemctl list-unit-files` + +List all installed unit files along with presets and states. + +4. `systemctl mask unit` + +Mask a unit to stop it from starting. + +5. `systemctl soft-reboot` + +Performs a soft-reboot, restarting the user space without going through [initramfs](Initramfs.md), keeping decrypted block devices decrypted.