Home / Alt manpages / quotasync(1)

  • quotasync(1)
  • User command
  • linux

Flush Linux Quotas to Disk with quotasync

quotasync pushes the kernel's in-memory quota usage and limits out to the quota files on disk. This guide covers flushing selected filesystems and checking the sync worked, useful before reading quotas with a file parser such as repquota. Allow about five minutes for a single known mount point, plus time to identify the correct quota scope.

The examples assume the quota package is installed and that you can use sudo when the mounted filesystem requires it.

Checkpoint

This command synchronises accounting data. It does not enable quotas, create quota files, scan a filesystem, or edit individual limits. Keep quotacheck, quotaon and quota-editing commands as separate operations.

1. Confirm the installed command

Check the executable and version before copying an example into a script. On the machine used for this guide, the package is quota 4.06-1build6 and the program reports quota utilities version 4.06. Option names and diagnostic wording can differ on another release, so record the version alongside whatever you are troubleshooting.

$ command -v quotasync
/usr/bin/quotasync
$ quotasync --version
Quota utilities version 4.06.
Compiled with: USE_LDAP_MAIL_LOOKUP EXT2_DIRECT HOSTS_ACCESS RPC RPC_SETQUOTA BSD_BEHAVIOUR
$ quotasync --help
quotasync: Utility for syncing quotas.
Usage: quotasync [-ugP] mount-point...
   or: quotasync [-ugP] -a

Reading the version and help text normally needs no elevated privilege. The help output also gives away the rule people miss: you must name at least one mount point, or use --all.

2. Identify the exact mount point

Use the mount point itself as the argument, not the block device, the quota file, or a directory where an application happens to store data. Inspect the mounted filesystems and choose an exact path that is under quota management:

$ findmnt -o TARGET,SOURCE,FSTYPE,OPTIONS
TARGET SOURCE     FSTYPE OPTIONS
/      /dev/ROOT  ext4   rw,relatime,usrquota,grpquota
/srv   /dev/DATA  xfs    rw,relatime,usrquota,grpquota
$ findmnt -no TARGET /srv
/srv

That output is illustrative, so swap in a mount point from your own host. A quota option on one mount does not automatically apply to every mount, and a bind mount or a directory below a mounted filesystem is not a separate quota target on its own.

Check the mount table again if the path came from a service or automounter:

$ grep -E '^[^#].* /srv ' /proc/mounts /etc/mtab 2>/dev/null
/proc/mounts:/dev/DATA /srv xfs rw,relatime,usrquota,grpquota 0 0

The exact line and option order vary. What you want is an entry whose target matches the path you intend to synchronise. If nothing matches, stop and resolve the mount or quota configuration first.

3. Synchronise user quotas on one mount

Without a scope option, quotasync synchronises user quotas. Spell the scope out explicitly in operational work anyway, so a later edit cannot silently change what a script does:

$ sudo quotasync --user /srv
$ printf 'quotasync exit status: %s\n' "$?"
quotasync exit status: 0

A zero exit status means the requested synchronisation succeeded; the program normally prints nothing else. It writes the current in-memory user usage and limits to the quota data for /srv, it does not print a report.

Required privileges depend on your system's quota implementation and policy. Try without sudo only if your administrator has deliberately granted the access needed. If the unprivileged command fails on a permission error, retrying with sudo may be right, but do not use elevated access to paper over an uncertain mount point.

4. Include group or project quotas deliberately

Pass --group for group usage and limits, or --project for project usage and limits. These are separate requests, so only run the scopes your quota policy actually uses:

$ sudo quotasync --group /srv
$ sudo quotasync --project /srv
$ printf 'last exit status: %s\n' "$?"
last exit status: 0

Do not tack on all three flags just to be thorough. A command can succeed for one scope while another remains unsynchronised, simply because you never asked for it.

For a host with several intended mounts, list them explicitly so the command itself documents its scope:

$ sudo quotasync --user / /srv /home
$ printf 'quotasync exit status: %s\n' "$?"
quotasync exit status: 0

Every path must be an intended mounted filesystem. Keep the original list in the change record, especially if a service depends on quota reporting straight afterwards.

5. Use --all only after reviewing every mount

--all synchronises every filesystem the quota system knows about. It saves maintaining a list, but it also broadens the operation well beyond the filesystem you may have started out investigating:

$ findmnt -o TARGET,SOURCE,FSTYPE,OPTIONS
$ sudo quotasync --user --all
$ printf 'quotasync exit status: %s\n' "$?"
quotasync exit status: 0

Review the mount list and the host's quota policy before reaching for this form. Do not combine --all with mount-point arguments, the documented forms are either --all or one or more named filesystems. If one requested sync fails, quotasync exits non-zero, so check the output and system logs before assuming the whole operation completed.

6. Verify the result with the reader that needed fresh data

The whole reason to run quotasync is often to make a quota-file reader see current values. After a successful flush, run the relevant read-only report against the same scope:

$ sudo quotasync --user /srv
$ sudo repquota /srv
*** Report for user quotas on device /dev/DATA
Block grace time: 7days; Inode grace time: 7days
                        Block limits                File limits
User            used    soft    hard  grace    used  soft  hard  grace
---------------------------------------------------------------
root      123456       0       0              42     0     0

The device, values and table layout are host-specific, and that is not the point. The point is that repquota reads the intended filesystem and returns a report after quotasync returned zero. If the report still looks wrong, check whether you synchronised user, group or project data, and whether the reader is using the same quota format.

7. Diagnose failure without changing configuration

An invalid option or a failed sync produces a non-zero exit status. Capture it immediately, since a later shell command overwrites $?:

$ sudo quotasync --user /path/that/is/not/a/mount
quotasync: cannot find mount point /path/that/is/not/a/mount
$ status=$?
$ printf 'quotasync exit status: %s\n' "$status"
quotasync exit status: 1

The diagnostic text can vary by release. Check the path with findmnt, confirm the quota type is configured, and retry only once you have fixed the actual problem. Do not create or rename aquota.user, aquota.group, quota.user or quota.group as a guessed repair; the manual names them as quota files, but their presence and format depend on the filesystem and quota setup.

Recovery

There is no rollback command here, because synchronisation is not a reversible configuration edit. If a report looks wrong, stop any consumer that would act on it, preserve the diagnostic output, and investigate the quota configuration and recent filesystem changes. Running the correct synchronisation again is the normal recovery once you understand the cause.

Done means

  • You recorded the installed quota version and checked the local option syntax.
  • You selected exact mounted filesystem paths from findmnt.
  • You requested the required user, group or project scope explicitly.
  • quotasync returned exit status 0 for every intended target.
  • A read-only quota report such as repquota now sees the expected filesystem and current data.
  • You did not use --all without reviewing its wider scope.