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: Hadoop
How to Build an Optimal Hadoop Cluster to Store and Maintain Unlimited Amounts of Data Using Microservers
Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
Some of key questions to be discussed are:
- What is the “typical” Hadoop cluster and what should be installed on the different machine types?
- Why should you consider the typical workload patterns when making your hardware decisions?
- Are all microservers created equal for Hadoop deployments?
- How do I plan for expansion if I require more compute, memory, storage or networking?
|Designing Electronics with Linux||May 22, 2013|
|Dynamic DNS—an Object Lesson in Problem Solving||May 21, 2013|
|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|
- Designing Electronics with Linux
- New Products
- Making Linux and Android Get Along (It's Not as Hard as It Sounds)
- Dynamic DNS—an Object Lesson in Problem Solving
- Using Salt Stack and Vagrant for Drupal Development
- Validate an E-Mail Address with PHP, the Right Way
- Tech Tip: Really Simple HTTP Server with Python
- Build a Skype Server for Your Home Phone System
- Why Python?
- Drupal Is a Framework: Why Everyone Needs to Understand This
- Reply to comment | Linux Journal
12 min 36 sec ago
- Reply to comment | Linux Journal
1 hour 2 min ago
- Not free anymore
5 hours 4 min ago
8 hours 51 min ago
- Reply to comment | Linux Journal
8 hours 59 min ago
- Understanding the Linux Kernel
11 hours 14 min ago
13 hours 44 min ago
- Kernel Problem
23 hours 47 min ago
- BASH script to log IPs on public web server
1 day 4 hours ago
1 day 7 hours ago