Linux quota all users

How to use Quota on Ubuntu

A Quota is a built-in feature of the Linux kernel that is used to set a limit of how much disk space a user or a group can use. It is also used to limit the maximum number of files a user or a group can create on Linux. The filesystem where you want to use quota must also support quota. Some of the filesystems that support quota on Linux are ext2, ext3, ext4, xfs, etc.

In this article, I will show you how to use quota in a multi-user environment on Ubuntu. So, let’s get started.

Installing Quota Management Utilities on Ubuntu:

On Ubuntu/Debian, you can install the quota package from the official package repository of Ubuntu/Debian. The quota package installs the required programs, which are essential to work with quotas.

First, update the APT package repository cache with the following command:

Now, install the quota package with the following command:

Now, press y and then press Enter>.

The quota package should be installed.

Enabling Filesystem Quota:

As I told you, that there are 2 types of quota; user quota and group quota. You can enable either of the quota or both, depending on your need.

To permanently enable quota on a filesystem, open /etc/fstab file with the following command:

Now, add usrquota and/or grpquota options in the options field (4th) of the filesystem which you want to enable quota in the /etc/fstab file. Once you’re done, save the file by pressing + x followed by y and then press Enter>.

NOTE: To enable user quota, use the usrquota option only. If you want to enable the group data alone, use the grpquota option. To enable both user and group quota, use the usrquota,grpquota option.

Now, reboot your computer for the changes to take effect.

If you just want to try out quota, then you can use the mount command to temporarily enable quota on a filesystem.

To temporarily enable quota on the root filesystem, run the following command:

Initializing Quota on Filesystems:

To ready the filesystem for quota, you have to run the quotacheck command on each of the filesystems you want to use quota.

Let’s say you want to use only user quota on the root (/) filesystem. To do that, initialize quota as follows:

If you want to use group quota only, then the command would be,

Читайте также:  Install driver linux modprobe

If you want to use both user and group quota, then run the following command:

Now, turn on quota on the root (/) filesystem with the following command:

As you can see, the quota is turned on.

If for some reason, you decide to turn off quota, then you can do so with the following command:

Working with User Quota:

Now, let’s say you want to add disk quota for the user bob. To do that, run the following command:

You should see the following window.

Here are some terms that you should know.

Filesystem: It is the disk partition where this quota is to be applied. In my case, it’s /dev/sda2, the root (/) filesystem partition. Don’t try to change it.

Blocks: This is the amount of disk space (in blocks) the user bob can use.

You can’t use MB or GB unit here directly. You have to convert MB or GB unit to the equivalent block size and use the block size here. 1 block is equal to 1 KB or 1024 bytes.

Let’s say you want to let the user bob use only 1 GB of disk space. You need to convert GB or MB to a KB unit.

So, 1 GB = 1024 MB = 1024 * 1024 KB.

How many blocks in 1 GB? Well, (1024 * 1024 KB / 1 KB) = 1048576 blocks for each GB unit.

There are 1048576 blocks for each GB unit.

So, for 5 GB of disk space, the block size is 5 * 1048576 = 5242880 blocks.

Inode: It is the number of files you can create in a filesystem. So, if the user bob is allowed to have 1000 inodes, he can only create 1000 files or directories. Even if the total size of 1000 files or directories is less than the number of blocks he can use, he won’t be able to create any new files or directories. So, I would keep it a little high.

A good measure is keeping it about 60-70% of the total block size.

So, for a block size of 1048576, a good enough inode number is 629,146 or 734,004.

Soft and Hard Limit: Both block and inode can have a soft and a hard limit. A user or group can exceed the soft limit for a certain number of days, called a grace period. But by no means are they allowed to exceed the hard limit. You can put 0 for the soft limit to disable the soft limit if you want. In this case, only the hard limit will be used.

NOTE: You should only set the soft and hard limits. Don’t modify the values of the blocks and inode columns. They represent the blocks and inodes that the user is currently using.

I set the quota for the user bob as follows. Once you’re done, save the file. The quota should be applied.

Working with Group Quota:

To set a group quota for the group www-data (let’s say), run the following command:

Читайте также:  Узнать версию платформы 1с linux

Now, you can set group quota the same way as user quota.

Changing Grace Period:

To change the grace period for the soft limit, run the following command:

Now, change the number of days for block and inode grace period depending on your need. Once you’re done, save the file.

Generating Quota Reports:

To generate quota usage reports, run the following command:

As you can see, the user and group quota report is generated.

If you only want to generate user quota reports, run the following command:

In the same way, if you only want to generate group quota reports, run the following command:

So, that’s how you use quota on Ubuntu. Thanks for reading this article.

About the author

Shahriar Shovon

Freelancer & Linux System Administrator. Also loves Web API development with Node.js and JavaScript. I was born in Bangladesh. I am currently studying Electronics and Communication Engineering at Khulna University of Engineering & Technology (KUET), one of the demanding public engineering universities of Bangladesh.

Linux Hint LLC, editor@linuxhint.com
1309 S Mary Ave Suite 210, Sunnyvale, CA 94087
Privacy Policy and Terms of Use

Источник

Disk quota

«A disk quota is a limit set by a system administrator that restricts certain aspects of file system usage on modern operating systems. The function of setting quotas to disks is to allocate limited disk-space in a reasonable way.«

This article covers the installation and setup of disk quota.

Installation

Configuration

Set up the filesystem

Edit fstab to enable the quota mount option(s) on selected file systems, e.g.:

/dev/sda3 /home ext4 defaults,usrquota 0 2

To additionally enable the group quota mount option:

/dev/sda3 /home ext4 defaults,usrquota,grpquota 0 2

If supported by the kernel and file system it is recommended to use journaled quota instead:

/dev/sda3 /home ext4 defaults,usrjquota=aquota.user,jqfmt=vfsv1 0 2

Append grpjquota=aquota.group to enable group quota.

Remount the partition to apply the change:

Create quota index

To create the quota index for /home :

Append the -g parameter to also create a group index.

To enable disk quotas for the desired file system:

To disable disk quotas for the file system:

Usage

Enable quota for user/group

  • To find out how many 1 kilobyte blocks are there for a partition use $ df .
  • You may use a online bytes converter to calculate the correct amount of blocks [1].
  • The command # setquota may be used as an alternative of # edquota [2].

Quotas are configured using edquota (as the root user) that will be opened in the default configured text editor:

Disk quotas for user user (uid 1000): Filesystem blocks soft hard inodes soft hard /dev/sda3 24 0 0 6 0 0

blocks Indicates number of 1k blocks currently used by the user/group. soft Indicates max number of blocks for the user/group before a warning is issued and grace period countdown begins. If set to «0» (zero) then no limit is enforced. hard Indicates max number of blocks for the user/group can use. If maximum amount has been reached, no further disk space can be used. If set to «0» (zero) then no limit is enforced. inodes Indicates the current inodes amount used by the user/group. soft Indicates the soft inode limit for the user/group. hard Indicates the hard inode limit for the user/group.

Читайте также:  Каково главное отличие суперпользователя от остальных пользователей linux

Consider the following configuration for ftpuser1:

Disk quotas for user ftpuser1 (uid 1000): Filesystem blocks soft hard inodes soft hard /dev/sda3 24 1000000 1048576 6 0 0

In this case if ftpuser1 uses over 976MB of space a warning will be issued. If the hard limit of 1GB has been reached the user will be unable to write any more data.

See #Specify a grace period to give users a specific amount of time to reduce storage usage when they hit their soft limit.

Warning: The hard limit applies to all files written by and for the respective user/group, including temporary files by started applications, which may crash at this point.

Specify a grace period

To give current users some time to reduce their file usage, a grace period can be configured. This specifies the allowed time a user/group can exceed their soft limit and while under their hard limit:

Grace period before enforcing soft limits for users: Time units may be: days, hours, minutes, or seconds Filesystem Block grace period Inode grace period /dev/sda3 7days 7days

The grace period can be set in seconds, minutes, hours, days, weeks or months.

Reports

Shows all configured quotas:

Shows quotas on a specific partition:

Show quotas that apply to a user/user group:

Copy quota settings

To one or several users

To copy quota settings from user1 to user2 :

# edquota -p user1 user2 

To copy quota settings to several other users, append user3 user4 .

To groups

To copy quota settings from group1 to group2 :

# edquota -g -p group1 group2 

To all users

The idea is to modify the quota settings for one user and copy the setting to all other users. Set the quota for user1 and apply the quota to users with a UID greater than 999:

# edquota -p user1 $(awk -F: '$3 > 999 ' /etc/passwd)

Tips and tricks

Quota warnings

The command warnquota can be used to warn the users about their quota. Configuration is available in /etc/warnquota.conf .

Stats

The command quotastats can be used to give more information about the current quota usage:

Number of dquot lookups: 101289 Number of dquot drops: 101271 Number of still active inodes with quota : 18 Number of dquot reads: 93 Number of dquot writes: 2077 Number of quotafile syncs: 134518740 Number of dquot cache hits: 7391 Number of allocated dquots: 90 Number of free dquots: 2036 Number of in use dquot entries (user/group): -1946

See also

Источник

Оцените статью
Adblock
detector