- Storage Concepts
- Listing Disks & Partitions
- Partitioning Disks
- Filesystems
- Mounting & Unmounting
- The /etc/fstab File
- Disk Usage & Space
- Swap Space
- Practice Exercises
ββββββββββββββββββββββββββββββββββββββββ
β Physical Disk β
β (e.g., /dev/sda β 500 GB) β
ββββββββββββ¬βββββββββββ¬βββββββββββββββββ€
β /dev/sda1β /dev/sda2β /dev/sda3 β
β (boot) β (root) β (home) β
β 512 MB β 50 GB β 449.5 GB β
β ext4 β ext4 β ext4 β
β /boot β / β /home β
ββββββββββββ΄βββββββββββ΄βββββββββββββββββ
| Device | Path | Description |
|---|---|---|
| First SATA/SCSI disk | /dev/sda |
Entire disk |
| First partition | /dev/sda1 |
First partition on sda |
| Second partition | /dev/sda2 |
Second partition on sda |
| NVMe SSD | /dev/nvme0n1 |
First NVMe drive |
| NVMe partition | /dev/nvme0n1p1 |
First partition on NVMe |
| Virtual disk | /dev/vda |
Virtio disk (VMs) |
# List block devices (most readable)
lsblk
# NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
# sda 8:0 0 500G 0 disk
# ββsda1 8:1 0 512M 0 part /boot
# ββsda2 8:2 0 50G 0 part /
# ββsda3 8:3 0 449.5G 0 part /home
lsblk -f # Show filesystem types
lsblk -o NAME,SIZE,TYPE,FSTYPE,MOUNTPOINT # Custom columns
# fdisk list (detailed)
sudo fdisk -l # All disks and partitions
sudo fdisk -l /dev/sda # Specific disk
# Partition information
sudo parted -l # List all disk layouts
cat /proc/partitions # Kernel's view of partitions
# Get UUIDs
sudo blkid # Block device IDs
ls -l /dev/disk/by-uuid/ # UUID symlinks
β οΈ Warning: Partitioning can destroy data. Always back up first and practice on VMs!
sudo fdisk /dev/sdb # Open fdisk for disk sdb
# fdisk commands (interactive):
# m β Help menu
# p β Print partition table
# n β New partition
# d β Delete partition
# t β Change partition type
# w β Write changes and exit
# q β Quit without savingsudo parted /dev/sdb
# Interactive commands:
# print β Show partition table
# mklabel gpt β Create GPT partition table
# mkpart primary ext4 1MiB 100GiB β Create partition
# rm 1 β Delete partition 1
# quit β Exit
# Non-interactive examples:
sudo parted /dev/sdb mklabel gpt
sudo parted /dev/sdb mkpart primary ext4 1MiB 50GiB
sudo parted /dev/sdb mkpart primary ext4 50GiB 100%| Feature | MBR | GPT |
|---|---|---|
| Max disk size | 2 TB | 9.4 ZB |
| Max partitions | 4 primary (or 3 + extended) | 128 |
| Boot mode | BIOS (Legacy) | UEFI |
| Redundancy | No backup | Backup header at end of disk |
| Recommended | Old systems | Modern systems β |
# ext4 (most common for Linux)
sudo mkfs.ext4 /dev/sdb1
# XFS (RHEL default, great for large files)
sudo mkfs.xfs /dev/sdb1
# Btrfs (modern, CoW, snapshots)
sudo mkfs.btrfs /dev/sdb1
# FAT32 (USB drives, cross-platform)
sudo mkfs.vfat -F 32 /dev/sdb1
# exFAT (large files, cross-platform)
sudo mkfs.exfat /dev/sdb1| Filesystem | Max File | Max Volume | Journaling | Use Case |
|---|---|---|---|---|
| ext4 | 16 TB | 1 EB | β | General purpose |
| XFS | 8 EB | 8 EB | β | Large files, servers |
| Btrfs | 16 EB | 16 EB | β CoW | Snapshots, NAS |
| ZFS | 16 EB | 256 ZB | β CoW | Enterprise storage |
| FAT32 | 4 GB | 2 TB | β | USB, compatibility |
| exFAT | 128 PB | 128 PB | β | Large USB/SD |
# Check filesystem (MUST unmount first!)
sudo umount /dev/sdb1
sudo fsck /dev/sdb1 # Automatic detection
sudo fsck.ext4 /dev/sdb1 # Specific to ext4
sudo e2fsck -f /dev/sdb1 # Force check
# XFS check (can be done mounted, read-only)
sudo xfs_repair /dev/sdb1# Create mount point
sudo mkdir -p /mnt/mydisk
# Mount a partition
sudo mount /dev/sdb1 /mnt/mydisk
# Mount with specific filesystem type
sudo mount -t ext4 /dev/sdb1 /mnt/mydisk
# Mount read-only
sudo mount -o ro /dev/sdb1 /mnt/mydisk
# Mount with options
sudo mount -o rw,noexec,nosuid /dev/sdb1 /mnt/mydisk
# Mount by UUID (preferred β doesn't change if disk order changes)
sudo mount UUID="xxxx-xxxx-xxxx" /mnt/mydisk
# Mount an ISO file
sudo mount -o loop image.iso /mnt/iso
# Mount a USB drive (usually auto-detected)
sudo mount /dev/sdb1 /mnt/usb
# Mount NFS share
sudo mount -t nfs server:/share /mnt/nfs
# Remount with different options (without unmounting)
sudo mount -o remount,rw /mnt/mydisksudo umount /mnt/mydisk # By mount point
sudo umount /dev/sdb1 # By device
# Force unmount (if busy)
sudo umount -f /mnt/mydisk
# Lazy unmount (detach now, cleanup when not busy)
sudo umount -l /mnt/mydisk
# Find what's using the mount
lsof +D /mnt/mydisk
fuser -vm /mnt/mydiskmount # All current mounts
mount | grep sdb # Filter for specific disk
findmnt # Tree view of mounts
findmnt -t ext4 # Only ext4 mounts
df -hT # Mounts with filesystem type/etc/fstab defines filesystems to mount automatically at boot.
cat /etc/fstab# <device> <mount> <type> <options> <dump> <pass>
UUID=xxxx-xxxx-xxxx-xxxx / ext4 errors=remount-ro 0 1
UUID=yyyy-yyyy-yyyy-yyyy /home ext4 defaults 0 2
UUID=zzzz-zzzz-zzzz-zzzz /boot ext4 defaults 0 2
UUID=aaaa-aaaa-aaaa-aaaa none swap sw 0 0
tmpfs /tmp tmpfs defaults,noatime 0 0
| Field | Description | Common Values |
|---|---|---|
| device | UUID, LABEL, or device path | UUID=..., /dev/sda1 |
| mount | Mount point | /home, /mnt/data |
| type | Filesystem type | ext4, xfs, swap, nfs |
| options | Mount options | defaults, noatime, ro |
| dump | Backup flag | 0 (no), 1 (yes) |
| pass | fsck order | 0 (skip), 1 (root), 2 (other) |
| Option | Description |
|---|---|
defaults |
rw, suid, dev, exec, auto, nouser, async |
noatime |
Don't update access times (performance boost) |
noexec |
Prevent execution of binaries |
nosuid |
Ignore SUID/SGID bits |
ro |
Read-only |
rw |
Read-write |
auto |
Mount at boot |
noauto |
Don't mount at boot |
user |
Allow normal users to mount |
nofail |
Don't halt boot if device missing |
# Test fstab without rebooting
sudo mount -a # Mount everything in fstab
# Always test fstab before rebooting!
sudo findmnt --verify # Verify fstab syntaxπ¨ A broken
/etc/fstabcan prevent your system from booting. Always test withmount -abefore rebooting.
# Disk free space
df -h # Human-readable
df -hT # Include filesystem type
df -h /home # Specific mount point
df -i # Inode usage
# Directory sizes
du -sh /var/log # Total size of directory
du -sh /var/* # Size of each item in /var
du -sh * | sort -rh | head -10 # Top 10 largest items
du -ah . | sort -rh | head -20 # Top 20 largest files (recursive)
# ncdu β interactive disk analyzer
sudo apt install ncdu
ncdu / # Interactive usage viewerSwap is disk space used when RAM is full β acts as "overflow" memory.
swapon --show # Active swap spaces
free -h # Memory + swap overview
cat /proc/swaps # Kernel's swap info# Create a 4 GB swap file
sudo fallocate -l 4G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
# Make permanent β add to fstab
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
# Verify
swapon --show
free -h# Check current swappiness (0-100, lower = use swap less)
cat /proc/sys/vm/swappiness # Default: 60
# Temporary change
sudo sysctl vm.swappiness=10
# Permanent change
echo "vm.swappiness=10" | sudo tee -a /etc/sysctl.conf- List all block devices with
lsblk -f - Check disk usage of
/varand find the largest subdirectory - UUID: Find the UUID of your root partition with
sudo blkid - fstab: Read your
/etc/fstaband identify each entry - Swap: Check your current swap space and swappiness value
- Mount: Mount a USB drive or ISO file to
/mnt/test - ncdu: Install
ncduand find the largest directory on your system - (VM only): Create a new partition, format it as ext4, and mount it
β Previous: Process Management Β· π Home Β· Next: Networking Fundamentals β