Linux

  • https://linuxcommand.org/tlcl.php
  • https://commandlinux.com/statistics/linux-kernel-contributors-lines-of-code-statistics/
  • Today: powers ~96% of web servers, 100% of top 500 supercomputers, and ~70% of all smartphones (via Android)
  • ~40 millions of lines of code (2025)
  • magic bytes and superblock
  • Physical block, sectors
  • partitions, mounting, volumes, fdisklsblkpartedmount
  • process structure PCB/Address space
    • machports as thread id, windows has dedicated thread id, linux has lightweight process as thread id
    • multi-processing, multithreading, multi-tasking OS, preemptive?
  • How OS starts up and is there anything missing in processes?
    • systemd?
  • Rings of kernel?
    • dmesg command
  • How PTY and TTY are connected
  • regex

History of Linux

YearEvent
1969Unix created at AT&T Bell Labs by Ken Thompson, Dennis Ritchie, and others.
Written in assembly, later rewritten in C
1983GNU Project launched by Richard Stallman to build a free Unix-like OS.
Produced core tools (gcc, bash, glibc) but lacked a kernel
1987MINIX - a small Unix-like OS, released by Andrew Tanenbaum for educational use.
Inspired Linus Torvalds
1991Linux kernel announced by Linus Torvalds (21-year-old Finnish student) on Aug 25
1992Linux kernel relicensed under GPL v2. Combined with GNU tools, forming the first usable GNU/Linux system
1993Slackware and Debian - among the first Linux distributions released
1994Linux kernel 1.0 released (March 14). ~176,000 lines of code
1998Major companies (IBM, Oracle, Intel) announce Linux support
2000IBM invests $1 billion in Linux - signals enterprise legitimacy
2003RHEL (Red Hat Enterprise Linux) launched, creating a commercial model around Linux
2004Ubuntu released by Canonical - made Linux significantly more accessible for desktop use
2005Git created by Linus Torvalds to manage Linux kernel source after a licensing dispute with BitKeeper
2007Android launched (based on the Linux kernel), later becoming the world’s most-used OS
2015systemd becomes the default init system across most major distros
2019Microsoft ships WSL 2 (Windows Subsystem for Linux) with a real Linux kernel inside Windows
2020Linux kernel 5.x - widespread support for modern hardware and improved security
2024Kernel 6.x series; Rust programming language officially added as a second language for kernel development

Key People

  • Linus Torvalds — created the Linux kernel (1991), continues as its principal maintainer
  • Richard Stallman (RMS) — founded GNU Project; created GPL license; GNU tools form the userland
  • Ken Thompson & Dennis Ritchie — created Unix and C at Bell Labs, the foundational inspiration
  • Andrew Tanenbaum — created MINIX; his academic OS directly inspired Torvalds

Linux OS layers

  • The Kernel (Kernel space)
    • It manages memory allocation, CPU time, process scheduling, and device drivers
  • The Userland Utilities (User space)
    • Historically these tools were provided by GNU, but alternatives exist for each layer
    • C Library (libc): bridge between user programs and the kernel via system calls
      • glibc (GNU C Library) - standard on most distros
      • Alternatives: musl (Alpine Linux; lightweight), Bionic (Android)
    • Core Utilities: basic commands (ls, cp, grep, awk, etc.)
      • GNU coreutils - standard on most distros
      • Alternative: BusyBox - single binary replacing 300+ tools; used in containers and embedded systems
    • Shell: command interpreter; user’s interface to the kernel
      • bash (GNU Bourne Again Shell) - default on most distros
      • Alternatives: zsh (macOS default), fish, dash (minimal, used for scripts)
    • Init System: the first process started by the kernel, responsible for booting everything else
      • systemd - default on most modern distros
      • Alternatives: OpenRC (Gentoo, Alpine), runit (Void Linux; simple, process supervision focused), s6 (minimal, used in containers)
  • The Graphical Interface (User space)
    • Login: Display Manager
      • Login screen greeter; starts the display server and launches the DE session
      • Examples: GDM (GNOME), SDDM (KDE), LightDM (lightweight, DE-agnostic)
    • Runtime: Display Server —> Window Manager —> Desktop Environment
      • Display Server: Manages screen/input
        • Historically X11 (X.Org), now being replaced by Wayland
      • Window Manager: Draws and manages window borders/placement
        • Standalone: i3, Openbox
        • Bundled inside DEs: Mutter (GNOME), KWin (KDE Plasma)
      • Desktop Environment (DE): Full suite - file manager, taskbar, settings
        • Examples: GNOME, KDE Plasma, XFCE, Cinnamon
        • Uses a Widget Toolkit to render UI controls in apps:
          • GTK — used by GNOME and its apps
          • Qt — used by KDE Plasma and its apps

The Linux Kernel

  • https://developer.ibm.com/articles/l-linux-kernel/
  • Source code: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
  • A single binary (vmlinuz) loaded into memory at boot
    • Compressed (vmlinuz): typically 8-15 MB
    • Uncompressed (vmlinux): 50-100+ MB
    • Full set of compiled modules under /lib/modules/<version>/ adds several hundred MB more
  • Monolithic kernel — all subsystems run together in kernel space with shared memory and direct function calls
    • Contrast with microkernel (MINIX, QNX): only bare minimum in kernel space; everything else runs as isolated user-space processes — more fault-tolerant but slower due to IPC overhead
    • Linux is often called a modular monolithic kernelkernel modules give flexibility without the IPC cost
  • Internal subsystems:
    • System Call Interface (SCI)
      • thin layer that multiplexes/demultiplexes syscalls from user space into the kernel
      • implementation can vary by CPU architecture
    • Process Management (PM)
      • scheduling, process creation, signals, IPC
    • Memory Management (MM)
      • virtual memory, paging, page tables
      • each process gets its own isolated virtual address space
    • Virtual File System (VFS)
      • abstraction over all file systems (ext4, btrfs, xfs, tmpfs etc.)
      • unified open/read/write API regardless of underlying FS
    • Network Stack
      • implements network protocols (TCP/IP, UDP, etc.), socket API, and Netfilter for packet filtering/NAT
    • Device Drivers (DD)
      • hardware abstraction
      • block devices (disks), character devices (keyboards, terminals), network devices
      • Takes up ~60% of Kernel
    • Architecture-dependent code
      • low-level code per CPU architecture (x86, ARM, RISC-V)

Kernel Modules

  • They are kernel object files (.ko) that can be loaded or unloaded at runtime without rebooting
  • Stored in /lib/modules/<kernel-version>/
    • modules.dep: A text file generated by the system that maps out module dependencies
    • modules.builtin: drivers permanently compiled into vmlinuz itself (not loadable .ko files)
    • kernel/: Contains the actual modules, organized by category
      • kernel/drivers/: Hardware drivers (network cards, graphics, USB, etc.)
      • kernel/fs/: Filesystem drivers (ext4, Btrfs, NTFS, etc.)
      • kernel/net/: Network protocol modules (IPv6, Bluetooth, etc.)
  • Examples: GPU drivers (nvidia.ko), filesystem drivers (ntfs.ko), network drivers
  • Commands
    • lsmod: list currently loaded modules
    • modprobe: load/unload with dependency resolution
    • insmod/rmmod: lower-level load/unload (used in kernel module development)
    # Check if a driver is loaded (e.g. diagnosing Wi-Fi/GPU issues)
    lsmod | grep nvidia
     
    # Load a module (e.g. required before setting up Docker/Kubernetes networking)
    modprobe br_netfilter
     
    # Swap a conflicting driver (e.g. open-source nouveau --> proprietary nvidia)
    modprobe -r nouveau
    modprobe nvidia

Flavors of Linux

DistroBased onPackage MgrWho uses it / Key traits
Debian family
DebianaptWeb hosting, VPS servers; very stable, conservative release cycle
UbuntuDebianaptStartups, cloud VMs (AWS/GCP/Azure default), data science; LTS every 2 years
Linux MintUbuntuaptHome users, schools; ships Cinnamon DE; easiest Windows —> Linux transition
Pop!_OSUbuntuaptDevelopers, gamers; excellent NVIDIA support out-of-the-box; optional tiling WM
Kali LinuxDebianaptSecurity engineers, pentesters, CTF; ships 600+ preinstalled security tools
TailsDebianaptJournalists, activists, whistleblowers; boots from USB, routes all traffic through Tor, leaves no trace on host
Raspberry Pi OSDebianaptMakers, students, IoT; optimized for ARM; official OS for Raspberry Pi hardware
Red Hat family
FedoradnfDevelopers wanting cutting-edge packages; upstream testing ground for RHEL
RHELFedoradnfFinance, telecom, government, healthcare; paid support & certification from Red Hat
AlmaLinux / RockyRHELdnfWeb hosting, SMEs; binary-compatible RHEL drop-in; created after CentOS EOL in 2021
Amazon LinuxRHELdnfAWS-native workloads; default EC2 AMI; optimized for AWS services
Arch family
Arch LinuxpacmanPower users, developers; rolling-release, minimal base, build-it-yourself philosophy
ManjaroArchpacmanDesktop users; Arch benefits with GUI installer and curated rolling releases
SUSE family
openSUSEzypperDevOps, sysadmins; Leap (stable) / Tumbleweed (rolling); strong YaST admin tooling
SUSE Linux Enterprise (SLE)openSUSEzypperSAP workloads, European enterprises, finance; commercial OS built from openSUSE upstream
Gentoo family
GentooemergeEmbedded, custom appliances; source-based - everything compiled from source for max customization
Chrome OSGentooK-12 education, Chromebook users; runs Android & Linux apps in containers
Independent
Alpine LinuxapkDocker containers, microservices; extremely minimal (~5 MB); musl libc + BusyBox
NixOSnixDevOps, reproducible builds; entire system state declared in config files
AndroidConsumer mobile, IoT; Linux kernel but no GNU userland - uses ART runtime + Bionic libc

How OS starts up?

Initial RAM Disk

  • https://en.wikipedia.org/wiki/Initial_ramdisk
  • Load temporary root file system into RAM
  • make preparations before the real root file system can be mounted
  • Ways to achieve:
    • initrd: initial RAM Disk
      • stored in /initrd
    • initramfs: Initial RAM Filesystem
      • stored in /boot