Topics Discussed:
- Booting Process in Linux
- Linux Architecture
- Process in Linux
- Memory Management
- Shared Memory Management
- Swapping
- Virtual File System
Booting Process in Linux:
When a Linux system powers on, there is a sequence of events that lead to the operating system booting up:
1. Power On: The motherboard is activated.
2. ROM: The Read-Only Memory initiates the first program to run – the BIOS/UEFI.
3. BIOS/UEFI: Basic Input/Output System or Unified Extensible Firmware Interface performs POST and locates the bootloader.
– POST (Power-On Self Test): Validates that key hardware components like the disk, keyboard, and mouse are functioning.
– Bootloader: Determines the booting device as set in BIOS/UEFI settings.
4. MBR/GPT: Master Boot Record or GUID Partition Table is read to proceed with booting.
– MBR: Used by BIOS systems.
– GPT: Used by UEFI systems, offering more advanced features.
5. GRUB2: The Grand Unified Bootloader version 2 takes over to load the kernel into RAM.
– Init RFS: Initializes the root filesystem to ensure peripherals are discoverable for booting.
6. Kernel Loading: The kernel, upon loading, starts the `systemd` process – the first process in the system hierarchy.
7. Runlevel/Targets: Determines the state of the system (multi-user, GUI, etc.).
8. Services Initialization: System services such as network and login services are started.
9. User Login Process: `logind` handles user authentication to provide shell access.
Linux Architecture:
Linux architecture divides space into two main segments:
1. Kernel Space: Any program running inside the kernel operates here, managing core functions like process scheduling, memory management, filesystems, hardware device access, and networking.
2. User Space: Programs running outside the kernel’s core processes. Interaction with the kernel is done through system calls.
Processes in Linux:
A process is an instance of a program in execution, each with a unique identifier (PID). They can be parent or child processes.
Behind the Scenes of the `ls` Command:
When the `ls` command is invoked:
1. The shell forks a child process.
2. The `exec` system call is used to run `ls`.
3. The kernel checks for the `ls` executable in the environment’s path variable.
4. The shell waits for the output of the `ls` command, which lists directory contents.
Memory Management:
Linux employs a combination of virtual and physical memory mechanisms, including:
– Memory Management Unit (MMU): Manages memory and caching operations for the CPU.
– Page Table: Keeps a mapping table in RAM for virtual-to-physical memory address translation.
– Lazy Allocation: Delays physical page allocation until it’s necessary, conserving resources.
Shared Memory Management:
Threads within a process can share the same memory space, facilitating efficient data access and manipulation.
Swapping:
To free up RAM, inactive pages are moved to the swap space, though this is not a substitute for adequate physical memory.
Virtual File System:
The `/proc` directory hosts virtual files representing system and process information, which are not used for storage. Similar to `/proc`, `/sys` provides device and system information, while `/dev` includes device files.
– tmpfs: A temporary filesystem in RAM for short-lived files.
– dev/shm: A directory for shared memory segments.
– Inodes: Data structures that store information about files on Linux file systems.
– Journaling: A file system mechanism to keep track of changes not yet committed to the file system’s main part.