Linux 101 : Troubleshooting low diskspace issues ( df, du and badblocks commands)
Troubleshooting a filesystem could involve finding out which file consumes a lot of disk space, or checking bad blocks on the disk. Below some of the tools that could help us diagnose these issues.
The df utility:
The "df" utility gives us information about the filesystems and their disk space usage in the "use%" column.
When that value gets close to 100%, it means that the partition is about to get full.
The "du" utility allows us to know disk usage for files on the system.
After discovering the partition that is full or almost full using "df -h", we could run the utility "du" on its mount point displayed also in the "df -h" results in the "Mounted on" column.
To display the files in an ascending order according to their size, we use the below command:
Once we find the file or the directory that uses up most of the space, we could, for example, compress it using the "tar" utility and free up space:
The badblocks utility:
The "badblocks" utility tests a disk for corrupted blocks:
v: verbose (outputs all the details on the screen)
s: show progress
s: show progress
With this command you can see how much data is written to a hard drive per second. We can also see the data read per second from these device:
MB_wrtn/s : number of MBs written per sesond to /dev/sda.
MB_read : number of MBs read from /dev/sda since the last boot.
MB_wrtn : number of MBs written to /dev/sda since the last boot.
If we need to create a directory on a partition, but we discover that the partition is full, an alternative would be to create a symbolic link on the "full" partition and to make it point to the directory we want to create (somewhere else, where we have enough disk space).
We use the below command to create a symbolic link:
Creates a symbolic link named "extra" in the "/home/Albert" directory that points to the directory "/usr/var/Albert" on another partition (that have enough space).