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,
fdisk,lsblk,parted,mount - 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
| Year | Event |
|---|---|
| 1969 | Unix created at AT&T Bell Labs by Ken Thompson, Dennis Ritchie, and others. Written in assembly, later rewritten in C |
| 1983 | GNU Project launched by Richard Stallman to build a free Unix-like OS. Produced core tools (gcc, bash, glibc) but lacked a kernel |
| 1987 | MINIX - a small Unix-like OS, released by Andrew Tanenbaum for educational use. Inspired Linus Torvalds |
| 1991 | Linux kernel announced by Linus Torvalds (21-year-old Finnish student) on Aug 25 |
| 1992 | Linux kernel relicensed under GPL v2. Combined with GNU tools, forming the first usable GNU/Linux system |
| 1993 | Slackware and Debian - among the first Linux distributions released |
| 1994 | Linux kernel 1.0 released (March 14). ~176,000 lines of code |
| 1998 | Major companies (IBM, Oracle, Intel) announce Linux support |
| 2000 | IBM invests $1 billion in Linux - signals enterprise legitimacy |
| 2003 | RHEL (Red Hat Enterprise Linux) launched, creating a commercial model around Linux |
| 2004 | Ubuntu released by Canonical - made Linux significantly more accessible for desktop use |
| 2005 | Git created by Linus Torvalds to manage Linux kernel source after a licensing dispute with BitKeeper |
| 2007 | Android launched (based on the Linux kernel), later becoming the world’s most-used OS |
| 2015 | systemd becomes the default init system across most major distros |
| 2019 | Microsoft ships WSL 2 (Windows Subsystem for Linux) with a real Linux kernel inside Windows |
| 2020 | Linux kernel 5.x - widespread support for modern hardware and improved security |
| 2024 | Kernel 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 callsglibc(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
- GNU
- 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)
- Standalone:
- 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 appsQt— used by KDE Plasma and its apps
- Display Server: Manages screen/input
- Login: Display Manager
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
- Compressed (
- 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 kernel — kernel 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,tmpfsetc.) - unified
open/read/writeAPI regardless of underlying FS
- abstraction over all file systems (
- 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)
- System Call Interface (SCI)
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 dependenciesmodules.builtin: drivers permanently compiled intovmlinuzitself (not loadable.kofiles)kernel/: Contains the actual modules, organized by categorykernel/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 modulesmodprobe: load/unload with dependency resolutioninsmod/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
- Linux distributions (aka distros) package the Linux kernel with a package manager, init system, and default tools.
- Comprehensive list of linux distros: https://distrowatch.com/dwres.php?resource=family-tree
| Distro | Based on | Package Mgr | Who uses it / Key traits |
|---|---|---|---|
| Debian family | |||
| Debian | — | apt | Web hosting, VPS servers; very stable, conservative release cycle |
| Ubuntu | Debian | apt | Startups, cloud VMs (AWS/GCP/Azure default), data science; LTS every 2 years |
| Linux Mint | Ubuntu | apt | Home users, schools; ships Cinnamon DE; easiest Windows —> Linux transition |
| Pop!_OS | Ubuntu | apt | Developers, gamers; excellent NVIDIA support out-of-the-box; optional tiling WM |
| Kali Linux | Debian | apt | Security engineers, pentesters, CTF; ships 600+ preinstalled security tools |
| Tails | Debian | apt | Journalists, activists, whistleblowers; boots from USB, routes all traffic through Tor, leaves no trace on host |
| Raspberry Pi OS | Debian | apt | Makers, students, IoT; optimized for ARM; official OS for Raspberry Pi hardware |
| Red Hat family | |||
| Fedora | — | dnf | Developers wanting cutting-edge packages; upstream testing ground for RHEL |
| RHEL | Fedora | dnf | Finance, telecom, government, healthcare; paid support & certification from Red Hat |
| AlmaLinux / Rocky | RHEL | dnf | Web hosting, SMEs; binary-compatible RHEL drop-in; created after CentOS EOL in 2021 |
| Amazon Linux | RHEL | dnf | AWS-native workloads; default EC2 AMI; optimized for AWS services |
| Arch family | |||
| Arch Linux | — | pacman | Power users, developers; rolling-release, minimal base, build-it-yourself philosophy |
| Manjaro | Arch | pacman | Desktop users; Arch benefits with GUI installer and curated rolling releases |
| SUSE family | |||
| openSUSE | — | zypper | DevOps, sysadmins; Leap (stable) / Tumbleweed (rolling); strong YaST admin tooling |
| SUSE Linux Enterprise (SLE) | openSUSE | zypper | SAP workloads, European enterprises, finance; commercial OS built from openSUSE upstream |
| Gentoo family | |||
| Gentoo | — | emerge | Embedded, custom appliances; source-based - everything compiled from source for max customization |
| Chrome OS | Gentoo | — | K-12 education, Chromebook users; runs Android & Linux apps in containers |
| Independent | |||
| Alpine Linux | — | apk | Docker containers, microservices; extremely minimal (~5 MB); musl libc + BusyBox |
| NixOS | — | nix | DevOps, reproducible builds; entire system state declared in config files |
| Android | — | — | Consumer 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
- stored in
initramfs: Initial RAM Filesystem- stored in
/boot
- stored in