[HowTo] adjust filesystem space reserved for the root account

Share your HowTo, Documentation, Tips and Tricks. Not for support questions!.
Post Reply
Message
Author
User avatar
wizard10000
Global Moderator
Global Moderator
Posts: 1244
Joined: 2019-04-16 23:15
Location: southeastern us
Has thanked: 125 times
Been thanked: 220 times

[HowTo] adjust filesystem space reserved for the root account

#1 Post by wizard10000 »

Debian and other Linux distributions reserve 5% of a filesystem for the root account; this is so unprivileged users can't completely fill up a filesystem and break system operations such as event logging. Just my opinion but that 5% was a great idea when drives were smaller but 5% of a 1TB drive is 50GB and that can be a lot of useful space that may not ever be used.

By default systemd limits the size of its journal to 4GB so on our 1TB drive that'd be quite a bit of space on the drive that can only be accessed by the root account. Fortunately the reserved space on a filesystem can be adjusted using tune2fs. From tune2fs' man page -

Code: Select all

       -m reserved-blocks-percentage
              Set the percentage of the file system which may only be allocated
              by privileged processes.   Reserving some number of  file  system
              blocks for use by privileged processes is done to avoid file sys‐
              tem  fragmentation,  and  to  allow  system daemons, such as sys‐
              logd(8), to continue to function correctly  after  non-privileged
              processes  are  prevented  from writing to the file system.  Nor‐
              mally, the default percentage of reserved blocks is 5%.
so on my 512GB root partition that would be about 25GB of space on the drive that is only accessible by root. As mentioned jounalctl is limited to 4GB so that's a fair bit of wasted space. Here's what I did -

Code: Select all

wizard@laptop 15:09:14 $ sudo tune2fs -m 1 /dev/nvme0n1p2
[sudo] password for wizard: 
tune2fs 1.47.2 (1-Jan-2025)
Setting reserved blocks percentage to 1% (1249047 blocks)
wizard@laptop 15:09:30 $ 
which set the reserved percentage at 1% (about 5GB). If you've got a really big root partition decimals are supported so -m 0.5 would also work if you prefer.

For non-root partitions there may not be need for reserved space at all - such as on my backup media so I can do

Code: Select all

wizard@server 15:12:10 $ sudo tune2fs -m 0 /dev/sda1
[sudo] password for wizard: 
tune2fs 1.47.2 (1-Jan-2025)
Setting reserved blocks percentage to 0% (0 blocks)
wizard@server 15:12:38 $ 
If you wanted to check how much disk space is reserved for root a quick and dirty way to do it would be with tune2fs -l and browse its output or if you wanted to just see reserved space you could do

Code: Select all

wizard@laptop 15:09:30 $ sudo tune2fs -l /dev/nvme0n1p2 | grep "Reserved block count\|Block size"
Reserved block count:     1249047
Block size:               4096
wizard@laptop 15:15:13 $ 
If you multiply reserved block count by block size you get reserved space in bytes.

Hope this gives folks some ideas :)
we see things not as they are, but as we are.
-- anais nin

Post Reply