Using the Quota Command Within a Chroot Environment

I was recently using Jailkit on Ubuntu to set up a chroot environment for users of a backup storage server. I wanted to give the users the ability to check their quotas with the regular quota command.

I go about telling Jailkit that the chroot directory will need the quota binary. This should be all that is needed, or so I thought.

Upon checking a quota as a chroot'd user, it barfs the following error,

1
2
3
4
$ quota
quota: Cannot open quotafile /home/aquota.user: Permission denied
quota: Quota file not found or has wrong format.
$

From what I can tell, this is a very misleading error message. The permissions of aquota.user are always 0600, readable / writable only by root. This can't be changed, not even as root. Witness.

1
-rw------- 1 root root 7168 2013-02-27 22:32 /home/bkusers/home/aquota.user

Using a bit of strace and some luck, I find what the quota command is really looking for is /proc/sys/fs/quota.

It simply does a stat() system call on that directory within proc, so if you simply do,

1
$ sudo mkdir -p /home/bkusers/proc/sys/fs/quota

then the quota command works like a charm within the chroot environment.

1
2
3
4
5
$ quota -s
Disk quotas for user testuser (uid 1007):
     Filesystem  blocks   quota   limit   grace   files   quota   limit   grace
       /dev/md3      16       0   3907M               4       0       0
$

My chroot directory in these examples was obviously /home/bkusers, modify accordingly for your needs.

Comments