Linux’s systems with many users, such as mail servers, samba servers, etc., sooner or later have the problem of users storing too much information in their working directories, being able to even in extreme cases to completely fill hard drives making the system unusable. With the use of disk quotas, it is possible to limit the amount of space available for each user or globally for all. The truth is that in this article you will have the necessary information to implement and manage disk quotas for user control.
Quota types
By Blocks: A block corresponds to 1 KB and a quota by blocks would correspond to the total of blocks that a user can use in the system. Remember that files are stored on disk blocks. Thus, a 100-byte file will occupy a 1kb block on the hard disk.
By inodes (inodes): It is a number that acts as a pointer to the Linux file system and indicates in which specific blocks of the hard disk the data of a file is located. Also, the inode in your reference saves information about permissions, owner, attributes, etc. It could be seen in a simple analogy that an inode is like a unique serial number for each file in the system and through this number the system retrieves its data (blocks) and its attributes or metadata (permissions, owner, dates, etc.).
In the case of cutoas, a quota for inodes would indicate the total of inodes to which the user is entitled, it would almost represent the total of files that the user can create and I say “almost” because users can create symbolic links ln -s on existing files that do not increase the number of inodes. But for simplicity you can see it as 1 inode = 1 file.
Limits
Both block and inode quotas have usage limits and are of two types:
HARD: (Hard) When set (for blocks or inodes), it is the absolute limit. The user may not exceed this limit.
SOFT: (Soft) This limit (for blocks or inodes) which is always less than HARD, can be exceeded by the user, but it will be constantly warned that the use limit for blocks or inodes has already been exceeded. It could be seen as a warning limit that will be telling the user that their limit has already been exceeded and take action.
When using the SOFT limit, two situations can occur. The first is that a grace time is NOT established, and then the user can continue using blocks or inodes until reaching the HARD limit, which will be their absolute limit of use.
The second situation is that the grace time is established, which can be in days, hours, minutes or seconds. In this case, the user will be able to continue using blocks or inodes until the grace time expires or the HARD limit is reached, whichever comes first.
Thanksgiving can be set per user or globally.
Where are they implemented?
Quotas are established by filesystem or file system, that is, you must decide where it is more convenient to install a quota system, but there is no problem if it is installed in all. Quotas can be set per user, per group, or both. In the example below:
#> mount / dev / sda1 on / boot type ext3 (rw, noatime) / dev / sda2 on / type ext3 (rw, noatime) / dev / sda3 on / home type ext3 (rw, noatime) none on / proc type proc (rw) none on / proc / sys / fs / binfmt_misc type binfmt_misc (rw)
The above is a typical example of a Linux machine with multiple file systems (/ boot, /, and / home). As is known, / home is where users have their work directories (HOME), so only in this file system we will create quotas, in the other two it has no case.
Setting
We only add support for quotas on the filesystem that interests us. The above by itself, it is obvious that it does nothing, it would be necessary to restart the system for the changes to be applied but it is not really necessary, the following re-mounts the “/ home” file system:
#> mount -o remount / home #> mount / dev / sda1 on / boot type ext3 (rw, noatime) / dev / sda2 on / type ext3 (rw, noatime) / dev / sda3 on / home type ext3 (rw, noatime, usrquota, grpquota) none on / proc type proc (rw)
The “/home” file system is now ready to support disk quotas. The next step is to check with the quotacheck command for file systems that support quotas. This command creates, verifies or repairs the quota control in the systems that support it, in this case it will create the support:
#> mount -o remount / home #> mount / dev / sda1 on / boot type ext3 (rw, noatime) / dev / sda2 on / type ext3 (rw, noatime) / dev / sda3 on / home type ext3 (rw, noatime, usrquota, grpquota) none on / proc type proc (rw)
The “/home” file system is now ready to support disk quotas. The next step is to check with the quotacheck command for file systems that support quotas. This command creates, verifies or repairs the quota control in the systems that support it, in this case it will create the support:
quotacheck: Cannot stat old group quota file: File or directory does not exist quotacheck: Cannot stat old user quota file: File or directory does not exist quotacheck: Cannot stat old group quota file: #> quotacheck -augmv quotacheck: Scanning / dev / sda3 [/ home] done quotacheck: Cannot stat old user quota file: File or directory does not exist File or directory does not exist quotacheck: Checked 2539 directories and 35556 files quotacheck: Old file not found. quotacheck: Old file not found.
The errors that you send is precisely because there was no previous quota system, it is normal for you to send them. When quotas are in full use, it is a good idea to run quotacheck periodically to check for inconsistencies and correct them in time. Regarding the options, they indicate the following:
• a – all, that is, it checks all file systems for quotas.
• u – user, check for quota support for users.
• g – group, check for quota support for groups.
• m – no-remount, prevents the system from being remounted as read-only.
• v – verbose, reports what it does as it progresses, they are the messages that go out to the terminal.