Linux – Trying to grok Linux quotas, where is the data stored

disk-space-utilizationext3linuxquota

So all the tutorials and documentation for the Linux quota system has left me confused. For each filesystem with quotas enabled/on where is the actual quota information stored? Is it filesystem metadata or is it in a file?

Say user foo creates a new file on /home. How does the kernel determine whether user foo is below their hard limit? Does the kernel have to tally up quota information on that filesystem each time or is it in the superblock or somewhere else?

As far as I understand, the kernel consults the aquota.user file for the actual rules, but where is the current quota usage data stored? Can this be viewed with any tools outside repquota and the like? TIA!!

Update:

Thanks for the help. I had already read that mini-HOWTO. I am pretty clear on the usage of the user space tools. What I was unclear on is whether the usage data was ALSO in the file that stored per-user limits and you answered this with a yes.

From what I can tell, rc.sysinit runs quotacheck and quotaon on startup. The quotacheck program analyzes the filesystem, updates the aquota.* files. It then makes use of quota.h and the quotactl() syscall to inform the kernel of quota info.

From this point forward the kernel hashes that information and increments/decrements quota stats as changes occur. Upon shutdown, the init.d/halt script runs the quotaoff command RIGHT before the filesystems are unmounted. The quotaoff command does not appear to update the aquota.* files with the information the kernel has in memory. I say this because the {a,c,m}times for the aquota.user file are only updated upon a reboot of the system or by manual running the quotacheck command. It appears – as far as I can tell – that the kernel just drops it's up-to-date usage data on the floor at shutdown. This information is never used to update the aquota.* files. They are updated during startup by quotacheck(rc.sysinit). Seems silly to me since that updated info had already been collected by the kernel. So…in conclusion I am still not entirely clear on the methods. 😉

Best Answer

For each filesystem with quotas enabled/on where is the actual quota information stored?

See e.g. the quotaon manpage. There will be files named .quota* in the filesystem root directory, which contain the necessary information (.quota.user,.quota.group, .quota.ops.user, .quota.ops.group).

Say user foo creates a new file on /home. How does the kernel determine whether user foo is below their hard limit? Does the kernel have to tally up quota information on that filesystem each time or is it in the superblock or somewhere else?

No, the kernel continually tracks fs usage, so it does not need to recalculate that on each allocation (which would be prohibitively expensive). It will do the calculation once when quotas are enabled, and then update that. The initial calculation is performed by quotacheck.

As far as I understand, the kernel consults the aquota.user file for the actual rules, but where is the current quota usage data stored? Can this be viewed with any tools outside repquota and the like? TIA!!

Quota information is stored in .quota* (see above). I'm not aware of any tools to generate quota usage reports, apart from repquota. But you should be able to generate most reports using/scripting repquota. Or you'll have to hack the source...

BTW:

The Quota mini-HOWTO give a good overview over the Linux quota system. It's a bit dated, but the fundamentals have not changed much.