Disk usage is always an issue, whether you are using Linux, DOS or any other Operating System. After discovering the disk is full the first thing to do is find out what files are taking up the most disk space and who owns those files. There are three different commands that you can use to obtain this information—df, du and ls (for more information, look in the man pages).
On using one of these commands, you find that one or more users have more disk space allocated than you do. One way for a System Administrator to avoid this kind of problem is to implement a disk quota for each user.
Before implementing the quota utility, you must have a kernel that supports it. Quota is supported by default in the Linux kernel since version 2.0. If you are not already running a 2.0.x kernel, you must install the quota package and create a new kernel that supports it.
To make quota available for a certain file system, you must edit the /etc/fstab file and add entries for usrquota and/or grpquota.
My fstab file is shown in Listing 1. The word usrquota is an option from the fstab that turns quota on for users on this device. You can also use grpquota to turn on grpquota for this device or use a combination of both.
Before you can use the quota package, the command quotacheck must be run to check the specified file system for any previously set quotas. If this is the first time you've used the command and no quotas are found, it creates a quota.user or quota.group file or files in the root of the specified file system. Which files are created is dependent on which options are specified in the fstab file. The quotacheck command runs each time you boot the system.
The first time I ran quotacheck on my machine the output looked like this:
quotacheck -v /dev/hda3 Scanning /dev/hda3 [/home] done Checked 50 directories and 331 files Using quotafile /home/quota.user
Now that quotacheck has run, you can turn on quota for your system by using the command quotaon. This command has different options. The easiest one for first time use is:
quotaon -avThis command installs quota on all file systems marked read/write in the etc/fstab file and also displays a message showing which file systems have quota turned on. Here's another example:
newroom:~# quotaon -av /dev/hda3: user quotas turned on newroom:~#To run quotaon each time you boot your machine, add the following line to the /etc/rc.d/rc.local file:
quotaon -avugThe opposite of quotaon is quotaoff, and it has the same options. This command turns quota off for a file system.
Now it is time to specify a quota for the users or groups. The easiest thing to do is to give everyone the same amount of disk space.
To get an indication of how much each user is currently using, use the command repquota. This command displays a summary of the disc usage and quotas for the specified file systems. For each user the current number of files and the amount of space (in kilobytes) is printed, along with any quotas created with edquota (see explanation of this command below). An example of this summary is shown in Listing 2.
The command used to set disk quotas is called edquota. This command brings up the quota editor which is used in the same way as the commands described above. The -u option is used to specify a user quota, and the -g option is used to specify a group quota. When you use edquota with one of the options, a temporary file is created containing an ASCII representation of the current disk quotas for that user or group, and the editor is invoked for this file. You can use the editor to modify or add new quotas and so on. Upon exiting the editor, edquota reads the temporary file and modifies the binary quota files to reflect the changes. When in the editor, you should only edit numbers that follow an = sign. For each file system using quota, two lines are put in the temporary file:
Quotas for user dsnjaro: /dev/hda3: blocks in use: 49, limits (soft = 0, hard = 0) inodes in use: 30, limits (soft = 0, hard = 0)
The first line contains the number of blocks in use and how many blocks a user or group can allocate. The second line contains the number of inodes in use and how many can be allocated. The soft parameter specifies a “soft limit”—people or groups can exceed this limit for a certain period of time (set by the -t option). The hard parameter specifies a “hard limit”—the absolute maximum amount of space a user or group can have.
If you don't wish to set a quota for a particular user or group, assign the value 0 to both soft and hard. This is a better documented solution than leaving this user or group out of the user.quota or group.quota file.
To change the hard and soft limits, use the edquota command with the -t option set. Using the editor, you can specify these time limits in either days, hours, minutes or seconds. If you set the hard limit equal to the soft limit, users or groups are not allowed to have more than this value.
To give everyone on your system the same quota, use the -p option to define a prototype user. To give everyone the same quota as this prototype user, give the command:
edquota -p <uid of the prototype> *
All commands described in this article are only for use by the system administrator (almost every command has to read all directories and their files) for security reasons.
Free Webinar: Linux Backup and Recovery
Most companies incorporate backup procedures for critical data, which can be restored quickly if a loss occurs. However, fewer companies are prepared for catastrophic system failures, in which they lose all data, the entire operating system, applications, settings, patches and more, reducing their system(s) to “bare metal.” After all, before data can be restored to a system, there must be a system to restore it to.
In this one hour webinar, learn how to enhance your existing backup strategies for better disaster recovery preparedness using Storix System Backup Administrator (SBAdmin), a highly flexible bare-metal recovery solution for UNIX and Linux systems.
|Using Salt Stack and Vagrant for Drupal Development||May 20, 2013|
|Making Linux and Android Get Along (It's Not as Hard as It Sounds)||May 16, 2013|
|Drupal Is a Framework: Why Everyone Needs to Understand This||May 15, 2013|
|Home, My Backup Data Center||May 13, 2013|
|Non-Linux FOSS: Seashore||May 10, 2013|
|Trying to Tame the Tablet||May 08, 2013|
- Using Salt Stack and Vagrant for Drupal Development
- Making Linux and Android Get Along (It's Not as Hard as It Sounds)
- New Products
- Validate an E-Mail Address with PHP, the Right Way
- Drupal Is a Framework: Why Everyone Needs to Understand This
- A Topic for Discussion - Open Source Feature-Richness?
- Home, My Backup Data Center
- New Products
- RSS Feeds
- New Products
- Reply to comment | Linux Journal
5 min 47 sec ago
- This is the easiest tutorial
6 hours 20 min ago
- Ahh, the Koolaid.
11 hours 58 min ago
- git-annex assistant
17 hours 58 min ago
- direct cable connection
18 hours 20 min ago
- Agreed on AirDroid. With my
18 hours 31 min ago
- I just learned this
18 hours 35 min ago
19 hours 5 min ago
- not living upto the mobile revolution
21 hours 56 min ago
- Deceptive Advertising and
22 hours 32 min ago