Flush Linux Quotas to Disk with quotasync
You will flush in-kernel quota usage and limits into the quota files on selected file systems, then check that the synchronisation succeeded. This is 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 file system requires it.
The route
Jump straight to the step you need, or tick off Done means at the end.
- 1. Confirm the installed command
- 2. Identify the exact mount point
- 3. Synchronise user quotas on one mount
- 4. Include group or project quotas deliberately
- 5. Use --all only after reviewing every mount
- 6. Verify the result with the reader that needed fresh data
- 7. Diagnose failure without changing configuration
Checkpoint
This command synchronises accounting data. It does not enable quotas, create quota files, scan a file system, 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 in another release, so record the version with the change 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 exposes the most easily missed rule: you must name at least one mount point, or use --all.
2. Identify the exact mount point
Use the mount point as the argument, not the block device, quota file, or directory where an application happens to store data. Inspect the mounted file systems and choose an exact path that is managed by quotas:
$ 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
The output above is illustrative: replace /srv with a mount point from your own host. Do not assume that a quota-related option on one mount applies to every mount. A bind mount or a directory below a mounted file system is not automatically a separate quota target.
Check the mount table again if the path is supplied by 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. The useful result is an entry whose target is the path you intend to synchronise. If no such entry exists, stop and resolve the mount or quota configuration first.
3. Synchronise user quotas on one mount
Without a scope option, quotasync synchronises user quotas. Make the scope explicit in operational work so a later edit does not silently change the meaning of a script:
$ 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 no success message. The command writes the current in-memory user usage and limits to the quota data associated with /srv; it does not print a report.
Privileges depend on the system's quota implementation and policy. Start without sudo only if your administrator has deliberately granted the required access. If the unprivileged command fails with a permission error, retrying with sudo may be appropriate. Do not use elevated access to compensate for 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 synchronisation requests, so 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 add all three flags merely to be thorough. Use them when the corresponding quota type is configured and meaningful on that file system. A command can complete for one scope while a different scope remains unsynchronised if you did not request it.
For a host with several intended mounts, list them explicitly so the reviewable command shows its scope:
$ sudo quotasync --user / /srv /home
$ printf 'quotasync exit status: %s\n' "$?"
quotasync exit status: 0
Every path must be an intended mounted file system. Keep the original list in the change record, especially when a service depends on quota reporting immediately afterwards.
5. Use --all only after reviewing every mount
--all requests synchronisation on all file systems known to the quota system. It avoids maintaining a list, but it broadens the operation beyond the file system you may have been 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 using this form. Do not combine --all with mount-point arguments; the documented forms are either --all or one or more desired file systems. If one requested synchronisation fails, quotasync exits non-zero, so inspect the command output and system logs before treating the whole operation as complete.
6. Verify the result with the reader that needed fresh data
The main 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. For example:
$ 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. The check is not that these exact numbers appear. It is that repquota reads the intended file system and returns a report after quotasync returned zero. If the report is still unexpected, check whether you synchronised user, group or project data and whether the reader uses the same quota format.
7. Diagnose failure without changing configuration
An invalid option or a failed requested synchronisation produces a non-zero exit status. Capture it immediately, because a later shell command replaces $?:
$ 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 that the quota type is configured, and retry only after correcting the identified problem. Do not create or rename aquota.user, aquota.group, quota.user or quota.group as a guessed repair. The manual identifies those as quota files, but their presence and format depend on the file system and quota setup.
There is no rollback command because this operation is a synchronisation, not a reversible configuration edit. If a report looks wrong, stop consumers that would act on it if necessary, preserve the diagnostic output, and investigate the quota configuration and recent file-system changes. Running the correct synchronisation again is the normal recovery once the cause is understood.
Done means
- You recorded the installed quota version and checked the local option syntax.
- You selected exact mounted file-system paths from
findmnt. - You requested the required user, group or project scope explicitly.
quotasyncreturned exit status 0 for every intended target.- A read-only quota report such as
repquotanow sees the expected file system and current data. - You did not use
--allwithout reviewing its wider scope.