- Posted on
- • Getting Started
Mastering Containers, Filesystems & Storage in Linux
- Author
-
-
- User
- Linux Bash
- Posts by this author
- Posts by this author
-
Containers: Lightweight Application Virtualization
Core Concepts:
- Virtualization Method: Isolates apps using namespaces (PID, network, mount) and cgroups (resource limits).
- Containers vs. VMs:
- VMs: Emulate full OS (heavy, hypervisor-dependent).
- Containers: Share host kernel (lightweight, faster startup).
docker run -it ubuntu:22.04 /bin/bash # Run container interactively
Docker Essentials:
- Installation:
bash sudo apt install docker.io # Debian/Ubuntu sudo systemctl enable --now docker
- Key Commands:
bash docker pull nginx:latest # Download image docker ps -a # List containers docker build -t myapp . # Build image from Dockerfile
- docker-compose: Orchestrate multi-container apps:
yaml # docker-compose.yml services: web: image: nginx ports: - "80:80"
bash docker-compose up -d # Launch stack
Linux Filesystems: Structure & Types
Organization & VFS:
- Hierarchy:
/
(root) →/bin
,/etc
,/home
,/var
. - VFS Role: Unifies access to all filesystems (ext4, NFS, tmpfs) via standardized system calls.
Filesystem Types:
Type | Use Case | Journaling |
---|---|---|
ext4 | General-purpose | Yes |
XFS | Large files | Yes |
Btrfs | Snapshots, RAID | Yes |
tmpfs | RAM-backed temp | No |
NFS | Network shares | Depends |
Why Journaling? Prevents corruption after crashes by logging changes first.
Disk Management & Partitioning
Hardware & Naming:
- Disk Types: HDD (spinning platters), SSD (flash), NVMe (PCIe-attached).
- Device Nodes:
/dev/sda
: First SATA disk/dev/nvme0n1
: First NVMe disk/dev/sda1
: First partition on SATA disk
Partitioning Tools:
sudo fdisk /dev/sdb # Interactive partitioning
sudo blkid # Show UUIDs/filesystems
lsblk -o NAME,SIZE,FSTYPE,MOUNTPOINT # Tree view
Strategies & Backup:
- MBR vs. GPT: GPT supports >2TB disks and >4 partitions.
- Backup Partition Table:
bash sudo sfdisk -d /dev/sda > sda-backup.txt # Backup sudo sfdisk /dev/sda < sda-backup.txt # Restore
Filesystem Operations
Creation & Maintenance:
sudo mkfs.ext4 /dev/sdb1 # Format partition
sudo fsck /dev/sdb1 # Check/repair errors
sudo chattr +i /critical/file # Immutable file (ext4)
lsattr /secret/config # View extended attributes
Mounting & Automation:
- Manual Mount:
bash sudo mount /dev/sdb1 /mnt/data
- Permanent Mount: Add to
/etc/fstab
:
UUID=abcd1234 /mnt/data ext4 defaults 0 2
- Network Filesystems:
bash sudo mount -t nfs 192.168.1.10:/share /mnt/nfs
- Automount (autofs): Mount on-demand when accessed.
ext4 Deep Dive
Structure:
- Superblock: Filesystem metadata (size, block count).
- Inodes: Store file attributes (permissions, timestamps).
- Block Groups: Divide disk for parallel access.
Utilities:
sudo dumpe2fs /dev/sda1 # Show ext4 details
sudo tune2fs -c 30 /dev/sda1 # Check every 30 mounts
LVM: Flexible Storage Management
Concepts:
- Physical Volume (PV): Disk/partition (
/dev/sdb
). - Volume Group (VG): Pool of PVs.
- Logical Volume (LV): Virtual partition created from VG.
Operations:
# Create LV
sudo pvcreate /dev/sdb # Mark disk as PV
sudo vgcreate myvg /dev/sdb # Create VG
sudo lvcreate -L 20G -n mylv myvg # Create 20G LV
sudo mkfs.ext4 /dev/myvg/mylv # Format
# Resize LV (extend)
sudo lvextend -L +5G /dev/myvg/mylv # Add 5G
sudo resize2fs /dev/myvg/mylv # Resize filesystem
# Snapshots (point-in-time backup)
sudo lvcreate -s -n snap -L 1G /dev/myvg/mylv
Troubleshooting Toolkit
Tool | Purpose |
---|---|
df -h | Disk space by filesystem |
**du -sh *** | Directory sizes |
dmesg | Kernel logs (disk errors) |
lsblk | Block device topology |
iostat | Disk I/O performance |
Key Takeaways
- Containers isolate apps; Docker simplifies deployment.
- ext4/XFS handle journalling; tmpfs uses RAM.
- LVM enables dynamic storage: resize LVs, snapshot data.
- Always backup partition tables before modifying disks.
# Audit filesystem health:
sudo fsck -AN; sudo dmesg | grep -i "error"; df -h
Next: Deep dive into Kubernetes orchestration!