We can set limitations on disk space usage, called quotas, for either a user or group.
Not only can we set them, but we can also determine how much space a user or group has used on a disk.
You can enable quotas on either EXT4 or XFS formatted storage units.
Quota Installation
Sometimes you may need to install the ‘quotas’ software package.
For CentOS:
For Ubuntu:
Now that we installed the quota software, we are ready to begin.
Enable Quotas
After we install the software, we have the ability for quotas, but we need to enable them. Not only do we specify which drives, but we can also specify which users or groups.
So, to start, we need some users and groups to play with for these examples. Let’s add four users and 2 groups:
You can run these one line at a time or put is in a bash script, make it executable and run it. Don’t forget the ‘shebang’, ‘#!/bin/bash’, at the beginning.
We now have four users: ‘user1’, ‘user2’, ‘user3’ and ‘user4’. The odd numbered users are in a group called ‘odd’ and the even numbered users are in the group ‘even’.
Now, we need to set up a drive to use for quotas. You should have a partition set up as ‘/dev/sdb5’ which we will not use anymore. Use the following commands to use it. Be aware that if you have not followed along with the examples, then you may need to use your own partition that is usable and change the partition name accordingly:
We need to unmount the drive to format it since we cannot if it is currently mounted. We then format it as ‘ext4’ and create a share for mounting the drive to for accessing.
We can then run the command:
Copy the UUID and alphanumeric characters after it. You will edit the ‘/etc/fstab’ and add this UUID to a new line. You’ll also set up the share, format type, and set it to user quotas (usrquota) and group quotas (grpquota), etc. An example:
Your UUID will be different, but the rest should be the same. Save and exit the editor. Run the following code to remount only the drive:
If you list the files in the share, ‘ls /share’. You should see a response of ‘lost+found’. The share is set and ready for quotas.
Before we enable quotas, we need to set up the database to store the quota information. Use the following command:
The ‘-m’ is to make the databases, ‘u’ is for the ‘user’ database and ‘g’ is for the group database. Now, if you run ‘ls -a /share’, there should be two more files listed in the databases. The files are ‘aquota.users’ for the user quota and ‘aquota.group’ for the group quotas.
Now, the quotas are on, but we have not configured.
Configuring and Reporting Quotas
If I look at a report for ‘/share’, I can see that only the user and group ‘root’ have files on the drive. These would be the two databases set up when adding those to the drive. To see the report, use:
Figure 1 shows the report output.
FIGURE 1
The parameter ‘u’ is for ‘users’, ‘ g’ is for ‘group’ and ‘v’ is ‘verbose’.
Now, before setting quotas, there are a few things to cover.
We have ‘soft’ and ‘hard’ limits. ‘Soft’ limits are where you get messages that you have exceeded the limit. The ‘soft’ limit is a flexible setting. ‘Hard’ Limits are in stone and users cannot exceed the amount set. When you hit the ‘hard’ limit, you are out of space.
There are two options for ‘soft’ and ‘hard’ limits, which are ‘space’ and ‘files’. The system measures the space in blocks (inodes) and is 1k, no matter the underlying block size set on the disk. The system does not use the file limitations, but in some cases, may be better in certain situations.
It is possible to set both options for both users and groups. Be aware that our Group ‘odd’ comprises ‘user1’ and ‘user3’. If we set up a group block limit of ‘1000000’, which is 1 GB and ‘user3’ uses 999 MB, then ‘user1’ only has 1 MB of storage left to use, even if as a user he has 500 MB. Keep in mind that the two units work together. If you do not set the group settings correctly, a user can have all their space used by another user in the same group.
So, let’s make an example. We want ‘user1’ to have a soft block limit of ‘250000’ (250MB) and a hard block limit of ‘500000’ (500MB). We will do the same for ‘user3’. So the command is:
The first set of numbers is for the block ‘soft’ and ‘hard’ limit. The last two numbers, set at ‘0’, are ‘soft’ and ‘hard’ limits for file usage.
Now if you run the ‘requota’ command, see that the set limits are for the user ‘user1’.
Since we said that ‘user3’ should have the same settings, we can simply replicate the settings for one user to another:
Now, running ‘repquota’ again shows ‘user1’ and ‘user3’ have the same settings.
Let’s set up the group ‘even’ to have a soft limit of ‘1000000’ (1GB) and a hard limit of ‘1500000’ (1.5GB). Keep in mind that this is a Group Quota with no user limits. Here, they share the space between them. Perform the following command to configure these settings and my output is shown in Figure 2:
FIGURE 2
In a bit, we can test the limits, but let’s look at another method for changing quotas. We use ‘edquota’ to copy the settings from one user to another, but we can also copy group quotas as well. Another option is to configure a single user or group and edit a file. So, let’s look at the group ‘odd’. Use the command:
The command brought up a configuration file in ‘nano’ for the group ‘odd’, as shown in Figure 3. You can edit the file and keep in mind that the numbers do not need to line up, there only needs to be spaces between the numbers. I’ll set the soft limit to ‘500000’ and the hard limit of ‘1000000’. These settings are double what the two have as users limits. There should be no issues since if each user maxes out their user limits, it won’t max out the group limits.
FIGURE 3
So, what happens with ‘user2’ and ‘user4’ with their group limits?
The problem right now is that ‘root’ set up ‘/share’ and has all permissions. Let’s change that:
Now, everyone can have full access, up to their quota limits.
If we use ‘sudo su user2’, we can get to a prompt as ‘user2’. Perform:
After the creation of the file, I have hit my hard limit. If I log in as ‘user4’, I should not be able to make a file since the group quota is met. If I try to create a folder, I get an error that there is no space left on the drive. I have met the quota of the ‘hard’ limit.
But, ‘user1’ or ‘user3’ should still be able to make files since their quota has not been met.
XFS Quotas
We need to set up the quota environment so the quotas work.
Find a drive that is formatted as XFS or format one as XFS. In my case, I am using ‘/dev/sdb6’.
Before we can make changes, we need to unmount it:
We then need to edit the file ‘/etc/fstab’ and add the line:
Of course, the UUID will be different for your system. You can replace the UUID with ‘/dev/sdb6’. The main difference here are the parameters after ‘defaults’. The ‘uquota’ enable user quotas and ‘gquotas’ enable group quotas.
After saving and exiting the editor, you need to create the shared mount point:
Now we can mount the drive and the new settings:
After we mount the drive, we need to change the permissions, so since this is a demonstration, we can just give all permissions to all users:
The permissions need to be set after we mount the drive.
For anything to appear, you need to login as ‘user1’, for example (sudo su user1), and got to ‘/xfs’ (cd /xfs) then create files. Creating folders will not help much, you need files.
Now go back as yourself in the system (exit).
The basic program is interactive and gives you a prompt, ‘xfs_quota>’. Here, you can enter your commands for reports and then you can leave the interactive program by entering ‘quit’.
For a reporting about a specific user, use:
Replace ‘username’ with the user, such as ‘user1’, that you want a report about.
From outside the interactive program, you can execute single commands from an expert mode. Here, we can set the hard and soft limits for a user or group. In the following code, we can set the program to use expert mode with the ‘-x’ parameter. We then specify to run a command with ‘-c’. The command we will run is to limit the user ‘user1’ to a soft limit for blocks (size) and a hard limit on ‘/xfs’:
Instead of ‘b’ for blocks with ‘bsoft’ and ‘bhard’, we can use ‘i’ for inodes, or files, with ‘isoft’ and ‘ihard’.
The command defaults to setting limits for users. To change to groups, use the ‘-g’ parameter after the ‘limit’ command and specify a group instead of a user:
If you want to change the settings, just reissue the command with the new values you require.
We can check the limits set for all users and groups with the command:
If you want to remove quotas, just edit the ‘fstab’ file and remove the ‘uquota,gquota’ from the drive you wish and replace it with ‘defaults,noquota’.
This should get you started with quotas on XFS.
Conclusion
As with every aspect of a server, we can limit the amount of storage a user or group can use.
For some companies, storage space may not be large, so this is a necessary evil to reduce the storage allotted to all employees.
Try Quotas to get used to setting this up.
Not only can we set them, but we can also determine how much space a user or group has used on a disk.
You can enable quotas on either EXT4 or XFS formatted storage units.
Quota Installation
Sometimes you may need to install the ‘quotas’ software package.
For CentOS:
Code:
sudo yum install quota -y
For Ubuntu:
Code:
sudo apt install quota -y
Now that we installed the quota software, we are ready to begin.
Enable Quotas
After we install the software, we have the ability for quotas, but we need to enable them. Not only do we specify which drives, but we can also specify which users or groups.
So, to start, we need some users and groups to play with for these examples. Let’s add four users and 2 groups:
Code:
sudo useradd -m user1
sudo useradd -m user2
sudo useradd -m user3
sudo useradd -m user4
sudo groupadd odd
sudo groupadd even
sudo usermod -aG odd user1
sudo usermod -aG odd user3
sudo usermod -aG even user2
sudo usermod -aG even user4
You can run these one line at a time or put is in a bash script, make it executable and run it. Don’t forget the ‘shebang’, ‘#!/bin/bash’, at the beginning.
We now have four users: ‘user1’, ‘user2’, ‘user3’ and ‘user4’. The odd numbered users are in a group called ‘odd’ and the even numbered users are in the group ‘even’.
Now, we need to set up a drive to use for quotas. You should have a partition set up as ‘/dev/sdb5’ which we will not use anymore. Use the following commands to use it. Be aware that if you have not followed along with the examples, then you may need to use your own partition that is usable and change the partition name accordingly:
Code:
sudo umount /dev/sdb5
sudo mkfs.ext4 /dev/sdb5
sudo mkdir /share
We need to unmount the drive to format it since we cannot if it is currently mounted. We then format it as ‘ext4’ and create a share for mounting the drive to for accessing.
We can then run the command:
Code:
blkid /dev/sdb5
Copy the UUID and alphanumeric characters after it. You will edit the ‘/etc/fstab’ and add this UUID to a new line. You’ll also set up the share, format type, and set it to user quotas (usrquota) and group quotas (grpquota), etc. An example:
Code:
UUID=e9e02e39-7c35-4ad4-b16c-6c7a577a3178 /share ext4 noatime,noexec,usrquota,grpquota 0 0
Your UUID will be different, but the rest should be the same. Save and exit the editor. Run the following code to remount only the drive:
Code:
mount -o remount /share
If you list the files in the share, ‘ls /share’. You should see a response of ‘lost+found’. The share is set and ready for quotas.
Before we enable quotas, we need to set up the database to store the quota information. Use the following command:
Code:
sudo quotacheck -mug /dev/sdb5
The ‘-m’ is to make the databases, ‘u’ is for the ‘user’ database and ‘g’ is for the group database. Now, if you run ‘ls -a /share’, there should be two more files listed in the databases. The files are ‘aquota.users’ for the user quota and ‘aquota.group’ for the group quotas.
Now, the quotas are on, but we have not configured.
Configuring and Reporting Quotas
If I look at a report for ‘/share’, I can see that only the user and group ‘root’ have files on the drive. These would be the two databases set up when adding those to the drive. To see the report, use:
Code:
sudo repquota -ugv /share
Figure 1 shows the report output.
FIGURE 1
The parameter ‘u’ is for ‘users’, ‘ g’ is for ‘group’ and ‘v’ is ‘verbose’.
Now, before setting quotas, there are a few things to cover.
We have ‘soft’ and ‘hard’ limits. ‘Soft’ limits are where you get messages that you have exceeded the limit. The ‘soft’ limit is a flexible setting. ‘Hard’ Limits are in stone and users cannot exceed the amount set. When you hit the ‘hard’ limit, you are out of space.
There are two options for ‘soft’ and ‘hard’ limits, which are ‘space’ and ‘files’. The system measures the space in blocks (inodes) and is 1k, no matter the underlying block size set on the disk. The system does not use the file limitations, but in some cases, may be better in certain situations.
It is possible to set both options for both users and groups. Be aware that our Group ‘odd’ comprises ‘user1’ and ‘user3’. If we set up a group block limit of ‘1000000’, which is 1 GB and ‘user3’ uses 999 MB, then ‘user1’ only has 1 MB of storage left to use, even if as a user he has 500 MB. Keep in mind that the two units work together. If you do not set the group settings correctly, a user can have all their space used by another user in the same group.
So, let’s make an example. We want ‘user1’ to have a soft block limit of ‘250000’ (250MB) and a hard block limit of ‘500000’ (500MB). We will do the same for ‘user3’. So the command is:
Code:
sudo setquota -u user1 250000 500000 0 0 /share
The first set of numbers is for the block ‘soft’ and ‘hard’ limit. The last two numbers, set at ‘0’, are ‘soft’ and ‘hard’ limits for file usage.
Now if you run the ‘requota’ command, see that the set limits are for the user ‘user1’.
Since we said that ‘user3’ should have the same settings, we can simply replicate the settings for one user to another:
Code:
sudo edquota -u user3 -p user1
Now, running ‘repquota’ again shows ‘user1’ and ‘user3’ have the same settings.
Let’s set up the group ‘even’ to have a soft limit of ‘1000000’ (1GB) and a hard limit of ‘1500000’ (1.5GB). Keep in mind that this is a Group Quota with no user limits. Here, they share the space between them. Perform the following command to configure these settings and my output is shown in Figure 2:
Code:
sudo setquota -g even 1000000 1500000 0 0 /share
FIGURE 2
In a bit, we can test the limits, but let’s look at another method for changing quotas. We use ‘edquota’ to copy the settings from one user to another, but we can also copy group quotas as well. Another option is to configure a single user or group and edit a file. So, let’s look at the group ‘odd’. Use the command:
Code:
sudo edquota -g odd
The command brought up a configuration file in ‘nano’ for the group ‘odd’, as shown in Figure 3. You can edit the file and keep in mind that the numbers do not need to line up, there only needs to be spaces between the numbers. I’ll set the soft limit to ‘500000’ and the hard limit of ‘1000000’. These settings are double what the two have as users limits. There should be no issues since if each user maxes out their user limits, it won’t max out the group limits.
FIGURE 3
So, what happens with ‘user2’ and ‘user4’ with their group limits?
The problem right now is that ‘root’ set up ‘/share’ and has all permissions. Let’s change that:
Code:
sudo chmod 777 /share
Now, everyone can have full access, up to their quota limits.
If we use ‘sudo su user2’, we can get to a prompt as ‘user2’. Perform:
Code:
cd /share
mkdir user2
cd user2
dd if=/dev/zero of=/share/user2/data count=1 bs=999M
After the creation of the file, I have hit my hard limit. If I log in as ‘user4’, I should not be able to make a file since the group quota is met. If I try to create a folder, I get an error that there is no space left on the drive. I have met the quota of the ‘hard’ limit.
But, ‘user1’ or ‘user3’ should still be able to make files since their quota has not been met.
XFS Quotas
We need to set up the quota environment so the quotas work.
Find a drive that is formatted as XFS or format one as XFS. In my case, I am using ‘/dev/sdb6’.
Before we can make changes, we need to unmount it:
Code:
sudo umount /dev/sdb6
We then need to edit the file ‘/etc/fstab’ and add the line:
Code:
UUID=859d7b54-2431-4df2-8bbe-89fd935f7f17 /xfs xfs defaults,uquota,gquota 0 0
Of course, the UUID will be different for your system. You can replace the UUID with ‘/dev/sdb6’. The main difference here are the parameters after ‘defaults’. The ‘uquota’ enable user quotas and ‘gquotas’ enable group quotas.
After saving and exiting the editor, you need to create the shared mount point:
Code:
sudo mkdir /xfs
Now we can mount the drive and the new settings:
Code:
mount -a
After we mount the drive, we need to change the permissions, so since this is a demonstration, we can just give all permissions to all users:
Code:
sudo chown 777 /xfs
The permissions need to be set after we mount the drive.
For anything to appear, you need to login as ‘user1’, for example (sudo su user1), and got to ‘/xfs’ (cd /xfs) then create files. Creating folders will not help much, you need files.
Now go back as yourself in the system (exit).
The basic program is interactive and gives you a prompt, ‘xfs_quota>’. Here, you can enter your commands for reports and then you can leave the interactive program by entering ‘quit’.
For a reporting about a specific user, use:
Code:
quota <username>
Replace ‘username’ with the user, such as ‘user1’, that you want a report about.
From outside the interactive program, you can execute single commands from an expert mode. Here, we can set the hard and soft limits for a user or group. In the following code, we can set the program to use expert mode with the ‘-x’ parameter. We then specify to run a command with ‘-c’. The command we will run is to limit the user ‘user1’ to a soft limit for blocks (size) and a hard limit on ‘/xfs’:
Code:
xfs_quota -x -c 'limit bsoft=1g bhard=1536m user1' /xfs
Instead of ‘b’ for blocks with ‘bsoft’ and ‘bhard’, we can use ‘i’ for inodes, or files, with ‘isoft’ and ‘ihard’.
The command defaults to setting limits for users. To change to groups, use the ‘-g’ parameter after the ‘limit’ command and specify a group instead of a user:
Code:
xfs_quota -x -c 'limit -g bsoft=500m bhard=1g even' /xfs
If you want to change the settings, just reissue the command with the new values you require.
We can check the limits set for all users and groups with the command:
Code:
xfs_quota -x -c 'report' /xfs
If you want to remove quotas, just edit the ‘fstab’ file and remove the ‘uquota,gquota’ from the drive you wish and replace it with ‘defaults,noquota’.
This should get you started with quotas on XFS.
Conclusion
As with every aspect of a server, we can limit the amount of storage a user or group can use.
For some companies, storage space may not be large, so this is a necessary evil to reduce the storage allotted to all employees.
Try Quotas to get used to setting this up.

