Blog IndexPosts by TagHome

ZFS (on Linux) Quotas over NFS

Posted <2019-02-12 Tue 21:57> by Aaron S. Jackson.

I'll start by saying this is a bit of a hack.

The quota tools for Linux has absolutely no knowledge about ZFS quotas, nor does rquotad, and hence clients mounting via NFS are also unable to obtain this information. I had to find a way to work around this.

We have two ZFS pools, db and home. So, to begin with, I have the following entries in root's crontab.

* * * * * /usr/sbin/zfs userspace -npH home > /home/.quota 2>/dev/null
* * * * * /usr/sbin/zfs userspace -npH db > /db/.quota 2>/dev/null

This dumps ZFS userspace (i.e. quota) information to a dot file on each pool. In the global bashrc file on the login node, I have the following bash function.

function quota () {
echo -n "Quotas:"
cat /home/.quota | \
    awk -F'\t' '$2 == '$(id -u)' { print $3 "\n" $4 }' | \
    numfmt --to=iec | \
    tr '\n' ' ' | \
    awk '{ print " home: " $1 " used of " $2 }'
cat /db/.quota | \
    awk -F'\t' '$2 == '$(id -u)' { print $3 "\n" $4 }' | \
    numfmt --to=iec | \
    tr '\n' ' ' | \
    awk '{ print "          db: " $1 " used of " $2 }'
}

It isn't very pretty, but it does do the job. The output looks like this:

Quotas: home: 759G used of 3.0T
          db: 355G used of 3.0T

Not too bad for a quick hack :) Worth mentioning that if the quota is exceeded, you will still receive the usual "Disk quota exceeded" message.

Wanting to leave a comment?

Comments and feedback are welcome by email (aaron@nospam-aaronsplace.co.uk).

Related posts:

Tags: hacks

Blog IndexPosts by TagHome

Copyright 2007-2022 Aaron S. Jackson (compiled: Sun 2 Jan 00:24:09 GMT 2022)