Grimoire-
Command
.es

GNU+Linux command memo

Reduce ext partition reserved blocks

Réduire le nombre de blocks réservés à l’utilisateur root sur un système de fichier ext, et récupérer ainsi l’espace libre pour les utilisateurs.

On ext (ext2, ext3, ext4) filesystems, 5% of the blocks are reserved by default for the root user. For a 1To disk, it represents 50Go. It can safely be reduced.

$ sudo tune2fs -l /dev/mapper/machine--vg-root | rg "Reserved block count" (1)
Reserved block count:     6220910 (2)
$ df -h | rg "machine--vg-root" (3)
/dev/mapper/machine--vg-root   469G    361G   84G  81% /
$ sudo tune2fs -m 0.1 /dev/mapper/machine--vg-root (4)
tune2fs 1.45.5 (07-Jan-2020)
Setting reserved blocks percentage to 0.1% (124831 blocks)
$ python -c 'print(124831*4096/1024)' (5)
499324
$ df -h | rg "machine--vg-root" (6)
/dev/mapper/machine--vg-root   469G    361G  108G  77% /
1 Find how many blocks are reserved on your ext partition, here it’s around 25Go (for a 512 Go SSD).
2 To get the block size : tune2fs -l /dev/mapper/machine—​vg-root | rg "Block size" ; here it’s 4096 octets. It can also been read via blockdev --getbsz /dev/mapper/machine—​vg-root.
3 Check the free space of this partition (here it’s 84 Go)
4 Set the reserved blocks percentage to : 0.1 %
5 Compute the size in kilo-octects, it’s now around 500 Mo
6 Check the free space of this partition again, it’s now 108 Go
You need to keep some reserved blocks on your root filesystem, else you might brake your system.