Linux Disk Management
Comprehensive guide to managing storage devices in Linux, including disk partitioning, filesystem creation, mounting, and maintenance. Learn essential commands and best practices for storage administration.
Overview
Linux disk management involves several key concepts and tools:
- Block devices - Physical storage devices (HDDs, SSDs, USB drives)
- Partitions - Logical divisions of storage devices
- Filesystems - Data organization structures (ext4, xfs, btrfs)
- Mount points - Directory locations where filesystems are accessed
- Partition tables - MBR (legacy) or GPT (modern) partition schemes
Essential Commands
| Command | Purpose | Example |
|---|---|---|
lsblk |
List block devices | lsblk -f |
fdisk |
Partition management (MBR) | fdisk /dev/sda |
parted |
Advanced partitioning (GPT/MBR) | parted /dev/sda |
mkfs |
Create filesystems | mkfs.ext4 /dev/sda1 |
mount |
Mount filesystems | mount /dev/sda1 /mnt |
umount |
Unmount filesystems | umount /mnt |
df |
Show disk usage | df -h |
du |
Directory usage | du -sh /home |
Listing Disks and Partitions
View all block devices
Shows tree view of all block devices and their mount points
Show filesystem information
Displays filesystem types, UUIDs, and labels
List partition tables
Shows detailed partition information for all disks
Show disk usage
Displays mounted filesystems with human-readable sizes
Creating Partitions
Using fdisk (MBR partition table)
Creates a 10GB primary partition on /dev/sdb
Using parted (GPT partition table)
Creates GPT partition table and 10GB partition
Non-interactive parted
Creates GPT table and partition using entire disk
Formatting Partitions
Create ext4 filesystem
Formats partition with ext4 filesystem
Create ext4 with label
Creates ext4 filesystem with volume label
Create XFS filesystem
Formats partition with XFS filesystem
Create FAT32 filesystem
Creates FAT32 filesystem (useful for USB drives)
Mounting Filesystems
Mount partition temporarily
Creates mount point and mounts partition
Mount with specific options
Mounts with read-write and noatime options
Unmount filesystem
Safely unmounts the filesystem
Permanent mounting (/etc/fstab)
Configures automatic mounting at boot
Disk Usage Monitoring
Show filesystem usage
Displays used and available space for mounted filesystems
Show directory sizes
Shows size of each directory in /home
Find large files
Finds files larger than 100MB in /home
Monitor disk usage in real-time
Updates disk usage display every second
Advanced Operations
Resize ext4 filesystem
Resizes ext4 filesystem to use all available partition space
Check filesystem integrity
Checks and repairs filesystem errors
Clone disk with dd
Creates exact copy of disk (use with extreme caution)
Best Practices
Safety Guidelines
- Always backup important data before disk operations
- Use
lsblkto verify device names before partitioning - Test mount operations before adding to /etc/fstab
- Use UUIDs instead of device names in /etc/fstab for stability
- Unmount filesystems properly before removing devices
Performance Tips
- Use GPT partition tables for disks larger than 2TB
- Align partitions to 1MB boundaries for SSD performance
- Consider noatime mount option to reduce write operations
- Use appropriate filesystem for your use case (ext4, xfs, btrfs)
- Monitor disk health with SMART tools
Common Issues and Solutions
Device is busy error
Identifies processes preventing unmount
Partition table corrupted
Attempts to recover or recreate partition table
Filesystem errors
Checks and repairs filesystem corruption