Linux ve Unix sistemlerde disk yönetimi, sistem yöneticilerinin en temel görevlerinden biridir. Bu makalede, disk yönetiminde kullanılan temel komutları ve kullanım amaçlarını detaylı olarak inceleyeceğiz.
## 1. Disk Kullanımını İzleme Komutları
### df (Disk Free)
`df` komutu, dosya sistemlerinin kullanım durumunu gösterir.
– `df -h`: İnsan tarafından okunabilir formatta (GB, MB) gösterir
– `df -i`: İnode kullanımını gösterir
– `df -T`: Dosya sistemi türünü gösterir
– `df -l`: Sadece yerel dosya sistemlerini gösterir
### du (Disk Usage)
`du` komutu, dizinlerin ve dosyaların disk kullanımını gösterir.
– `du -h`: İnsan tarafından okunabilir formatta gösterir
– `du -s`: Sadece toplam boyutu gösterir
– `du -a`: Tüm dosyaları gösterir
– `du -c`: Toplam boyutu en sonda gösterir
## 2. Disk Bölümlendirme Komutları
### fdisk
Klasik disk bölümlendirme aracı:
– `fdisk -l`: Tüm diskleri ve bölümlerini listeler
– `fdisk /dev/sda`: Belirtilen diski bölümlendirme için açar
### parted
Modern disk bölümlendirme aracı:
– `parted -l`: Tüm diskleri ve bölümlerini listeler
– `parted /dev/sda print`: Belirli bir diskin bölümlerini gösterir
– `parted /dev/sda mkpart`: Yeni bölüm oluşturur
### gparted
Grafiksel disk bölümlendirme aracı:
– `gparted`: Grafiksel arayüzü başlatır
## 3. Dosya Sistemi Yönetimi
### mkfs (Make Filesystem)
Dosya sistemi oluşturma:
– `mkfs.ext4 /dev/sda1`: ext4 dosya sistemi oluşturur
– `mkfs.xfs /dev/sda2`: XFS dosya sistemi oluşturur
– `mkfs.btrfs /dev/sda3`: BTRFS dosya sistemi oluşturur
### mount/umount
Disk bölümlerini bağlama ve ayırma:
– `mount /dev/sda1 /mnt`: Diski bağlar
– `umount /mnt`: Diski ayırır
– `mount -a`: fstab dosyasındaki tüm diskleri bağlar
## 4. Disk Sağlığı ve Performans
### smartctl
Disk sağlığını kontrol etme:
– `smartctl -a /dev/sda`: Detaylı disk bilgilerini gösterir
– `smartctl -H /dev/sda`: Disk sağlık durumunu gösterir
### iostat
Disk I/O istatistikleri:
– `iostat -x 1`: Her saniye disk performans metriklerini gösterir
– `iostat -m`: MB cinsinden istatistikleri gösterir
### fio
Disk performans testi:
– `fio — filename=/dev/sda — direct=1 — rw=randread`: Rastgele okuma testi
– `fio — filename=/dev/sda — direct=1 — rw=randwrite`: Rastgele yazma testi
## 5. Disk Sorunları ve Çözümleri
### fsck (Filesystem Check)
Dosya sistemi kontrolü ve onarımı:
– `fsck /dev/sda1`: Dosya sistemini kontrol eder
– `fsck -f /dev/sda1`: Zorla kontrol yapar
– `fsck -y /dev/sda1`: Tüm soruları otomatik “evet” yanıtlar
### badblocks
Bozuk sektör kontrolü:
– `badblocks -v /dev/sda1`: Bozuk sektörleri kontrol eder
– `badblocks -w /dev/sda1`: Yazma testi ile kontrol eder (destructive)
## 6. LVM (Logical Volume Management)
### pvs/vgs/lvs
LVM bileşenlerini listeleme:
– `pvs`: Fiziksel volumeleri gösterir
– `vgs`: Volume gruplarını gösterir
– `lvs`: Logical volumeleri gösterir
### pvcreate/vgcreate/lvcreate
LVM bileşenleri oluşturma:
– `pvcreate /dev/sda1`: Fiziksel volume oluşturur
– `vgcreate vg0 /dev/sda1`: Volume grup oluşturur
– `lvcreate -L 10G vg0`: 10GB logical volume oluşturur
## En İyi Uygulamalar
1. **Düzenli İzleme**: Disk kullanımını düzenli olarak izleyin
2. **Yedekleme**: Önemli disk işlemlerinden önce mutlaka yedek alın
3. **Performans Optimizasyonu**: Disk I/O performansını düzenli kontrol edin
4. **Otomatik Kontroller**: Disk sağlığı kontrollerini otomatikleştirin
5. **Dokümantasyon**: Disk yapılandırmalarını dokümante edin
## Sonuç
Linux/Unix sistemlerde disk yönetimi, sistem kararlılığı ve performansı için kritik öneme sahiptir. Bu komutları ve araçları etkin kullanmak, sistem yöneticilerine sorunları hızlı tespit etme ve çözme imkanı sağlar. Düzenli disk kontrolü ve bakımı, sistem güvenilirliğini artırır ve veri kayıplarını önler.
# Disk Management and Essential Commands in Linux/Unix Systems
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.
## 1. Disk Usage Monitoring Commands
### df (Disk Free)
The `df` command shows the usage status of file systems.
– `df -h`: Shows in human-readable format (GB, MB)
– `df -i`: Shows inode usage
– `df -T`: Shows filesystem type
– `df -l`: Shows only local filesystems
### du (Disk Usage)
The `du` command shows disk usage of directories and files.
– `du -h`: Shows in human-readable format
– `du -s`: Shows only the total size
– `du -a`: Shows all files
– `du -c`: Shows the grand total at the end
## 2. Disk Partitioning Commands
### fdisk
Classic disk partitioning tool:
– `fdisk -l`: Lists all disks and their partitions
– `fdisk /dev/sda`: Opens specified disk for partitioning
### parted
Modern disk partitioning tool:
– `parted -l`: Lists all disks and their partitions
– `parted /dev/sda print`: Shows partitions of a specific disk
– `parted /dev/sda mkpart`: Creates new partition
### gparted
Graphical disk partitioning tool:
– `gparted`: Launches the graphical interface
## 3. Filesystem Management
### mkfs (Make Filesystem)
Creating filesystems:
– `mkfs.ext4 /dev/sda1`: Creates ext4 filesystem
– `mkfs.xfs /dev/sda2`: Creates XFS filesystem
– `mkfs.btrfs /dev/sda3`: Creates BTRFS filesystem
### mount/umount
Mounting and unmounting disk partitions:
– `mount /dev/sda1 /mnt`: Mounts the disk
– `umount /mnt`: Unmounts the disk
– `mount -a`: Mounts all disks in fstab
## 4. Disk Health and Performance
### smartctl
Checking disk health:
– `smartctl -a /dev/sda`: Shows detailed disk information
– `smartctl -H /dev/sda`: Shows disk health status
### iostat
Disk I/O statistics:
– `iostat -x 1`: Shows disk performance metrics every second
– `iostat -m`: Shows statistics in MB
### fio
Disk performance testing:
– `fio — filename=/dev/sda — direct=1 — rw=randread`: Random read test
– `fio — filename=/dev/sda — direct=1 — rw=randwrite`: Random write test
## 5. Disk Issues and Solutions
### fsck (Filesystem Check)
Filesystem check and repair:
– `fsck /dev/sda1`: Checks filesystem
– `fsck -f /dev/sda1`: Forces check
– `fsck -y /dev/sda1`: Automatically answers “yes” to all questions
### badblocks
Bad sector checking:
– `badblocks -v /dev/sda1`: Checks for bad sectors
– `badblocks -w /dev/sda1`: Checks with write test (destructive)
## 6. LVM (Logical Volume Management)
### pvs/vgs/lvs
Listing LVM components:
– `pvs`: Shows physical volumes
– `vgs`: Shows volume groups
– `lvs`: Shows logical volumes
### pvcreate/vgcreate/lvcreate
Creating LVM components:
– `pvcreate /dev/sda1`: Creates physical volume
– `vgcreate vg0 /dev/sda1`: Creates volume group
– `lvcreate -L 10G vg0`: Creates 10GB logical volume
## Best Practices
1. **Regular Monitoring**: Monitor disk usage regularly
2. **Backup**: Always backup before important disk operations
3. **Performance Optimization**: Regularly check disk I/O performance
4. **Automated Checks**: Automate disk health checks
5. **Documentation**: Document disk configurations
## Common Issues and Troubleshooting
1. **Disk Space Issues**
— Regular cleanup of temporary files
— Log rotation
— Identifying large files and directories
2. **Performance Problems**
— Monitoring I/O wait times
— Checking for fragmentation
— Optimizing disk scheduling
3. **Hardware Failures**
— Regular SMART checks
— Monitoring system logs
— Implementing RAID when necessary
## Security Considerations
1. **Access Control**
— Setting appropriate permissions
— Managing mount options
— Encrypting sensitive data
2. **Audit Trail**
— Logging disk operations
— Monitoring file system changes
— Tracking user activities
## Conclusion
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.
## Additional Resources
– 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.