Quota is a built-in Linux kernel function that is used to set the limit on disk space that a user or group can use. It is also used to limit the maximum number of files a user or group can create on Linux. The file system on which you want to use the quota must also support the quota. Some filesystems that support quotas on Linux are ext2, ext3, ext4, xfs, etc.
In this article, we will show you how to use quota in a multi-user Ubuntu environment. So let’s get started.
Installing the quota management utilities on Ubuntu:
On Ubuntu / Debian, you can install the quota package from the official Ubuntu / Debian package repository. The quota package installs the prerequisites required to work with quotas.
First, update the APT package repository cache with the following command:
$ sudo apt update
Now install the quota package using the following command:
$ sudo apt install quota
Enabling file system quota:
As we said, there are 2 types of quotas; user quota and group quota. You can enable either or both of these quotas, depending on your needs.
To permanently enable quota on the file system, open the / etc / fstab file with the following command:
$ sudo nano /etc/fstab
Now add the usrquota and / or grpquota options to the options field of the filesystem for which you want to enable quota in the / etc / fstab file. When you’re done, save the file by pressing
Note To enable user quota, use only the usrquota parameter. If you only want to include these groups, use the grpquota option. To enable both user and group quota, use the usrquota, grpquota parameter.
Now restart your computer for the changes to take effect.
$ sudo reboot
If you just want to try out a quota, you can use the mount command to temporarily enable quota on the filesystem. To temporarily enable quota on the root filesystem, run the following command:
$ sudo mount -o remount,usrquota,grpquota /
Initializing quota on file systems:
To prepare a filesystem for a quota, you must run the quotacheck command for each filesystem that you want to use a quota.
Let’s say you only want to use a custom quota on the root (/) filesystem. To do this, initialize the quota as follows:
$ sudo quotacheck -cum /
If you only want to use the group quota, then the command would be like this:
$ sudo quotacheck -cgm /
If you want to use both user and group quota, run the following command:
$ sudo quotacheck -cugm /
Now enable quota on the root (/) filesystem with the following command:
$ sudo quotaon -v /
If for some reason you decide to disable the quota, you can do it with the following command:
$ sudo quotaoff -v /
Working with custom quota:
Now, suppose you want to add a disk quota for the user andreyex. To do this, run the following command:
$ sudo edquota -u andreyex
Here are a few terms you should know.
Filesystem: This is the partition of the disk to which this quota should apply. In my case, this is / dev / sda2, the partition of the root (/) filesystem. Don’t try to change that.
Blocks: This is the amount of disk space (in blocks) that can be used by the user.
You cannot directly use MB or GB here. You have to convert the units of MB or GB to an equivalent block size and use the block size here. 1 block is equal to 1 KB or 1024 bytes.
Let’s say you want user grayex to only use 1 GB of disk space. You need to convert GB or MB to KB units.
So 1 GB = 1024 MB = 1024 * 1024 KB.
How many blocks are there in 1 GB? So (1024 * 1024 KB / 1 KB) = 1,048,576 blocks for each GB unit.
There are 1,048,576 blocks for every GB unit.
So, for 5 GB of disk space, the block size is 5 * 1048576 = 5242880 blocks.
Note this is the number of files you can create on the file system. So, if the user is allowed to have 1000 indexes, 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 it can use, it will not be able to create any new files or directories. So we would keep it a little higher.
A good measure is to keep around 60-70% of the total block size.
So, for a block size of 1048576, a good inode number of 629146 or 734004 is sufficient.
Hard and soft constraints: Both a block and an inode can be soft and hard constrained. A user or group can exceed the soft limit for a specified number of days, called a grace period. But in no case should they exceed the hard limit. You can set the soft cap to 0 to turn it off if you like. In this case, only the hard limit will be used.
Note You should only set soft and hard limits. Do not change the values of blocks and inode columns. They represent the blocks and indexes that the user is currently using.
We have set the quota for the user andreyex as follows. Once you’re done, save the file. The quota must be applied.
Working with group quota:
To set a group quota for group www data (say) run the following command:
$ sudo edquota -g www-data
You can now set a group quota in the same way as a custom quota.
Change of grace period:
To change the grace period for the soft limit, run the following command:
$ sudo edquota -t
Now change the number of days for the lock grace period and inode depending on your needs. Once you’re done, save the file.
Generating Quota Reports:
To generate quota usage reports, run the following command:
$ sudo repquota -aug
As you can see, the user and group quota report has been generated.
If you only want to generate custom quotas reports, run the following command:
$ sudo repquota -au
Likewise, if you want to generate reports on group quotas, run the following command:
$ sudo repquota -ag
So, this is how you use quota in Ubuntu. Thanks for reading this article.
Please disable your ad blocker or whitelist this site!