So I needed to do per-directory hard quotas for my users. Luckily, xfs supports “project” quotas which allow a directory hierarchy to be soft or hard limited.

To set this up for a user, lets call him derpface:

  1. Add the option “pquota” to fstab so the xfs partition gets mounted with project quotas enabled.

  2. Run the following commands to setup the project and directory declarations:

    mkdir /srv/derpface echo 1600:/srv/derpface >> /etc/projects echo derpface:1600 >> /etc/projid
    

    Note that the “1600? is merely a project id. I would use the UID or something unique to that user. I’m also using the username as the project name in this example to make things simpler.

  3. And now tell xfs to enable and apply a certain limit to the project.

    xfs_quota -x -c 'project -s derpface' /srv 
    xfs_quota -x -c 'limit -p bhard=300g derpface' /srv
    
  4. Done:) View your hard work with the following status command:

    xfs_quota -x -c "report -h" /srv
    

Note that if you were to bind mount this directory “/srv/derpface”, like for example, in a docker container, it would show as a 300GB volume

Thanks oracle!

PS: If you ever want to modify the quota, just re-run the command with the modified storage allowance:

xfs_quota -x -c 'limit -p bhard=600g derpface' /srv
Blog Logo

Mario Loria


Published

Image

./scriptthe.net

Because 127.0.0.1 gets old after a while.

Back to Overview