How does Linux Boot?
- It's a multi stage process.
- Dependent on Computer Architecture
- But has similar stages and software components
Neso Academy youtube
demonstrate behavoiur of fork and exec
Typical Usage
- fork() is often followed by exec() in the child process.
- This allows a parent process to create a new child process
- and then the child can execute a new program.
--pid: Creates a new PID namespace.
--fork: Forks the bash shell as a new child process.
--mount-proc: Mounts a new /proc filesystem for the new PID namespace.
--net: Isolates the network interfaces.
--uts: Isolates the hostname and domain name.
--ipc: Isolates inter-process communication.
--mount: Creates a new mount namespace.
/proc is a virtual filesystem representing processes.
Effect on containers
Inside a container, the processes appear to be the only processes on the system. The first process in the container will always be PID 1, making it appear like it's the root process of the system, even though it is running alongside other containers on the same host.
Example in containers:
Inside a container, a process like nginx might have PID 1, but on the host, it may have a different PID like 23045. The container is isolated from the host’s process tree.
Effect on containers: Containers can have their own isolated file systems, and they can see only the files that are part of their environment. This allows containers to have different root directories (/), with access to only specific files, without exposing the entire host filesystem.
Effect on containers: Containers can have their own isolated network stacks. They can have their own IP addresses, ports, and even virtual interfaces. Containers might communicate with each other over a bridge network but remain isolated from the host's networking. This is a key feature that allows multiple containers to run services on the same port (e.g., port 80 for HTTP) without conflict.
Example in containers:
Container A could have an IP like 10.0.0.2, while Container B could have 10.0.0.3, and both could use port 80, but their traffic is handled separately from each other and the host.
Effect on containers: This ensures that processes inside a container cannot use IPC to communicate with processes on the host or in other containers, providing isolation for processes that rely on shared memory or other forms of inter-process communication.
Example in containers:
If two containers are running separate databases, they can’t interfere with each other by accessing each other's shared memory segments or semaphores.
# Hostname Namespace - Custom hostname inside the container
# User Namespace - Use the host's user namespace (or "default" for UID/GID remapping)
# IPC Namespace - Isolated Inter-Process Communication for the container
# PID Namespace - Isolated process IDs
# Network Interface Namespace - Isolated network stack using bridge mode
# File System Namespace - Mount the host directory to container's /usr/share/nginx/html
# Expose port 80 on container as 8080 on host
# Prevent privilege escalation inside the container
Why Cgroups Are Important:
Resource Isolation: Ensures each group (e.g., container) has its own resource limits, improving performance isolation.
Fair Resource Distribution: Allocates resources fairly between groups to avoid resource starvation.
Resource Accounting: Tracks resource usage for monitoring and optimization.
Security: Prevents resource exhaustion attacks (e.g., Denial of Service) by limiting usage.
---
## **3. Subsystems (Controllers)**
- **cpu:** Controls CPU scheduling and usage.
- **memory:** Limits and tracks memory usage.
- **blkio:** Controls access to block devices (disk I/O).
- **net_cls:** Manages network packet classification.
- **devices:** Controls access to hardware devices.
cgcreate, cgset, cgexec: Command-line utilities for creating, configuring, and running processes in cgroups.
Systemd: Used in modern Linux systems for managing services and their associated cgroups.
Docker/Kubernetes: Use cgroups internally for resource limitation and isolation in containers.