Pages

Sunday, October 30, 2011

Available disk space in Linux

One of the basic tools to monitor your harddisks and partitions is df - disk free. It shows you a couple of information about how your harddisk is used. A sample output maybe like this:

# df
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/root            251915124  33553292 205565260  15% /
...

The output above shows the used device (/dev/root). It also shows the size of the disk, in this case 251915124 1K-blocks, how many 1K-blocks are used, how many 1K-blocks are available    and a percentage output of the usage of the device. At least the output shows where the device is mounted on. The output about the used and available 1K-blocks is hard to read but it can be recalculated in MB and GB:

# echo 251915124/1024/1024 | bc -l
240.24498367309570312500
# echo 33553292/1024/1024 | bc -l
31.99891281127929687500
# echo 205565260/1024/1024 | bc -l
196.04230880737304687500

The output show already KB values, deviding by 1024 twice will show the value in GB. In this case the disk has a size of 240GB, a usage of 32GB and 196GB space left. Luckily, df can show this information directly with the -h switch for human readable format:

# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/root             241G   32G  197G  15% /
...

To show the used filesystem use the -T switch:

# df -T -h
Filesystem    Type    Size  Used Avail Use% Mounted on
/dev/root     ext4    241G   32G  197G  15% /
tmpfs        tmpfs    1.9G     0  1.9G   0% /dev/shm

The output shows that /dev/root was formatted by ext4 and /dev/shm is only a temporary filesystem accessible by tmpfs. df has a few options more, like excluding filesystems or showing only a specific types of filesystems. To exclude filesystems (e.g. ext4) use the -x switch:

# df -h -x ext4
Filesystem            Size  Used Avail Use% Mounted on
tmpfs                 1.9G     0  1.9G   0% /dev/shm

To show only a specific filesystem use the -t switch:

# df -h -t ext4
Filesystem            Size  Used Avail Use% Mounted on
/dev/root             241G   32G  197G  15% /

One last hint: the example above shows that 32G are used and 197GB are available. The sum of these two values would be 129GB, but the disk istself has a size of 241GB. It seems that 12GB are missing?
Keep in mind that while creating a ext4 filesystem 5% of the disk will be spared for usage of system critical daemons like syslogd if the disk gets full:

# echo 241/100*5 | bc -l
12.05000000000000000000
# echo 197+32+12 | bc -l
241

At least 241GB again.

No comments:

Post a Comment