Before you start
Objectives: Learn what are quotas, and how to configure quotas on Ubuntu machine.
Prerequisites: no prerequisites.
Key terms: quota, Ubuntu, configuration
Quotas limit the amount of space users and groups have available for either the number of files and directories they can create or the total size of all their files and directories. File system quotas in Linux can be tracked on per user or per group basis. Also, quotas are provided per volume basis. Also, in Linux we can set soft and hard limits. Soft limits allows the user to extend the limit during the grace period, while the hard limit is a fixed limit.
Before we start configuring quotas, we have to install required packages, and those are quota andquotatool. In Ubuntu, to install them we will run the command # apt-get install quota quotatool. (we have to have root privileges to do this, so we use sudo together with the command in our example). Comands which need root will be indicated with #.
To enable file system quotas we first need to edit file system tables (fstab file), which is located in /etc/folder. In our case we will use gedit to edit the file, so we will enter # gedit /etc/fstab command in our terminal. Next, we will modify the mountpoint line for “/”. In our case the line is “UUID=c9f9c5f9-4c48-4029-8d43-c06777b83c95 / ext4 errors=remount-ro 0 1”. We have to add “,usrquota,grpquota” to the options section in that line, like this:
Edited Line in /etc/fstab File
By doing this we have enabled both user and group quotas. We could just enable user quotas (usrquota), or just group quotas (grpquota) if we wanted to. The next thing we have to do is remount our / partition. To do that we will enter the command # mount -o remount /
Note that if we type the mount command, we will see that our / volume is now mounted with usrquota and grpquota support. Now that we have enabled quotas at mount time, we need to turn quotas on and off. Before we can do that, we need to create two special quota tracking files. For every volume that has quota enabled, we have to have these files on that volume. Those files are “aquota.user” and “aquota.group”. To create those files easily, we can use the “quotacheck” tool together with “-acugm” options. The -a option means that it will check quota on all volumes, c means that it will skip reading existing quotas and just create new ones, u means that it will track user quotas, g stands for group quotas, and m will force the check.
Now if we list files in /, we will see those new quota tracking files. The next thing is to turn the quota system on, and to do that we will enter the quotaon command together with options “-vaug”. The option -v means verbose mode, a means all volumes, u stands for user quotas, and g for group quotas.
Quota Tracking Files
At this time the quotas are being tracked, but there are no limitations set yet. So now we need to edit quotas and change the values. To do that we can use edquota command. We need to specify the username of the user for which we want to edit quota. In our example the user will be “demo5”. So the whole command is # edquota demo5. This actually opens up the quota tracking file in the system default editor, and in our case the editor is nano.
edquota and nano
Note that the columns are not aligned, and the reason for that is that the string for the filesystem is big. However, we can easily count the columns and values in them by counting the space between the values (the space is the delimiter). So, here we can edit the values that are being recorded for “demo5” user. We can see the file system for which the quota is set, and if we had multiple of those, we would see them all here. In that case we could set different quotas on different volumes. The areas we can limit are blocks, soft, hard; and inodes, soft, hard. So, there are two different ways in which we can limit the amount of information stored. We can limit it based on the actual amount of disk space, and this is done with the blocks section. The second way is to use inodes, which stands for number of files the user can create. The “soft” and “hard” are the soft and hard limits. The soft limit is the maximum amount of storage space (blocks or inodes) that they can use, and this is used together with the grace period. If the user exceeds the limit inside of the grace period, the user will get a warning about the limit and will have time to go below the limit during the grace period. The hard limit is the absolute limit, and the user can’t go beyond that limit. In our example we will set the blocks limit. We will set 2000 block for soft limit, and 4000 for hard limit. Note that the blocks column is currently 32 and that is the number of blocks the “user5” is currently using.
When we save the file, the limits are set for user “demo5”. To take a look at the quota we can use #repquota to report on the quota usage. We can use the “-a” option to show quota for all users.
As we can see, the quota has been set to soft 2000 blocks, and hard to 4000 blocks. As the user “demo5” starts creating new files and once he reaches the quota limit, the system will forbid the user from creating new files. Let’s try this out. We will log in as a demo5 user, and to do that we can simply enter the command “su – demo5″, and then enter the password for demo5 user. Next, we will try to download some large file from the Internet. In our example we will try to downoload webmin app, and to do that we will use the command “wgethttp://prdownloads.sourceforge.net/webadmin/webmin_1.730_all.deb”. Doing this, at one point we get a warning that the sytem can’t write the downloaded file because the disk quota exceeded.
Quota Exceeded Example
If we take a look at the quotas using the repquota -a again, we see that the demo5 user reached the hard block quota that we have set.
And that’s it, now we know that quota system is working. If we ever want to check the user quota, we can simply enter “quota” command, and this will return the user’s quota. If we use the “-u” option and a username, we can view the quota of another user. For example, if we enter “quota -u demo5” we will get a quota for demo5 user.