Loïc Doubinine | Zed

Developer, Architect, DevOps and Site Reliability Engineer

Avatar
  • Posts
  • Socials
  • Tags
  • My story
  • Who am I
  • One command to win 1.2To of free space

    3 minutes read 592 words Linux - Ext4 - Tech

    TL;DR:

    Ext4 partitions reserve 5% of the volume to ensure enough free space is always available. I have tuned my ext4 filesystem to reduce reserved space from 5% to 0.05% to maximise usage on a multi Terabytes volume. For that I use the following command

    sudo tune2fs -m 0.05 /dev/vda
    

    I have NAS

    I have a personal NAS that I manage myself. No TrueNAS or anything pre-made. I manage it myself on a computer. It’s a Debian based distribution (proxmox to be exact) with hardware RAID drives attached.

    I have a big LVM volume with an ext4 partition where I put all my files inside. I have this exact volume for 3-4 years now. It grew whenever I add drives to it. From few TeraBytes it is 24To large now.

    I have a monitoring in place to follow its usage. And you guessed it, empty drive space does stay empty very long.

    A gauge showing that the cargo volume is full red at 97.2%
    Cargo is full

    As I’m not able to grow any Simoleon Tree at my place. I cannot add drive endlessly.

    A Sims2 money tree
    Sims 2 money tree

    I perform some cleaning on a regular basis to try to keep the used space under control. I mostly delete anything not relevant anymore. From Movies files to project dataset I abandoned I can sometimes free multiple Terabytes of data.

    Cleaning day

    Today was cleaning day. After doing the usual stuff, I go on the recycle bin to permanently delete some dangling files. I do a df on the server to check free space after that and find odd values.

    Results of the `df` command showing size=24T, used=20T, Available=2.4T use=90%
    df before

    Who did steal my 1.2To ?

    I check with a reliable calculator (my brain isn’t) and yes: 24-20=4 not 2.4. I know there is always some loss in filesystem to hold for maps, journals, or whatnot. But 1.6To seems excessive.

    After some search on the great library of Internet, I found that ext4 filesystem, by default, reserve a small portion of any partition made to ensure there is always free space on a volume.

    This seems at the utmost importance for system partitions because no space mean no shell. Believe me, I’m old enough to have worked on ancient system that did not have any protection in this regard, and it was a real challenge to get a shell on those computers. (considering you do not have physical access to it, of course)

    Another usage of this reserved space is to fight against fragmentation. As I’m running on HardDrive and not SSD, Fragmentation is still a thing I need to consider. My volume is for cold storage mostly. I have some hot files that change a lot, but they represent a minimal amount of the total data on the drives. Fragmentation should be low.

    Get my terabyte back

    As I don’t have a real usage of this reserved space, It is safe for me to remove it or at least reduce it a lot. So let’s go. Simply run the following command and done

    sudo tune2fs -m 0.05 /dev/vda
    

    And voilà !

    command `sudo tune2fs -m 0.05 /dev/vda` and results of the `df` command showing size=24T, used=20T, Available=3.6T use=86%
    df after
    A gauge showing that the cargo volume is not full anymore at 85.1%
    Cargo is not full anymore

    So what ?

    I manage my NAS by hand, and learn with it. Today I learned. Goal achieved.

    Thanks reading me,
    Bisoux 😗

    Although commenting is not an option on this blog, I am open to discussing this topic further on various social media platforms. You can follow those links to find me

    Twitter logo @ztec@mamot.fr Twitter logo @ztec6 Bluesky logo @ztec.fr