Question
How do you address a partition running out or close to running out of disk space?
Answer
The first thing you should do is confirm if the disk space is indeed full or nearly full. You can check this using the df command:
# df -h
You should see an output similar to the following:
# root@server [~] # df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 7.7G 0 7.7G 0% /dev
tmpfs 7.7G 7.6M 7.7G 1% /dev/shm
tmpfs 7.7G 59M 7.7G 1% /run
tmpfs 7.7G 0 7.7G 0% /sys/fs/cgroup
/dev/mapper/centos-root 50G 37G 14G 73% /
/dev/sda1 1014M 351M 664M 35% /boot
/dev/mapper/centos-home 1.8T 2.6G 1.8T 1% /home
/dev/loop0 2.2G 195M 1.9G 10% /tmp
tmpfs 1.6G 4.0K 1.6G 1% /run/user/42
tmpfs 1.6G 40K 1.6G 1% /run/user/0
According to the output above, you can see /dev/mapper/centos-root is at 73% full. Therefore, we should be investigating that partition.
Since /dev/mapper/centos-root is the root partition; it includes all the other partitions on the server. Using the du command, we will investigate the root partition's disk usage, but exclude the other partitions under it that do not count against its disk usage since they are their own partitions:
# du -h --max-depth=1 --exclude=/root --exclude=/tmp --exclude=/proc --exclude=/home/virtfs
Once you have determined the directory that is consuming the most disk space, you can use the following command to get a more detailed readout:
# du -h --max-depth=1 -x /PARTITION | sort -hr
Note: You will want to replace "PARTITION" with the complete file path.
We are using the -x flag because we are reading for --one-file-system. This skips directories on different file systems.
For example:
# root@server [~] # du -h --max-depth=1 -x /usr | sort -hr
21G /usr
14G /usr/share
2.9G /usr/local
2.1G /usr/lib64
1.2G /usr/lib
413M /usr/bin
272M /usr/src
181M /usr/sbin
152M /usr/libexec
40M /usr/include
0 /usr/selector.etc
0 /usr/selector
0 /usr/games
0 /usr/etc
From the output above, you can see that within the /usr directory, /usr/share/ is the directory that is using a lot of disk space. You could run the same command once more on /usr/share/ to calculate the details:
# du -h --max-depth=1 -x /usr/share | sort -hr
Once you have determined which directory consumes a lot of the disk space, then you can review individual files and sections of that directory to see if anything is using more space than it should. Often at times, this may be a log file that has never been cleared, or backups that were forgotten about. You can then perform any necessary actions to have the cause of the increased disk space addressed properly.
Comments
0 comments
Article is closed for comments.