Skip to content

Linux quotas (remove duplicates)

It

is possible to enable quotas on Linux to better manage the use of available disk space. This feature is especially important in multi-user environments, web servers, file servers, e-mail servers, etc.

In quota management, it is possible to define the amount of disk space for each user or group of users.

Quota management must be enabled before we can use this feature.

See the steps to follow: 1) Quota support must be compiled in the Kernel.
2) Edit the /etc/fstab file and add user (usrquota) and group (grpquota) quota management on the desired device.

$ vi /etc/fstab
/dev/hda6 /home ext2 defaults, usrquota, group share 1 2

3) Create the quota.user and quota.group file in the /home directory with the “quotacheck —cug” command and configure the read and write permissions only for the superuser. In some distributions these files have the names aquota.user and aquota.group. These two files will be the databases for user and group quotas respectively.

To create the quota files manually:

$ touch /home/quota.user
$ touch /home/quota.group
$ chmod 600 /home/quota.user
$ chmod 600 /home/quota.group

Or

$ quotacheck -cug

4) Run the quotacheck —avug command to start the newly created database.

5) Verify that the database was started. The quota.user and quota.group files must not be zero in size.

$ ls —lga /home

6) Enable the quota service:

$ quotano -a

7) Make sure that the quota service is enabled on boot. If the file /etc/rc.d/quotas does not exist, create a script file:

$ vi /etc/rc.d/quotas
#! /bin/bash
/sbin/quotaon-avug

Change permissions to 755:

$ chmod 755 /etc/rc.d/quotas

Create the symbolic link to the quota file for runlevel 3 and runlevel 5:

$ ln —s /etc/rc.d/quotas /etc/rc.d/rc3.d/s20quotas
$ ln —s /etc/rc.d/quotas /etc/rc.d/rc5.d/s20quotas

8) Check the quota system once a week by placing the quotacheck command in the root cron:

$ crontab —e
0 3 * * 0 /sbin/quotacheck —avug

Once these steps have been completed, the quota system can be used.

There are four types of quota limits, namely:

  • User hard limit: The physical limit is the total amount of disk space a user can have. The user will not be able to save anything else when this
  • limit is reached; User soft limits: The light limit acts as a warning area. When this limit is reached, the system notifies the user that their disk space is running out. The user may record to disk until the physical limit is reached;
  • Group hard limit: The physical limit per group defines the maximum amount of disk space a group of users can have. If this limit is reached, group users will no longer be able to make recordings even if space is available for a particular user;
  • Group soft limit: It has the same concept as the physical group limit, but works as a warning area.

We can also configure a grace period for quota management so that a user or group that has reached the slight limit can delete some files and remain within the established limits.

Once the time specified in the grace period is exceeded and no action is taken, the slight limit becomes a physical limit, making it impossible for users to work until the situation is actually resolved. This limit can be in minutes, hours, days, weeks, and even months.

Let’s now look at the quota management commands:

Quota command

The quota command shows the disk space quotas configured for a particular user or group and the space used.

Your most frequent options are:

  • -u: Shows the quota defined for a given user (default);
  • -g: Shows the quota defined for a given group;
  • -q: Shows only when the quota is exceeded;
  • -v: Shows the quotas even if none are defined.

Example:

$ share —v uira
Disk quota for user uira (uid 502): Filesystem blks quota limit grace files quota limit grace /dev/hda6 18320 19000 20000 58 0 0

In this example the user uira is using 18320 blocks. The light limit is 19000 blocks and the physical limit is 20000 blocks.

Only the superuser can see the quota of other users. An ordinary user can see their own quota and the quota of the group they are a member of.

Quotaon command

The quotaon command enables quota management on a previously configured device.

The most common options are:

  • -a: Enables quota management for all devices configured for quota control in the /etc/fstab file;
  • -g: Enables quota management for groups on a given device;
  • -u: Enables quota management for users on a given device;
  • -v: Shows all devices where quota management has been enabled.

Example:

$ quotano —avug

Enable user and group quotas for all devices configured to do so in /etc/fstab.

Quotaoff command

This command disables quota management on certain devices.

The options for this command are similar to the quotaon command.

Example:

$ quotaoff —gu /dev/hda6

Quotacheck command

This command scans a given device and builds the quota database files. It is important that this command be executed with certain regularity so that the quota bank is faithful to the reality of the file system.

The options for this command are:

  • -a: Scan all devices configured for quota management in the /etc/fstab file and builds the database for users and groups; -g group: Build the quota database for a given group;
  • -u user: Build the quota database for a given group;
  • -u user: Build the quota database for a given user;
  • -v: Shows all procedures performed by quotacheck.

Example:

$ quotaoff -a
$ quotacheck —aug
$ quotano

If you do not disable quotas for a particular device when running the quotacheck command, the information collected will remain in memory, but the files containing the database will not be updated.

Edquota command

This edquota command edits quotas for users and groups. It uses the vi text editor or another standard text editor to configure disk quotas. The quota configuration file may seem a bit strange, but its configuration is simple.

The options available for the command are:

  • -g: If the -g option is specified, edquotas must take the group name as a parameter;
  • -u: This is the default option for editing user quotas;
  • -p userexample: This option is called proto-user. You can use this option to copy settings from one standard user to another user;
  • -t: This option is to configure the grace period for users or a particular group. It must be combined with the —u or —g option.

Example:

$ deduct —u ira
Quotas per user: uira /dev/hda6: blocks in use: 136, limits (soft = 19000, hard = 20000) Inodes in use: 132, limits (soft = 0, hard = 0)

In this example, the soft limit is 19000 blocks and the physical (hard) limit is 20000.

$ edquota — you
Time units may be: days, hours, minutes, or seconds <br></br>Grace period before enforcing soft limits for users: <br></br>/dev/hda6: block grace period: 15 days.

File grace period: 7 days In this example the grace period is 15 days for blocks and 7 days for files (inodes).

Repquota command

This command creates a report of the quotas and disk usage of the users of a particular device or group.

The options for this command are:

  • -a: Creates a quota report for all devices configured for quota management in the file /etc/fstab;
  • -u: This is the default option, which creates a user usage report;
  • -g: This option reports the use of quotas by group;
  • -v: Creates a descriptive heading for the report.

Example:

$ repshare —va
*** Report for user quotas on /dev/hda6 (/home) Block limits File limits User used soft hard grace used soft hard grace root 718000 0 0 0

Learn much more about Linux in our online course. You can register here. If you already have an account, or want to create one, just log in or create your user here.

Did you like it?

Share