Skip to main content

Linux Disk Management and Storage for DevOps

 Disk Management & Storage: The Complete Guide to Linux Storage

Master disk management, partitioning, and storage optimization like a professional system administrator.

📅 Published: Feb 2026
⏱️ Estimated Reading Time: 20 minutes
🏷️ Tags: Disk Management, Partitioning, Filesystems, LVM, Storage, Linux Administration


💽 Understanding Disks, Partitions, and Filesystems

The Storage Hierarchy: From Physical to Logical

Think of Linux storage like organizing a library:

  • Disk = The entire library building

  • Partition = Different rooms in the library (fiction, non-fiction, reference)

  • Filesystem = How books are organized in each room (Dewey decimal system)

  • Mount Point = Where you access each room from the main hallway

Key Concepts Explained

1. Disks (Physical Storage)

Disks are your physical hardware: HDD (Hard Disk Drive) or SSD (Solid State Drive). In Linux, disks are represented as files in /dev/:

  • /dev/sda = First disk

  • /dev/sdb = Second disk

  • /dev/nvme0n1 = First NVMe SSD

  • /dev/vda = First virtual disk (in VMs/cloud)

2. Partitions (Logical Divisions)

Partitions divide a disk into separate sections. Think of partitioning like dividing a large field into different plots of land:

  • /dev/sda1 = First partition on first disk

  • /dev/sda2 = Second partition on first disk

3. Filesystems (Organization Systems)

Filesystems determine how data is stored and organized on a partition:

  • ext4 = Most common Linux filesystem (reliable, mature)

  • XFS = High-performance, good for large files

  • Btrfs = Modern with advanced features (snapshots, compression)

  • NTFS = Windows filesystem (read/write support in Linux)

  • FAT32/exFAT = Simple, compatible with everything

4. Mount Points (Access Points)

Mount points are directories where partitions become accessible:

  • / = Root filesystem (main system)

  • /home = User home directories

  • /boot = Boot files

  • /var = Variable data (logs, databases)


🔗 Mounting and Unmounting Drives

Understanding the Mount Process

Mounting is like plugging in a USB drive on Windows - it makes the storage available. But in Linux, you control exactly where it appears in your directory tree.

Basic Mount Commands

bash
# View currently mounted filesystems
mount

# View in a cleaner format
findmnt

# Mount a partition temporarily
sudo mount /dev/sdb1 /mnt
# /dev/sdb1 = Partition to mount
# /mnt = Where to mount it (must exist)

# Mount with specific filesystem type
sudo mount -t ext4 /dev/sdb1 /mnt

# Mount with options
sudo mount -o ro /dev/sdb1 /mnt  # Read-only mount
sudo mount -o noexec /dev/sdb1 /mnt  # No execution allowed

# Unmount a filesystem
sudo umount /mnt
# Or: sudo umount /dev/sdb1

# Force unmount (if busy)
sudo umount -l /mnt  # Lazy unmount
sudo umount -f /mnt  # Force unmount (dangerous!)

Automatic Mounting with /etc/fstab

The /etc/fstab file tells Linux what to mount automatically at boot. Think of it as your "storage startup configuration."

bash
# View fstab
cat /etc/fstab

# Example fstab entry:
# /dev/sdb1  /data  ext4  defaults  0  2
# │          │      │     │         │  └── fsck order (2=check after root)
# │          │      │     │         └── dump backup (0=no backup)
# │          │      │     └── Mount options
# │          │      └── Filesystem type
# │          └── Mount point
# └── Device to mount

# Add a new entry to fstab
echo "/dev/sdb1 /data ext4 defaults 0 2" | sudo tee -a /etc/fstab

# Test fstab entries (mount all)
sudo mount -a

# Check if it worked
mount | grep /data

Common Mount Options

bash
# Useful mount options:
defaults       # Default options (rw, suid, dev, exec, auto, nouser, async)
rw/ro          # Read-write or read-only
noexec         # Prevent executing programs from this filesystem
nosuid         # Ignore set-user-ID and set-group-ID bits
nodev          # Don't interpret device files
noatime        # Don't update access times (improves performance)
nofail         # Don't fail boot if device not present (for external drives)
user           Allow users to mount
users          Allow any user to mount/unmount

Working with USB Drives and External Storage

bash
# Automatically detect and mount USB drives
sudo apt install usbutils  # Install USB tools

# Check what USB devices are connected
lsusb

# Mount USB drive manually
# 1. Find the device
sudo fdisk -l | grep -i "usb\|sd"

# 2. Create mount point
sudo mkdir /mnt/usbdrive

# 3. Mount (usually FAT32/NTFS for USB)
sudo mount /dev/sdc1 /mnt/usbdrive

# For NTFS drives (if not automatically working)
sudo apt install ntfs-3g
sudo mount -t ntfs-3g /dev/sdc1 /mnt/usbdrive

# For exFAT drives
sudo apt install exfat-utils exfat-fuse
sudo mount -t exfat /dev/sdc1 /mnt/usbdrive

📊 Checking Disk Usage: df and du

df: Disk Free Space

df shows how much space is used and available on mounted filesystems. Think of it as checking how full each room in your library is.

bash
# Basic disk usage
df

# Human readable (MB, GB)
df -h

# Show filesystem type
df -T

# Show specific filesystem
df -h /home

# Show inodes (file count limits)
df -i
# Important: Even with free space, you can run out of inodes!

# Exclude certain filesystem types
df -h -x tmpfs -x devtmpfs

Understanding df output:

text
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1        50G   35G   12G  75% /
/dev/sdb1       200G   50G  150G  25% /data
  • Size = Total capacity

  • Used = Space currently used

  • Avail = Space available for new files

  • Use% = Percentage used

  • Mounted on = Where it's accessible

du: Disk Usage by Directory

While df shows disk-level usage, du shows directory-level usage - which folders are taking up space.

bash
# Show size of current directory
du -sh
# -s = summary (total only)
# -h = human readable

# Show sizes of all subdirectories
du -h --max-depth=1

# Sort by size (largest first)
du -sh * | sort -rh

# Find largest directories starting from root
sudo du -ah / 2>/dev/null | sort -rh | head -20
# 2>/dev/null hides permission errors

# Exclude certain patterns
du -sh --exclude="*.log" --exclude="*.tmp" /var

# Show both size and percentage
du -sch /home/*

# Find files larger than 100MB
find / -type f -size +100M -exec du -h {} \; 2>/dev/null | sort -rh

Practical Disk Usage Scenarios

bash
# Find what's taking space in /var
sudo du -ah /var 2>/dev/null | sort -rh | head -10

# Monitor log directory growth
watch -n 60 'du -sh /var/log'

# Find and list large files
find /home -type f -size +100M -exec ls -lh {} \; 2>/dev/null

# Check Apache/Nginx log sizes
du -ch /var/log/apache2/*.log
du -ch /var/log/nginx/*.log

# Check Docker disk usage
docker system df

🔧 Disk and Partition Tools: fdisk, lsblk, blkid

lsblk: List Block Devices

lsblk shows all block devices (disks and partitions) in a tree format. It's like a family tree for your storage.

bash
# List all block devices
lsblk

# List with more details
lsblk -f
# Shows filesystem type, UUID, mount points

# List with size in human readable format
lsblk -h

# Show only disks (no partitions)
lsblk -d

# Show specific device
lsblk /dev/sda

# Output with all information
lsblk -o NAME,SIZE,FSTYPE,TYPE,MOUNTPOINT,UUID

Sample lsblk output:

text
NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda      8:0    0   500G  0 disk 
├─sda1   8:1    0   512M  0 part /boot/efi
├─sda2   8:2    0   488G  0 part /
└─sda3   8:3    0   1.9G  0 part [SWAP]
sdb      8:16   0   1.8T  0 disk 
└─sdb1   8:17   0   1.8T  0 part /data

blkid: Block Device Identifiers

blkid shows UUIDs and filesystem types for block devices. UUIDs are unique identifiers used in /etc/fstab instead of device names.

bash
# Show all block device information
sudo blkid

# Show specific device
sudo blkid /dev/sda1

# Output example:
# /dev/sda1: UUID="abcd-1234" TYPE="vfat" PARTUUID="xyz-789"

Why UUIDs are better: Device names like /dev/sda1 can change if you add/remove disks. UUIDs stay the same, making /etc/fstab more reliable.

fdisk: Partition Table Editor

fdisk is a tool for creating, deleting, and managing partitions. Warning: This can destroy data if used incorrectly!

bash
# List partitions on a disk
sudo fdisk -l
sudo fdisk -l /dev/sda

# Interactive fdisk mode
sudo fdisk /dev/sdb
# Inside fdisk:
#   m = Help menu
#   p = Print partition table
#   n = Create new partition
#   d = Delete partition
#   w = Write changes and exit
#   q = Quit without saving

# Create a new partition non-interactively
echo -e "n\np\n1\n\n\nw" | sudo fdisk /dev/sdb
# Creates a new primary partition using all space

Creating and Formatting a New Partition

bash
# Step 1: Create partition
sudo fdisk /dev/sdb
# Inside: n (new), p (primary), 1 (partition number), enter, enter (use all space), w (write)

# Step 2: Format partition (creates filesystem)
sudo mkfs.ext4 /dev/sdb1
# For other filesystems:
# sudo mkfs.xfs /dev/sdb1
# sudo mkfs.ntfs /dev/sdb1
# sudo mkfs.vfat /dev/sdb1

# Step 3: Create mount point
sudo mkdir /data

# Step 4: Mount it
sudo mount /dev/sdb1 /data

# Step 5: Add to fstab for automatic mounting
echo "UUID=$(sudo blkid -s UUID -o value /dev/sdb1) /data ext4 defaults 0 2" | sudo tee -a /etc/fstab

# Step 6: Test
sudo mount -a
df -h /data

💾 Swap Memory and Swap Files

What is Swap?

Swap is virtual memory - using disk space as extra RAM. Think of it like having an overflow parking lot:

  • RAM = Main parking lot (fast access)

  • Swap = Overflow parking (slower, but better than no parking)

Checking Swap Status

bash
# Check if swap is active
swapon --show

# Or check with free
free -h
# Look for Swap line

# Show swap summary
cat /proc/swaps

Creating Swap Space

Method 1: Swap Partition (Recommended for permanent use)

bash
# Check available partitions
sudo fdisk -l

# Create swap on existing partition
sudo mkswap /dev/sdb2

# Enable swap
sudo swapon /dev/sdb2

# Make permanent (add to fstab)
echo "/dev/sdb2 none swap sw 0 0" | sudo tee -a /etc/fstab

Method 2: Swap File (Flexible, no partition needed)

bash
# Create 2GB swap file
sudo fallocate -l 2G /swapfile

# Or use dd if fallocate doesn't work
# sudo dd if=/dev/zero of=/swapfile bs=1M count=2048

# Set proper permissions
sudo chmod 600 /swapfile

# Format as swap
sudo mkswap /swapfile

# Enable swap
sudo swapon /swapfile

# Make permanent
echo "/swapfile none swap sw 0 0" | sudo tee -a /etc/fstab

# Verify
swapon --show
free -h

Swap Configuration and Optimization

bash
# Check current swappiness (0-100)
cat /proc/sys/vm/swappiness
# Lower value = less likely to use swap
# Default is 60, servers often use 10 or 1

# Change swappiness temporarily
sudo sysctl vm.swappiness=10

# Make permanent
echo "vm.swappiness=10" | sudo tee -a /etc/sysctl.conf
sudo sysctl -p

# Disable swap temporarily
sudo swapoff -a

# Re-enable all swap
sudo swapon -a

When to Use Swap

Use swap when:

  • You have limited RAM

  • Running memory-intensive applications

  • Want to handle memory spikes gracefully

Don't rely on swap for:

  • Database servers (very slow)

  • High-performance applications

  • Systems that need consistent speed


🧩 LVM (Logical Volume Manager) Basics

What is LVM and Why Use It?

LVM is like having dynamic storage that can grow, shrink, and move without disrupting your system. Traditional partitions are like fixed rooms - LVM is like having movable walls!

Benefits of LVM:

  1. Resize volumes without unmounting

  2. Combine multiple disks into one volume

  3. Take snapshots (point-in-time backups)

  4. Easy migration between physical disks

LVM Components

Think of LVM as building with Lego:

  • Physical Volume (PV) = Individual Lego pieces (disks/partitions)

  • Volume Group (VG) = A box of Lego pieces

  • Logical Volume (LV) = What you build from the pieces

  • Filesystem = What you put on your creation

Basic LVM Commands

bash
# Install LVM tools (if not installed)
sudo apt install lvm2  # Ubuntu/Debian
sudo yum install lvm2  # Red Hat/CentOS

# Create a Physical Volume (PV)
sudo pvcreate /dev/sdb

# Create a Volume Group (VG)
sudo vgcreate data_vg /dev/sdb

# Create a Logical Volume (LV)
sudo lvcreate -L 100G -n data_lv data_vg
# -L = Size, -n = Name

# Format the LV
sudo mkfs.ext4 /dev/data_vg/data_lv

# Mount it
sudo mkdir /data
sudo mount /dev/data_vg/data_lv /data

LVM Management Operations

bash
# Display LVM information
sudo pvs        # Physical volumes
sudo vgs        # Volume groups
sudo lvs        # Logical volumes

# Display detailed information
sudo pvdisplay
sudo vgdisplay
sudo lvdisplay

# Extend a logical volume (add more space)
# Step 1: Extend LV
sudo lvextend -L +50G /dev/data_vg/data_lv

# Step 2: Resize filesystem
sudo resize2fs /dev/data_vg/data_lv
# For XFS: sudo xfs_growfs /data

# Reduce a logical volume (shrink)
# WARNING: Backup first! Shrinking is risky.
# Step 1: Unmount and check filesystem
sudo umount /data
sudo e2fsck -f /dev/data_vg/data_lv

# Step 2: Shrink filesystem
sudo resize2fs /dev/data_vg/data_lv 50G

# Step 3: Shrink LV
sudo lvreduce -L 50G /dev/data_vg/data_lv

# Step 4: Remount
sudo mount /dev/data_vg/data_lv /data

# Add another disk to volume group
sudo pvcreate /dev/sdc
sudo vgextend data_vg /dev/sdc

# Take a snapshot (point-in-time backup)
sudo lvcreate -L 10G -s -n data_snapshot /dev/data_vg/data_lv
# -s = snapshot, -n = snapshot name

# Restore from snapshot
sudo umount /data
sudo lvconvert --merge /dev/data_vg/data_snapshot
sudo mount /dev/data_vg/data_lv /data

Real-World LVM Example: Adding Disk Space

bash
# Current setup: /data is running out of space
df -h /data
# Output: /dev/mapper/data_vg-data_lv  100G   95G  5.0G  95% /data

# Add new 500GB disk
lsblk
# Shows new disk: /dev/sdc

# Add to LVM
sudo pvcreate /dev/sdc
sudo vgextend data_vg /dev/sdc

# Extend logical volume
sudo lvextend -L +400G /dev/data_vg/data_lv
sudo resize2fs /dev/data_vg/data_lv

# Verify
df -h /data
# Output: /dev/mapper/data_vg-data_lv  500G   95G  405G  19% /data

📏 Disk Quotas: Limiting User Storage

What are Disk Quotas?

Disk quotas limit how much disk space users or groups can use. Think of it like giving each family member a storage locker with a size limit.

Enabling Quotas

bash
# Install quota tools
sudo apt install quota  # Ubuntu/Debian
sudo yum install quota  # Red Hat/CentOS

# Enable quotas on a filesystem
# Step 1: Add quota options to fstab
# Edit /etc/fstab, change:
# /dev/sdb1 /data ext4 defaults 0 2
# to:
# /dev/sdb1 /data ext4 defaults,usrquota,grpquota 0 2

# Step 2: Remount
sudo mount -o remount /data

# Step 3: Create quota database files
sudo quotacheck -cug /data
# -c = create, -u = user quotas, -g = group quotas

# Step 4: Enable quotas
sudo quotaon /data

# Check status
sudo quotaon -p /data

Setting Quota Limits

bash
# Set quota for a user
sudo edquota -u username
# This opens an editor with:
# Filesystem    blocks    soft    hard    inodes    soft    hard
# /dev/sdb1    0        0       0       0        0       0
# blocks = current usage (in 1KB blocks)
# soft = warning limit (can exceed temporarily)
# hard = absolute limit (cannot exceed)
# inodes = file count limits

# Example: Set 1GB soft limit, 1.2GB hard limit
# /dev/sdb1    0        1000000  1200000  0        0       0

# Set quota for a group
sudo edquota -g groupname

# Copy quota from one user to another
sudo edquota -p template_user target_user

# Set grace period (how long soft limit can be exceeded)
sudo edquota -t
# Sets grace period for all users on filesystem

Checking and Managing Quotas

bash
# Check user quota
sudo quota -u username

# Check all users
sudo repquota /data

# Check group quota
sudo quota -g groupname

# Turn quotas off
sudo quotaoff /data

# Update quota database (after manual changes)
sudo quotacheck -avug
# -a = all filesystems, -v = verbose, -u = user, -g = group

# View quota report
sudo repquota -a

User-Friendly Quota Reports

bash
# Create readable quota report
sudo repquota -s /data
# -s = human readable sizes

# Monitor quota usage
watch -n 60 'sudo repquota -s /data'

# Send quota warnings via email
# Install mailutils
sudo apt install mailutils
# Quota warnings are automatically emailed when users exceed soft limits

🎯 Real-World DevOps Scenarios

Scenario 1: Setting Up a New Data Disk

bash
#!/bin/bash
# setup-data-disk.sh

# Variables
DISK="/dev/sdb"
MOUNT_POINT="/data"

# Create partition
echo "Creating partition..."
echo -e "n\np\n1\n\n\nw" | sudo fdisk $DISK

# Format as XFS (good for large files)
echo "Formatting as XFS..."
sudo mkfs.xfs ${DISK}1

# Create mount point
echo "Creating mount point..."
sudo mkdir -p $MOUNT_POINT

# Add to fstab
echo "Adding to fstab..."
UUID=$(sudo blkid -s UUID -o value ${DISK}1)
echo "UUID=$UUID $MOUNT_POINT xfs defaults 0 2" | sudo tee -a /etc/fstab

# Mount
echo "Mounting..."
sudo mount -a

# Set permissions
echo "Setting permissions..."
sudo chmod 755 $MOUNT_POINT
sudo chown root:root $MOUNT_POINT

echo "Done! Disk mounted at $MOUNT_POINT"
df -h $MOUNT_POINT

Scenario 2: Emergency Disk Space Cleanup

bash
#!/bin/bash
# emergency-cleanup.sh

THRESHOLD=90
CURRENT_USAGE=$(df / | awk 'NR==2{print $5}' | sed 's/%//')

if [ $CURRENT_USAGE -gt $THRESHOLD ]; then
    echo "WARNING: Disk usage at ${CURRENT_USAGE}%"
    echo "Starting cleanup..."
    
    # 1. Clear package cache
    echo "Cleaning package cache..."
    sudo apt clean 2>/dev/null || sudo yum clean all 2>/dev/null
    
    # 2. Clear temporary files
    echo "Cleaning temporary files..."
    sudo rm -rf /tmp/*
    
    # 3. Clear old log files
    echo "Cleaning old logs..."
    sudo find /var/log -name "*.log" -type f -mtime +30 -delete
    
    # 4. Clear Docker (if installed)
    echo "Cleaning Docker..."
    docker system prune -af 2>/dev/null || true
    
    # 5. Report largest directories
    echo "Top 10 largest directories:"
    sudo du -ah / 2>/dev/null | sort -rh | head -10
    
    NEW_USAGE=$(df / | awk 'NR==2{print $5}' | sed 's/%//')
    echo "Cleanup complete. New disk usage: ${NEW_USAGE}%"
else
    echo "Disk usage okay: ${CURRENT_USAGE}%"
fi

Scenario 3: LVM-Based Storage Setup

bash
#!/bin/bash
# setup-lvm-storage.sh

# Variables
DISKS="/dev/sdb /dev/sdc"
VG_NAME="data_vg"
LV_NAME="data_lv"
MOUNT_POINT="/data"
LV_SIZE="500G"

echo "Setting up LVM storage..."

# Create physical volumes
for disk in $DISKS; do
    echo "Creating PV on $disk..."
    sudo pvcreate $disk
done

# Create volume group
echo "Creating VG $VG_NAME..."
sudo vgcreate $VG_NAME $DISKS

# Create logical volume
echo "Creating LV $LV_NAME with size $LV_SIZE..."
sudo lvcreate -L $LV_SIZE -n $LV_NAME $VG_NAME

# Format
echo "Formatting as ext4..."
sudo mkfs.ext4 /dev/$VG_NAME/$LV_NAME

# Mount
echo "Mounting at $MOUNT_POINT..."
sudo mkdir -p $MOUNT_POINT
sudo mount /dev/$VG_NAME/$LV_NAME $MOUNT_POINT

# Add to fstab
echo "Adding to fstab..."
UUID=$(sudo blkid -s UUID -o value /dev/$VG_NAME/$LV_NAME)
echo "UUID=$UUID $MOUNT_POINT ext4 defaults 0 2" | sudo tee -a /etc/fstab

echo "Setup complete!"
echo
echo "Summary:"
sudo vgs
sudo lvs
df -h $MOUNT_POINT

Scenario 4: Disk Health Monitoring

bash
#!/bin/bash
# disk-health-monitor.sh

LOG_FILE="/var/log/disk-health.log"

echo "=== Disk Health Report: $(date) ===" >> $LOG_FILE

# 1. Disk space
echo "Disk Usage:" >> $LOG_FILE
df -h >> $LOG_FILE

# 2. Inode usage
echo -e "\nInode Usage:" >> $LOG_FILE
df -i >> $LOG_FILE

# 3. SMART status (if available)
echo -e "\nSMART Status:" >> $LOG_FILE
for disk in /dev/sd[a-z]; do
    if [ -e $disk ]; then
        echo "Checking $disk..." >> $LOG_FILE
        sudo smartctl -H $disk 2>/dev/null | grep -E "SMART|result" >> $LOG_FILE || true
    fi
done

# 4. Check for bad blocks
echo -e "\nBad Block Check (if any):" >> $LOG_FILE
sudo badblocks -sv /dev/sda 2>/dev/null | tail -5 >> $LOG_FILE || echo "No bad blocks found" >> $LOG_FILE

# 5. Mount status
echo -e "\nMount Status:" >> $LOG_FILE
mount | grep -E "^/dev/" >> $LOG_FILE

echo -e "\n---\n" >> $LOG_FILE

# Send alert if any disk > 90% full
if df / | awk 'NR==2{print $5}' | grep -q '9[0-9]'; then
    echo "CRITICAL: Root disk almost full!" | mail -s "Disk Alert" admin@example.com
fi

📋 Quick Reference Cheat Sheet

TaskCommandDescription
Show disk spacedf -hHuman readable disk usage
Directory sizedu -sh directoryShow directory size
List block deviceslsblkTree view of disks/partitions
Show filesystem infoblkidUUID and filesystem type
Partition disksudo fdisk /dev/sdbInteractive partition editor
Format partitionsudo mkfs.ext4 /dev/sdb1Create filesystem
Mount filesystemsudo mount /dev/sdb1 /mntMount partition
Auto-mountEdit /etc/fstabMount at boot
Check swapswapon --show or free -hShow swap usage
Create swap filesudo fallocate -l 2G /swapfileCreate 2GB swap file
LVM: Create PVsudo pvcreate /dev/sdbCreate physical volume
LVM: Create VGsudo vgcreate vg_name /dev/sdbCreate volume group
LVM: Create LVsudo lvcreate -L 100G -n lv_name vg_nameCreate logical volume
LVM: Extend LVsudo lvextend -L +50G /dev/vg/lvAdd 50GB to LV
Set quotasudo edquota -u usernameEdit user quota
Check quotasudo quota -u usernameShow user quota usage
SMART checksudo smartctl -H /dev/sdaCheck disk health

🚀 Practice Exercises

Exercise 1: Create and Mount a New Partition

bash
# 1. List disks
lsblk

# 2. Create partition (use /dev/sdb or available disk)
sudo fdisk /dev/sdb
# Inside fdisk: n (new), p (primary), 1 (first), enter, +5G (5GB size), w (write)

# 3. Format
sudo mkfs.ext4 /dev/sdb1

# 4. Create mount point
sudo mkdir /mnt/mydata

# 5. Mount
sudo mount /dev/sdb1 /mnt/mydata

# 6. Verify
df -h /mnt/mydata
lsblk /dev/sdb

Exercise 2: Create and Use Swap File

bash
# 1. Create 1GB swap file
sudo fallocate -l 1G /swapfile1

# 2. Set permissions
sudo chmod 600 /swapfile1

# 3. Format as swap
sudo mkswap /swapfile1

# 4. Enable
sudo swapon /swapfile1

# 5. Verify
swapon --show
free -h

# 6. Test with stress
# Install: sudo apt install stress
stress --vm 1 --vm-bytes 500M --vm-hang 10
# Watch swap usage in another terminal: watch -n 1 free -h

Exercise 3: Basic LVM Operations

bash
# 1. Create physical volume
sudo pvcreate /dev/sdc

# 2. Create volume group
sudo vgcreate practice_vg /dev/sdc

# 3. Create logical volume
sudo lvcreate -L 5G -n practice_lv practice_vg

# 4. Format
sudo mkfs.ext4 /dev/practice_vg/practice_lv

# 5. Mount
sudo mkdir /mnt/lvmtest
sudo mount /dev/practice_vg/practice_lv /mnt/lvmtest

# 6. Verify
df -h /mnt/lvmtest
sudo lvs

Exercise 4: Disk Quota Setup

bash
# 1. Create test user
sudo useradd testuser
sudo passwd testuser

# 2. Create test directory
sudo mkdir /quota_test
sudo chown testuser:testuser /quota_test

# 3. Enable quotas (add ,usrquota to fstab options, remount)

# 4. Create quota database
sudo quotacheck -cug /quota_test
sudo quotaon /quota_test

# 5. Set quota
sudo edquota -u testuser
# Set: soft=100M, hard=200M

# 6. Test
sudo -u testuser dd if=/dev/zero of=/quota_test/testfile bs=1M count=150
# Should work but warn at 100MB

🔗 Master Disk Management with Hands-on Labs

Disk management is a critical skill for system administrators and DevOps engineers. Understanding storage, partitioning, and filesystems is essential for managing servers effectively.

👉 Practice disk management, LVM, and storage optimization in our interactive labs at:
https://devops.trainwithsky.com/

Our platform provides:

  • Real storage configuration exercises

  • LVM setup and management scenarios

  • Disk troubleshooting simulations

  • Production-like storage environments

  • Guided exercises with increasing complexity


Frequently Asked Questions

Q: Should I use ext4 or XFS?
A: Use ext4 for general purpose. Use XFS for large files (databases, media) or if you need consistent performance.

Q: How often should I check disk health?
A: Monthly for SMART checks, daily for disk space monitoring (automated).

Q: What's the difference between soft and hard quotas?
A: Soft quotas can be temporarily exceeded (with grace period). Hard quotas cannot be exceeded at all.

Q: When should I use LVM?
A: Use LVM when you need flexibility - resizing, combining disks, taking snapshots. For simple setups, regular partitions are fine.

Q: How do I recover from a full disk?
A: 1. Delete unnecessary files 2. Clear package/log caches 3. Move data to another disk 4. Extend disk/LVM if possible.

Q: What's the safest way to resize partitions?
A: Backup first! Use LVM for flexibility. For non-LVM, use tools like gparted from a live USB.

Q: How much swap should I have?
A: General rule: 2x RAM for <2GB RAM, equal to RAM for 2-8GB, 0.5x RAM for >8GB. But adjust based on your needs.

Having disk management issues or questions? Share your specific challenge in the comments below! 💬

Comments

Popular posts from this blog

Introduction to Terraform – The Future of Infrastructure as Code

  Introduction to Terraform – The Future of Infrastructure as Code In today’s fast-paced DevOps world, managing infrastructure manually is outdated . This is where Terraform comes in—a powerful Infrastructure as Code (IaC) tool that allows you to define, provision, and manage cloud infrastructure efficiently . Whether you're working with AWS, Azure, Google Cloud, or on-premises servers , Terraform provides a declarative, automation-first approach to infrastructure deployment. Shape Your Future with AI & Infinite Knowledge...!! Read In-Depth Tech & Self-Improvement Blogs http://www.skyinfinitetech.com Watch Life-Changing Videos on YouTube https://www.youtube.com/@SkyInfinite-Learning Transform Your Skills, Business & Productivity – Join Us Today! In today’s digital-first world, agility and automation are no longer optional—they’re essential. Companies across the globe are rapidly shifting their operations to the cloud to keep up with the pace of innovatio...

📊 Monitoring & Logging in Kubernetes – Tools like Prometheus, Grafana, and Fluentd

  Monitoring & Logging in Kubernetes – Tools like Prometheus, Grafana, and Fluentd Monitoring and logging are essential for maintaining a healthy and well-performing Kubernetes cluster. In this guide, we’ll cover why monitoring is important, key monitoring tools like Prometheus and Grafana, and logging tools like Fluentd to help you gain visibility into your cluster’s performance and logs. Shape Your Future with AI & Infinite Knowledge...!! Want to Generate Text-to-Voice, Images & Videos? http://www.ai.skyinfinitetech.com Read In-Depth Tech & Self-Improvement Blogs http://www.skyinfinitetech.com Watch Life-Changing Videos on YouTube https://www.youtube.com/@SkyInfinite-Learning Transform Your Skills, Business & Productivity – Join Us Today! 🚀 Introduction In today’s fast-paced cloud-native environment, Kubernetes has emerged as the de-facto container orchestration platform. But deploying and managing applications in Kubernetes is just half the ba...

🔒 Kubernetes Security – RBAC, Network Policies, and Secrets Management

  Kubernetes Security – RBAC, Network Policies, and Secrets Management Security is a critical aspect of managing Kubernetes clusters. In this guide, we'll cover essential security mechanisms like Role-Based Access Control (RBAC) , Network Policies , and Secrets Management to help you secure your Kubernetes environment effectively. Shape Your Future with AI & Infinite Knowledge...!! Want to Generate Text-to-Voice, Images & Videos? http://www.ai.skyinfinitetech.com Read In-Depth Tech & Self-Improvement Blogs http://www.skyinfinitetech.com Watch Life-Changing Videos on YouTube https://www.youtube.com/@SkyInfinite-Learning Transform Your Skills, Business & Productivity – Join Us Today! 🚀 Introduction: Why Kubernetes Security Is Non-Negotiable As Kubernetes becomes the backbone of modern cloud-native infrastructure, security is no longer optional—it’s mission-critical . With multiple moving parts like containers, pods, services, nodes, and more, Kuberne...