Disk Tasks
Jump to navigation
Jump to search
Disk Space
Find top dirs within a dir for disk usage:
du -hx /path/to/dir --max-depth 1 | sort -rh | head
Find the inode usage (modify the /*/* to the depth and specific dirs you need):
du --inodes -sch /*/*|sort -hk1
Can also do this for inodes:
find . -type d | while read line; do echo "$( find "$line" -maxdepth 1 | wc -l) $line"; done 2>/dev/null | sort -rn | head -n20
For very old environments
When sort doesn't have -h flag:
du -hx --max-depth=1 | awk '{printf "%s %08.2f\t%s\n", index("KMG", substr($1, length($1))), substr($1, 0, length($1)-1), $0}' | sort -r|cut -f2,3
Or, list the dir size within a dir this way:
du -sk /path/to/dir/* | sort -n | while read size fname; do for unit in k M G T P E Z Y; do if [ $size -lt 1024 ]; then echo -e "${size}${unit}\t${fname}"; break; fi; size=$((size/1024)); done; done
Resizing an LVM
This is after you have powered off the VM, and raised its disk size in VMware, VirtualBox, or whatever. After you have done that and booted it back up (assuming sda is the disk, sda2 is the PV, and the device mapper is os-root):
echo 1 > /sys/class/block/sda/device/rescan parted /dev/sda resizepart 2 -- -1 pvresize /dev/sda2 lvresize -l +95%FREE /dev/mapper/os-root resize2fs /dev/mapper/os-root
Testing A Disk
RAID?
It's important to determine if there's a RAID first, if there is one you need to go with RAID-specific commands instead. To determine that, use:
cat /proc/mdstat
Or:
lspci | grep -i raid
RAID-less SMART Test
Where sda is the hard disk:
smartctl -t long /dev/sda
Check progress with:
smartctl -a /dev/sda
Read-only Partition?
mount -o remount rw /partition