Penguin Crumbs

Notes and tips from a Linux user

home about this blog

Monitor hard disk space usage and reclaim reserved blocks

Just few words about how to monitor hard disk usage and a little trick to free some space in partitions formatted with ext4, ext3, ext2.

Let's start with the command df. It shows the usage of all partitions. Since modern distributions like Ubuntu often make extensive use of snap partitions (the command "snap list" will show you the programs that can use them), it's better to filter the output like this:

 df -h | grep -v snap

And this shows the usage of each directory, sorted by size:

 du -hd 1 | sort -h

Now the trick: partitions formatted with ext4, ext3 and ext2 reserve 5% of space for the root user: in this way when you run out of space the root user can still login and free space.
This is good for the main system partitions, but it's a bit annoying for large data-only partitions.

You can show reserved space with this command:

 sudo tune2fs -l /dev/sdb1 | grep "Reserved block count"

...and if you want to get new space, deleting all the reserved blocks:

 sudo tune2fs -m 0 /dev/sdb1

PS: of course, replace "/dev/sdb1" with the right partition :-)

Posted on 2019-06-04  
⇦  back
Copyright © 2019-2024 Marcello Zaniboni