26 C
Monday, April 12, 2021

How to Use Quota on Ubuntu? – Linux Hint

Must read

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 <Ctrl> + 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:

$ sudo mount -o remount,usrquota,grpquota /

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,

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

$ sudo quotacheck -cugm /

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.

Easy right?

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:

$ sudo edquota -g www-data

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.

Source link

- Advertisement -

More articles


Please enter your comment!
Please enter your name here

Latest article