2

If you are on a Linux machine and have a file system with activated user-quota, you can check via the following commands that quotacheck counts files multiple times if they can be reached via bind-mounts (if source & target of these bind-mounts both reside on the file system that quotacheck visits):

# we assume /home has active user-quota
repquota /home # check used quota before changes
mkdir /home/test_user/dir
mkdir /home/other_dir
mount -o bind /home/test_user/dir /home/other_dir
head -c1000000 /dev/urandom > /home/test_user/dir/test
chown test_user /home/test_user/dir/test
repquota /home # repquota now reports 1000000 bytes more for test_user
# umount /home/test_user/dir # possible solution
quotaoff -a
quotacheck -vuam
quotaon -a
# mount -o bind /home/test_user/dir /home/other_dir # possible solution
repquota /home # repquota now reports 2000000 bytes more for test_user

The only solution I can think of is to umount all bind-mounted directories before executing the quotacheck and remount them afterwards. Are there any other solutions? Removing the usrquota-option from the bind-mounted directories does not seem to work (not surprised, don't bother explaining it). And excluding some directories from being visited by quotacheck does not seem to be possible (man page does not mention any relevant option). By the way, I tested this on Debian 8 (Kernel 3.16.0, quota 4.01).

Clarification: Apart from the bind-mounts, everything under /home belongs to a single file system.

1

It turns out there was a bug in quotacheck. I submitted a patch to fix it, but have no clue when (or even if) a new version of quota including that patch will be published. Directly attaching files to my answer does not seem to be possible, so I will not post the patch here. But if someone is interested, make a comment and I will post the patch as a code block.

EDIT: My patch was not accepted, because it was beside the point. quotacheck is already able to work correctly in the presence of bind-mounts when compiled with the EXT2_DIRECT option and used on ext file systems. Unfortunately a bug prevented that from working on ext4 file systems, which the author has now fixed (commit 2b3795805c8d1bd8873b046508777fa6e9a5c83d in git://git.code.sf.net/p/linuxquota/code ).

0

You have a very interesting problem. It looks there isn't any option for quotacheck to ignore the directories. Probably you will need to change the quotacheck job and run it for each volume ignoring the binded ones. You can get the list of binded volumes with findmnt with something like:

findmnt | awk '$2 ~ /\[.*\]$/'

So probably your cron job could be something like

findmnt --noheadings --raw | awk '$2 !~ /\[.*\]$/ {print$1}'  | while read FS ; do quotacheck -vum $FS ; done

It doesn't look like a very elegant way of doing it and I believe it won't work if the bind mount lives in a directory that you are going to check, but unfortunately I don't know another way of giving a list of directories to ignore.

  • Unfortunately, that doesn't work. Everything under /home is one file system and the bind-mounts have both their source and their target on that file system. I've added a clarification. – user2845840 May 30 '16 at 18:47
0

It turns out that the current stable Debian (stretch) suffers from this bug, too. Luckily, it's easy to recompile the "quota" package and patch it:

# follow this tutorial: https://wiki.debian.org/BuildingTutorial#Rebuild_without_changes

apt-get source quota
apt-get build-dep quota
apt-get install devscripts
cd quota-4.03/

# this package uses "quilt" for patches, follow a different tutorial for "quilt":
#   https://wiki.debian.org/UsingQuilt#Using_quilt_with_Debian_source_packages

export QUILT_PATCHES=debian/patches
export QUILT_REFRESH_ARGS="-p ab --no-timestamps --no-index"
quilt push -a
quilt new quotacheck_ext4_direct.diff
quilt add quotacheck.c
vi quotacheck.c
    # https://marc.info/?l=fedora-extras-commits&m=147878735423631&w=2
    # add "!strcmp(mnt->me_type, MNTTYPE_EXT4)"
quilt refresh
quilt pop -a

# return to the original tutorial: https://wiki.debian.org/BuildingTutorial#Rebuild_without_changes

dch -n # enter something in the changelog
debuild -b -uc -us

The diff file should look like this:

$ cat debian/patches/quotacheck_ext4_direct.diff

Index: quota-4.03/quotacheck.c
===================================================================
--- quota-4.03.orig/quotacheck.c
+++ quota-4.03/quotacheck.c
@@ -959,7 +959,7 @@ Please stop all programs writing to file
 start_scan:
        debug(FL_VERBOSE | FL_DEBUG, _("Scanning %s [%s] "), mnt->me_devname, mnt->me_dir);
 #if defined(EXT2_DIRECT)
-       if (!strcmp(mnt->me_type, MNTTYPE_EXT2) || !strcmp(mnt->me_type, MNTTYPE_EXT3) || !strcmp(mnt->me_type, MNTTYPE_NEXT3)) {
+       if (!strcmp(mnt->me_type, MNTTYPE_EXT2) || !strcmp(mnt->me_type, MNTTYPE_EXT3) || !strcmp(mnt->me_type, MNTTYPE_NEXT3) || !strcmp(mnt->me_type, MNTTYPE_EXT4)) {
                if ((failed = ext2_direct_scan(mnt->me_devname)) < 0)
                        goto out;
        }

Finally, you install the new package using dpkg -i and force a quota recalculation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.