Disk management in Linux and Unix systems is one of the most fundamental responsibilities of system administrators. In this article, we will examine in detail the basic commands used in disk management and their purposes.
The df
command shows the usage status of file systems.
df -h
: Shows in human-readable format (GB, MB)df -i
: Shows inode usagedf -T
: Shows filesystem typedf -l
: Shows only local filesystems
The du
command shows disk usage of directories and files.
du -h
: Shows in human-readable formatdu -s
: Shows only the total sizedu -a
: Shows all filesdu -c
: Shows the grand total at the end
Classic disk partitioning tool:
fdisk -l
: Lists all disks and their partitionsfdisk /dev/sda
: Opens specified disk for partitioning
Modern disk partitioning tool:
parted -l
: Lists all disks and their partitionsparted /dev/sda print
: Shows partitions of a specific diskparted /dev/sda mkpart
: Creates new partition
Graphical disk partitioning tool:
gparted
: Launches the graphical interface
Creating filesystems:
mkfs.ext4 /dev/sda1
: Creates ext4 filesystemmkfs.xfs /dev/sda2
: Creates XFS filesystemmkfs.btrfs /dev/sda3
: Creates BTRFS filesystem
Mounting and unmounting disk partitions:
mount /dev/sda1 /mnt
: Mounts the diskumount /mnt
: Unmounts the diskmount -a
: Mounts all disks in fstab
Checking disk health:
smartctl -a /dev/sda
: Shows detailed disk informationsmartctl -H /dev/sda
: Shows disk health status
Disk I/O statistics:
iostat -x 1
: Shows disk performance metrics every secondiostat -m
: Shows statistics in MB
Disk performance testing:
fio --filename=/dev/sda --direct=1 --rw=randread
: Random read testfio --filename=/dev/sda --direct=1 --rw=randwrite
: Random write test
Filesystem check and repair:
fsck /dev/sda1
: Checks filesystemfsck -f /dev/sda1
: Forces checkfsck -y /dev/sda1
: Automatically answers "yes" to all questions
Bad sector checking:
badblocks -v /dev/sda1
: Checks for bad sectorsbadblocks -w /dev/sda1
: Checks with write test (destructive)
Listing LVM components:
pvs
: Shows physical volumesvgs
: Shows volume groupslvs
: Shows logical volumes
Creating LVM components:
pvcreate /dev/sda1
: Creates physical volumevgcreate vg0 /dev/sda1
: Creates volume grouplvcreate -L 10G vg0
: Creates 10GB logical volume
- Regular Monitoring: Monitor disk usage regularly
- Backup: Always backup before important disk operations
- Performance Optimization: Regularly check disk I/O performance
- Automated Checks: Automate disk health checks
- Documentation: Document disk configurations
-
Disk Space Issues
- Regular cleanup of temporary files
- Log rotation
- Identifying large files and directories
-
Performance Problems
- Monitoring I/O wait times
- Checking for fragmentation
- Optimizing disk scheduling
-
Hardware Failures
- Regular SMART checks
- Monitoring system logs
- Implementing RAID when necessary
-
Access Control
- Setting appropriate permissions
- Managing mount options
- Encrypting sensitive data
-
Audit Trail
- Logging disk operations
- Monitoring file system changes
- Tracking user activities
Disk management in Linux/Unix systems is critical for system stability and performance. Effective use of these commands and tools allows system administrators to quickly identify and resolve issues. Regular disk monitoring and maintenance increase system reliability and prevent data loss.
- Man pages for each command
- Online Linux documentation
- Community forums and support channels
- Professional training materials
Remember that proper disk management is essential for:
- System performance
- Data integrity
- Resource optimization
- System reliability
- Disaster recovery
Always stay updated with the latest tools and best practices in disk management to maintain an efficient and reliable system.