ubuntu disk quota

อ้างอิง http://www.extremetech.com/article2/0,1697,2140153,00.asp

Understanding Your Limits
Under Ubuntu, the quota system enables you to specify limits for files, links, and disk space per user. There are soft limits and hard limits, and an allotted grace period. These limits can be set for users or groups. This way, a group can share files within a given quota.

  • Hard limits—A hard limit specifies the maximum allocation for a user or group. For example, if you are allotted 10,000 files, then you cannot create any new files if you are over your quota. The only way to get under your quota is to either delete files, or have the administrator increase your limit.

     

  • Soft limits—Soft limits are used to provide a warning to users. If they go over their soft limit quota, then the grace time kicks in. The grace time says how long they have to remove files and get under their quota. If the grace time is set to seven days, then users have seven days to get under their quota. After the grace period, the soft limit is treated as a hard limit and the user is blocked from creating or updating new files. Soft limits are really useful since sometimes you might go a little over your quota for a short duration.

     

  • Disk limits—Soft and hard limits can be set based on disk space. For example, a user may be allocated a 100 MB soft limit at 110 MB hard limit. Small systems may have limits set in the megabyte range, while large systems may use gigabyte quotas.

     

  • File limits. This limit allows you to specify how many files a user (or group) can have. Files are anything that consumes an inode—this includes real files, device files, and links to other files. Small systems, such as local e-mail servers, may be limited to a few hundred or a few thousand files. In contrast, large file repositories may be allowed hundreds of thousands of files, or have no limit at all.

Note: The file system uses inodes to store meta-data information about files. This includes the actual file name (since it is not found inside the file contents), permissions, timestamps, and directory information.

Enabling Quotas

  1. Install the quota package.
    #sudo apt-get install quota
  2. Quotas are set on a per-file-system basis. Edit /etc/fstab and add the mount options usrquota and grpquota to your file system. In my case, I have added user quotas to my Ubuntu file system (/dev/hda1), and both user and group quota to second hard drive (/dev/hdb4). My /etc/fstab file looks like: # /etc/fstab: static file system information. # device mount fs options dump pass proc /proc proc defaults 0 0
    /dev/hda1 / ext3 defaults,errors=remount-o,usrquota 0 1
    /dev/hda5 none swap sw 0 0
    /dev/hdc /media/cdrom0 udf,iso9660 user,noauto 0 0
    /dev/hdb4 /mnt/disk ext3 defaults,usrquota,grpquota 0 0

    Tip: Don't enable quotas on read-only devices such as CD-ROM drives. Since a user has no way to add or remove files, quota information provides no value. Similarly, removable devices such as floppy disks and USB thumb drivers usually should not have quotas enabled.
  3. Since the partitions are already mounted, you will need to remount each of the quotaenabled file systems in order to load the new mount flags. Since the changes are in /etc/fstab, you won't need to do this after a reboot. Since I added quotas to / and /mnt/disk, I can remount using: $ sudo mount -o remount / $ sudo mount -o remount /mnt/disk $ mount | grep quota # check results /dev/hda1 on / type ext3 (rw,errors=remount-ro,usrquota) /dev/hdb4 on /mnt/disk type ext3 (rw,usrquota,grpquota)
  4. Before quotas can be enabled, you need to check for existing problems (even through there shouldn't be any problems). This is done using the quotacheck command. The parameters -augmv means all file systems, all user and group quotas, and don't remount the partitions. For large disks, this check might take a few minutes. If you don't have user quotas, then you do not need -u, and -g is only used when group quotas are enabled. Specifying the -g without the grpquota mount option will generate a warning, but won't cause problems. $ sudo quotacheck –augmv quotacheck: Scanning /dev/hdb4 [/mnt/disk] quotacheck: Cannot stat old user quota file: No such file or directory

    quotacheck: Cannot stat old group quota file: No such file or directory quotacheck: Cannot stat old user quota file: No such file or directory quotacheck: Cannot stat old group quota file: No such file or directory done quotacheck: Checked 10254 directories and 228748 files quotacheck: Old file not found. quotacheck: Old file not found. 

    The first time you run quotacheck -augmv, you will see a bunch of warnings about files not existing. This is because the system has not been checked before. After it is checked, the quota version 2 files /mnt/disk/aquota.user and /mnt/disk/ aquota.group (or quota.user and quota.group if you are using the older quota version 1 system) will be created and these errors should not appear again.

    Note: Even if you are not enabling both user and group quotas on a file system, you should create both files. Otherwise some quota commands may generate warnings.

  5. Now quotas can be turned on. sudo quotaon -augv

    Tip: Running sudo /etc/init.d/quota start will perform the quota check (Step 4) and turn on quotas (step #5).

    Editing Quotas
    After quotas are enabled you can edit them using edquota. Using edquota -u, you can edit the quota for any particular user. Similarly, edquota -g edits group quotas.

    sudo edquota -u bill
    sudo edquota -g users

    The edquota command opens an editor that allows you to specify the soft and hard limits for disk space (blocks) and files (inodes). Each partition where quotas are enabled is listed. The current values are also displayed. For example, my quota settings look like:

    Filesystem blocks soft hard inodes soft hard /dev/hda1 68866148 0 0 247947 0 0 /dev/hdb4 31153944 0 0 238603 0 0 

    This says that I am currently using about 65 GB on /dev/hda1, and using 247,947 inodes. On /dev/hdb4 I am using about 30 GB and 238,603 inodes. This also says that I have no quota limits. Changing and saving the soft and hard values will immediately enable quotas. If I am over quota, then the soft and hard limits are immediately enforced. The grace times default to seven days, but can be edited using sudo edquota -t. This brings up an editor that displays the current settings per device and allows you to change the values.

      Grace period before enforcing soft limits for users: Time units may be: days, hours, minutes, or seconds Filesystem               Block grace period    Inode grace period /dev/hda1                7days                         7days /dev/hdb4                7days                         7days  

    Tip: Don't worry about maintaining the correct column spacing when editing with edquota. The system only checks the number of columns separated by spaces, not the actual number of spaces. Saving changes and then running edquota again will reformat the columns.

Reporting Quotas

After enabling quotas, you can generate periodic reports using the repquota command. These can either be in the raw system format or in a human-readable form (-s).

repquota
 
 

You can also generate quota e-mails using warnquota. By default, e-mails are sent to each user when they are over quota, and root also receives a copy of each e-mail. You can change the e-mail sender’s information by editing /etc/warnquota.conf. When I need to track projects by disk space, I usually create a user account just for the project and enable a cron job to generate a nightly (or hourly) report for the project’s user (sudo repquota -a | grep projectusername). <p>Summary
Ubuntu provides many different options for managing concurrent applications.Whether your needs are for task switching, window management, or project tracking, there are plenty of options available. Using simple scripts, you can enhance clipboard usage and create directories that automate tasks. And best of all, you can literally budget your time.</p><blockquote><pre> </pre></blockquote>