Meniu

Use quota

Quota is a feature of Linux operating systems that allows a system administrator to impose a hard disk space limit on a user or group of users.

How is it used?

The first step is to edit the / etc / fstab file and add it to the partitions on which you want to apply the quota, the term "usrquota" or "grpquota". To enable quota support on a partition, in the / etc / fstab file, add the term "usrquota" or "grpquota" immediately after the default word, as follows:

/dev/hda1 / ext2 defaults 1 1
/dev/hda2 /usr ext2 defaults,usrquota 1 1

In our case, the file system on the second partition on the first hard disk was applied to the user. If you wanted for the group, you had to replace usrquota with grpquota. But if you want the quota for both users and groups, you can add them both, consecutively, separated by commas as in the example below.

/dev/hda1 / ext2 defaults 1 1
/dev/hda2 /usr ext2 defaults,usrquota,grpquota 1 1

In the second stage give the following commands:

touch /partitia_pe_care_se_aplica/quota.user

chmod 600 /partitia_pe_care_se_aplica /quota.user

The quota for the group can be set by replacing the file name quota.user with quota.group.

Next we have to give the order

quotacheck -v /partitia_pe_care_se_aplica

E.g:

quotacheck -v /dev/hda2

If all went well you should get an answer like:

Scanning /dev/hda2 [/home] done

Checked 451 directories and 1367 files

Using quotafile /home/quota.user

Quotacheck is used to scan a file system and see how much disk space is used, this information being used for the "quota.user" (or "quota.group") file. It is recommended that quotacheck be executed at system startup (this option being implicit in RedHat distributions).

Now we have to activate the quota, by order

quotaon -av

The operating system response should be:

/dev/hda2: user quotas turned on

The quotaon and quotaoff commands enable or disable the quota for a file system, respectively.

Setting the quota for a user

Order data:

edquota -u numele_utilizatorului

The operating system should respond like:
Quotas for user guest:

/dev/sdb6: blocks in use: 56, limits (soft = 0, hard = 0) inodes in use: 50, limits (soft = 0, hard = 0)

If something is wrong you may get the following answer:

/dev/sdb6: blocks in use: 0, limits (soft = 0, hard = 0)
inodes in use: 0, limits (soft = 0, hard = 0)

If no error message appears, a text editor (vi) will open with which you will have to edit the quota for the "guest" user, for example:

/dev/hda6: blocks in use: 992, limits (soft = 50000, hard = 55000)
inodes in use: 71, limits (soft = 10000, hard = 11000)

If you edit the quota for the group, give the order:

edquota -g numele_grupului

You can see the quota for a specific user with the command:

quota -u nume_utilizator

For example, for the quota -u guest command, the system responds like:

Disk quotas for user guest1 (uid 505):
Filesystem blocks quota limit grace files quota limit grace
/dev/hda6 992 50000 55000 71 10000 11000

If the answer you received is not in the style of the one above, then try the same command after rebooting the computer.

There is also the repquota command - which will print quota information from a file system.

automation

As I said, quotacheck should be done periodically. One way is to include it in the cron (program with which we schedule certain tasks). If we want this to be done weekly, say, we need to write a file with a script in the /etc/cron.weekly directory.

Example: The /etc/cron.weekly/runQuotachek file contains the script

#/bin/bash
/sbin/quotacheck -v -a

After writing the file we must set the right to be executed:

chmod a+x /etc/cron.weekly/runQuotacheck

Other information

1. Using the vi editor

The "edquota" command will open the "vi" text editor, so to edit the quota you need to know a few commands for vi. Here are some simple questions to help you get started.

Opening an existing file: vi filename

Requesting a new file: vi new_filename

Adding text to the file: press the INSERT key and start typing.

Saving the file: press the ESC key and then: w, to continue writing you need to press the INSERT key again. (w = write)

Save the file and exit the editor: press the ESC key and then: wq

Exiting the editor without saving, if writing to the file: press ESC and then: q!

Exiting the editor without saving, if no file was written: press ESC and then: q

If you do not want to use vi, you can specify another editor through the EDITOR environment variable.

You need to know that you do not edit quota.user directly, the files /partitia_pe_care_se_aplica/quota.user or quota.group, these are binary files. Command edquota offers you the text interface. When you command: wq in the editor, edquota binary converts what you wrote and writes to the quota.user or quota.group file.

2. Assigning the quota to several users

In the case of a system with a lot of users, it can be unpleasant for the administrator to do everything I wrote above to set the quota. Fortunately, there are tools with which we can set the same quota for multiple users. Here's how to set the same quota as the guest user, for all users. First we edit the quota for the guest user, as described above, then we give the command:

edquota -p guest 'awk -F: '$3>499 ' /etc/passwd'

3. The meaning of some terms

a) "block in use" means the number of blocks (in kilobytes) that a user has used on a partition.

b) "inodes in use" is the total number of files a user has on a partition.

c) Soft limit, hard limit and grace period

The software limit specifies the maximum space a user has on a partition. When combined with the grace period, it is like a boundary line, warning the user of quota overruns. The hard limit only works if the grace period is active. Specifies the absolute limit of space that a user can use on the partition and cannot cross. The grace period, executed with the "edquota -t" command, is a period of time before the "soft limit" is set to work. The units of measurement can be used: seconds, minutes, hours, days, weeks, months.

If you give the command "edquota -t" you will receive an answer like:

Time units may be: days, hours, minutes, or seconds Grace period before enforcing soft limits for users: / dev / hda2: block grace period: 0 days, file grace period: 0 days

Change 0 days with anything else allowed. A choice could be 7 days (or 1 week, 1 week).

4. Linux kernel and quota

The kernel of Red Hat 6.x and newer distributions comes with quota support included. If you recompiled the kernel, make sure it has quota support. If you use xconfig or menuconfig programs, be sure to set y to:

Support quota (CONFIG_QUOTA) [n] y.

The default Red Hat initiation script (/etc/rc.d/rc.sysinit) will contain the following lines indicating run quotacheck:

if [ -x /sbin/quotacheck ] then echo "Verifica quota pe sistemul radacina" /sbin/quotacheck -v -a fi

and will activate the quota by:

if [ -x /usr/sbin/quotaon ] then echo "Activare quota." /usr/sbin/quotaon -v -a fi

5. Other sources of information

You can also find information about the quota at the addresses:

http://www.freebsd.org/handbook/quotas.html

http://www.ipme.ru/doc/handbook/handbook.html

http://www.txol.net/linux/quotas.htm

http://www.yolinux.com

http://www.linuxdoc.org/LDP/solrhe/Securing-Optimizing-Linux-RH-Edition-v1.3/quota.html

John Doe

Articole publicate de la contributori ce nu detin un cont pe gnulinux.ro. Continutul este verificat sumar, iar raspunderea apartine contributorilor.
  • | 340 articole

Nici un comentariu inca. Fii primul!
  • powered by Verysign