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.
Fast/Flexible Linux OS Recovery
On Demand Now
In this live one-hour webinar, learn how to enhance your existing backup strategies for complete disaster recovery preparedness using Storix System Backup Administrator (SBAdmin), a highly flexible full-system recovery solution for UNIX and Linux systems.
Join Linux Journal's Shawn Powers and David Huffman, President/CEO, Storix, Inc.
Free to Linux Journal readers.Register Now!
- Sony Settles in Linux Battle
- Download "Linux Management with Red Hat Satellite: Measuring Business Impact and ROI"
- Profiles and RC Files
- Maru OS Brings Debian to Your Phone
- Snappy Moves to New Platforms
- Understanding Ceph and Its Place in the Market
- What's Our Next Fight?
- Git 2.9 Released
- The Giant Zero, Part 0.x
- Astronomy for KDE
With all the industry talk about the benefits of Linux on Power and all the performance advantages offered by its open architecture, you may be considering a move in that direction. If you are thinking about analytics, big data and cloud computing, you would be right to evaluate Power. The idea of using commodity x86 hardware and replacing it every three years is an outdated cost model. It doesn’t consider the total cost of ownership, and it doesn’t consider the advantage of real processing power, high-availability and multithreading like a demon.
This ebook takes a look at some of the practical applications of the Linux on Power platform and ways you might bring all the performance power of this open architecture to bear for your organization. There are no smoke and mirrors here—just hard, cold, empirical evidence provided by independent sources. I also consider some innovative ways Linux on Power will be used in the future.Get the Guide