File System Administration
  Искать только в названиях книг
Загрузить это руководство в формате PDF

Managing Disk Use

10

This chapter contains these sections:
Monitoring Available Disk Spacepage 171
Monitoring Files and Directoriespage 176
Reducing Overloaded File Systemspage 186
Controlling Disk Space With Quotaspage 193
You must routinely monitor UFS file systems on disk slices so that performance remains satisfactory. This chapter describes how to monitor available disk space and the size of files and directories, reduce overloaded file systems, and control disk space with quotas.

Monitoring Available Disk Space

You should routinely monitor disk space to see how close to capacity a system is running. Use the df command to monitor available disk space. When file systems are nearing maximum capacity, see "Reducing Overloaded File Systems" on page 186 for information on how to make more disk space available.
The df command displays information about specific disk slices, including:
  • Total number of 512-byte blocks (or kilobytes) and files allocated to each file system
  • Number of 512-byte blocks (or kilobytes) and files used in each file system
  • Number of 512-byte blocks (or kilobytes) and files remaining in each file system

Using the df Command

If you use the df command with no arguments, the number of 512-byte blocks used and the number of files for all mounted file systems is displayed. You can run df on a specific disk slice by specifying the special device name for the slice (for example, df /dev/dsk/c0t0d0s0), the mount point for the file system (for example, df /usr), or the name of a directory in the file system. Use the -F ufs option to limit the information to local UFS file systems. To display information about unmounted file systems not in the /etc/vfstab file, specify the file system name and type. Table 10-1 shows the most frequently used options to the df command.
Table 10-1 df
OptionDescription
-tDisplays total 512-byte blocks and files allocated and number of 512-byte blocks and files used
-gDisplays total 512-byte blocks and files allocated, used, and free, as well as the type of file system, file system ID, file name length, block size, and fragment size
-kDisplays the used kilobytes, free kilobytes, and the percent of capacity used

Note - For remotely mounted file systems, -1 is displayed instead of the number of files.

See the df(1M) manual page for a complete list of options.
· How to Display Blocks and Files Used for All Mounted File Systems
* Type df and press Return. A list of mounted file systems, device names, total 512-byte blocks used, and number of files is displayed.
In this example, /, /usr, /proc, and /tmp are on the local disk. The other file systems are NFS-mounted and do not use local disk resources:

  saturn% df  
  /                  (/dev/dsk/c0t0d0s0):   21338 blocks    9592 files  
  /usr               (/dev/dsk/c0t0d0s6):   46722 blocks   34103 files  
  /proc              (/proc           ):       0 blocks     112 files  
  /tmp               (swap            ):   66696 blocks    3177 files  
  /root              (saturn:(pid132)):       0 blocks      -1 files  
  /home              (saturn:(pid132)):       0 blocks      -1 files  
  /src               (saturn:(pid132)):       0 blocks      -1 files  
  /nse               (saturn:(pid132)):       0 blocks      -1 files  
  /net               (saturn:(pid132)):       0 blocks      -1 files  
  saturn%  

· How to Display Used Disk Space in Kilobytes and Its Percent of Capacity
* Type df -k and press Return. The file system, total kilobytes, used kilobytes, available kilobytes, percent of capacity used, and mount point are displayed:

  saturn% df -k  
  filesystem         kbytes   used     avail    capacity  mounted on  
  /dev/dsk/c0t0d0s0  22199    11530    8459         58%       /  
  /dev/dsk/c0t0d0s6  73399    50038    16031        76%       /usr  
  /proc              0        0        0             0%       /proc  
  swap               33364    8        33356         0%       /tmp  
  saturn:(pid132)   0        0        0             0%       /root  
  saturn:(pid132)   0        0        0             0%       /home  
  saturn:(pid132)   0        0        0             0%       /src  
  saturn:(pid132)   0        0        0             0%       /nse  
  saturn:(pid132)   0        0        0             0%       /net  
  saturn%  

· How to Display Blocks and Files Used for UFS File Systems
* Type df -F ufs and press Return. A list of UFS file systems, device names, total 512-byte blocks used, and number of files is displayed.
This example is for the same system as the previous example. This command shows only the UFS file systems. Although /proc and /tmp local file systems, they are not UFS file systems (/proc is a PROCFS file system, and /tmp is a TMPFS file system):

  saturn% df -F ufs  
  /                  (/dev/dsk/c0t0d0s0):   21338 blocks    9592 files  
  /usr               (/dev/dsk/c0t0d0s6):   46722 blocks   34103 files  
  saturn%  

· How to Display Blocks and Files Used and Total Blocks and Files for All Mounted File Systems
* Type df -t and press Return. A list of all mounted file systems, device names, total 512-byte blocks used, and number of files is displayed. The second line displays the total number of blocks and files allocated for the file system:

  saturn% df -t  
  /                  (/dev/dsk/c0t0d0s0):     21338 blocks    9592 files  
                                  total:     44398 blocks   11264 files  
  /usr               (/dev/dsk/c0t0d0s6):     46722 blocks   34103  
  files  
                                  total:    146798 blocks   37888 files  
  /proc              (/proc           ):         0 blocks     112 files  
                                  total:         0 blocks     140 files  
  /tmp               (swap            ):     66712 blocks    3177 files  
                                  total:     66728 blocks    3179 files  
  /root              (saturn:(pid132)):         0 blocks      -1 files  
                                  total:         0 blocks      -1 files  
  /home              (saturn:(pid132)):         0 blocks      -1 files  
                                  total:         0 blocks      -1 files  
  /src               (saturn:(pid132)):         0 blocks      -1 files  
                                  total:         0 blocks      -1 files  
  /nse               (saturn:(pid132)):         0 blocks      -1 files  
                                  total:         0 blocks      -1 files  
  /net               (saturn:(pid132)):         0 blocks      -1 files  
                                  total:         0 blocks      -1 files  
  saturn%  

Monitoring Files and Directories

When you have determined (using the df command) which file systems are overloaded, you can use the commands described in Table 10-2 to monitor files and directories.
Table 10-2
CommandInformation Provided
lsSize, age, permissions, owner of files
duTotal size of directories and their contents
quotNumber of blocks owned by users
findNames of files meeting search criteria
These sections tell you how to look for potential problems:

Monitoring System Log Files That Grow

As part of normal system operation, some system log files can grow quite large. Most of these log files are located in the /var directory. Table 10-3 lists examples of some of the system administrative files that can grow daily.
Table 10-3
FileUse
/var/adm/aculogLog of outgoing modem calls
/var/adm/admin.logLog of Administration Tool activities
/var/adm/lastlogHistory of last logins
/var/adm/messagesMessages from syslogd
/var/adm/pacctPer process accounting information (if accounting is turned on)
/var/adm/sa/*System accounting files
/var/adm/sulogHistory of su commands
Table 10-3
FileUse
/var/adm/utmpHistory of user logins
/var/adm/wtmpHistory of system logins
/var/cron/logHistory of actions of /usr/sbin/cron
/var/spell/spellhistWords that spell(1) fails to match
/var/lp/logs/*LP print service logs

Note - If your system is running accounting or system activity reporting (sar), see Security, Performance, and Accounting Administration for a list of associated files that you should also monitor.

· How to Check the Size of Files (in Kilobytes)
  1. Type cd directory and press Return.

  2. Type ls -l and press Return.

    A list of the files and directories is displayed, showing the size in kilobytes.

In this example, you can see that lastlog, wtmp, and wtmpx are substantially larger than the other files in the /var/adm directory.
Code Example 10-1 Checking the Size of Files

  venus% cd /var/adm  
  venus% ls -l  
  total 434  
  -r--r--r--   1 root     other     585872 Jan 28 14:53 lastlog  
  drwxrwxr-x   2 adm      adm          512 Dec  1 16:35 log  
  -rw-r--r--   1 root     other        408 Jan 28 14:15 messages  
  -rw-r--r--   1 root     other        177 Jan 24 16:56 messages.0  
  -rw-r--r--   1 root     other        177 Jan 17 16:13 messages.1  
  -rw-r--r--   1 root     other          0 Jan  4 04:05 messages.2  
  -rw-r--r--   1 root     other        562 Jan  2 13:13 messages.3  
  drwxrwxr-x   2 adm      adm          512 Dec  1 16:35 passwd  
  drwxrwxr-x   2 adm      sys          512 Jan 28 11:38 sa  
  -rw-rw-rw-   1 bin      bin            0 Nov 26 10:56 spellhist  
  -rw-------   1 root     root        1319 Jan 28 14:58 sulog  
  -rw-r--r--   1 root     bin          288 Jan 28 14:53 utmp  

Code Example 10-1 Checking the Size of Files (Continued)

  -rw-r--r--   1 root     bin         2976 Jan 28 14:53 utmpx  
  -rw-rw-r--   1 adm      adm        12168 Jan 28 14:53 wtmp  
  -rw-rw-r--   1 adm      adm       125736 Jan 28 14:53 wtmpx  
  venus%  

· How to Check the Size of Files (in Blocks)
  1. Type cd directory and press Return.

  2. Type ls -s and press Return.

    A list of the files and directories is displayed, showing the size in blocks.

In this example, you can see that lpNet uses eight blocks and lpsched and lpsched-1 use two blocks each.

  venus% cd /var/lp/logs  
  venus% ls -s  
  total 14            2 lpsched-1    0 lpsched-4      0 requests-2  
     8 lpNet        2 lpsched-2    0 requests  
     2 lpsched      0 lpsched-3    0 requests-1  
  venus%  

See "Reducing Overloaded File Systems" on page 186 for information on how to reduce the size of system log files.

Finding Large Files

When you need more space archiving or moving large files obviously recovers more space than moving small files. This section provides some suggestions for commands you can use to locate large files.
· How to Find Large Files (in Blocks)
  1. Type cd directory and press Return.

  2. Type ls -s | sort -nr | more and press Return. The files are sorted by block size from largest to smallest:


  venus% cd /var/adm  
  venus% ls -s | sort -nr | more  
  total 624  
   320 wtmpx  
   128 lastlog  
    74 pacct  
    56 messages  
    30 wtmp  
     6 utmpx  
     2 utmp  
     2 sulog  
     2 sa  
     2 passwd  
     2 log  
     0 spellhist  
  venus%  

· How to Find Files That Exceed a Given Size Limit
* Type find directory -size +nnn -print and press Return. Files above the size you specify (in 512-byte blocks) are listed.
This example shows how to find files with more than 400 (512-byte) blocks in the current working directory:
Code Example 10-2 Finding Files That Exceed a Given Limit

  venus% find . -size +400 -print  
  /home/jones/Howto/howto.doc  
  /home/jones/Howto/howto.doc.backup  
  /home/jones/Howto/howtotest.doc  
  /home/jones/Routine/routineBackupconcepts.doc  
  /home/jones/Routine/routineIntro.doc  
  /home/jones/Routine/routineTroublefsck.doc  

Code Example 10-2 Finding Files That Exceed a Given Limit (Continued)

  /home/jones/.record  
  /home/jones/Mail/pagination  
  /home/jones/Config/configPrintadmin.doc  
  /home/jones/Config/configPrintsetup.doc  
  /home/jones/Config/configMailappx.doc  
  /home/jones/Config/configMailconcepts.doc  
  /home/jones/snapshot.rs  
  venus%  

Finding Large Directories

Use the du command to find large directories. It provides summary totals on directories without listing every file. You can use the du command to get the total size (in blocks) of one or more directories (summing all the files and directories below), the total sizes of each subdirectory, and even the sizes of each file. The du command does not follow symbolic links, and it works only on locally mounted UFS file systems.
If you use the du command with no options, it displays the total block count for the specified directories and the subtotals for each subdirectory. Table 10-4 shows the options for the du command.
Table 10-4 du
OptionDescription
-sDisplays a total block count for the specified directories only, which sums up everything beneath
-aDisplays the total block count for the specified directories, the subtotals for each subdirectory, and the size of each file

Note - You can run du on individual files using the -a or -s option. No size is reported if you run the command on a file without using an option.

· How to Display the Total Size (in 512-byte Blocks) of One or More Directories
* Type du -s directory directory ... and press Return. The sizes of the directory or directories are displayed in 512-byte blocks:

  venus% du -s /usr/sbin /var/adm  
  12672  /usr/sbin  
  574    /var/adm  
  venus%  

· How to Display the Total Size (in 512-byte Blocks) of Directories and Their Subdirectories
* Type du directory directory ... and press Return. The sizes of the directory or directories and all subdirectories are displayed in 512-byte blocks:

  venus% du /usr/sbin /kernel  
  2546    /usr/sbin/static  
  12672   /usr/sbin  
  2108    /kernel/drv  
  36      /kernel/exec  
  1714    /kernel/fs  
  458     /kernel/misc  
  62      /kernel/sched  
  418     /kernel/strmod  
  94      /kernel/sys  
  4892    /kernel  
  venus%  

· How to Display the Total Size (in 512-byte Blocks) of One or More Directories, All Subdirectories, and All Files
* Type du -a directory directory ... and press Return. The sizes of the directory or directories, subdirectories, and all files are displayed in 512-byte blocks:

  venus% du -a /usr/sbin /kernel  
  18      /usr/sbin/add_drv  
  16      /usr/sbin/arp  
  240     /usr/sbin/autopush  
  8       /usr/sbin/chroot  
  22      /usr/sbin/ckbupscd  
  18      /usr/sbin/clri  
  58      /usr/sbin/cron  
  2       /usr/sbin/dcopy  
  42      /usr/sbin/devlinks  
  2       /usr/sbin/devnm  
  30      /usr/sbin/df  
  10      /usr/sbin/dfshares  
  32      /usr/sbin/disks  
  12      /usr/sbin/dispadmin  
  18      /usr/sbin/dname  
  20      /usr/sbin/drvconfig  
  2       /usr/sbin/drvload  
  2       /usr/sbin/eeprom  
  (More files not shown in this example)  
  venus%  

Finding Large Space Users

At times, you will need to find out who is using the most disk space. Type du -s user's home directory to display a summary of the space occupied by each user.
You can also use the quot command to find out who owns the space in any local UFS file system.

Note - The quot command works only on local UFS file systems. If you use the quot command on another file system, the error message filesystem not ufs filesystem is displayed.

· How to Display the User Allocation of a UFS File System
  1. Become superuser.

  2. Type quot filesystem and press Return.

    The users of a file system and the number of 1024-byte blocks used are displayed.

In this example, the users of the root file system are displayed:

  mars% su  
  Password:  
  # quot /  
  /dev/dsk/c0t0d0s0 (st):  
   8130           root  
   2451           bin  
    143           adm  
    109           lp  
     47           uucp  
     19           sys  
      7           pubs  
      1           svvs  
  #  

· How to Display Users for All UFS-Mounted File Systems
  1. Become superuser.

  2. Type quot -a and press Return.

    All users of a file system and the number of 1024-byte blocks used are displayed:


  mars% su  
  Password:  
  # quot -a  
  /dev/rdsk/c0t0d0s0 (/):  
   8130           root  
   2451           bin  
    143           adm  
    109           lp  
     47           uucp  
     19           sys  
      7           pubs  
      1           svvs  
  /dev/rdsk/c0t0d0s6 (/usr):  
  41004           bin  
  15274           root  
   2248           lp  
    759           uucp  
      1           adm  
      1           sys  
  /dev/rdsk/c0t0d0s7 (/opt):  
  78724           root  
  37409           bin  
  /dev/rdsk/c0t3d0s7 (/export/home):  
     23           pubs  
      9           root  
  #  

Finding Old and Inactive Files

Part of the job of cleaning up heavily loaded file systems involves locating and removing files that have not been used recently.
Use the ls -t command on a directory to list the most recently created or changed files first.
Use the find(1) command to locate files that have not been accessed for a specified amount of time. For example, use this command to locate regular files in the /home directory that have not been accessed in the last 60 days and to record the list in a file:

  # find /home -type f -atime +60 -print > /var/tmp/deadfiles &  
  #  

Here is an example of the output from the find command:

  venus% more /var/tmp/deadfiles  
  /home/jones/cat.rs  
  /home/jones/cmdayprint.ps  
  /home/jones/agenericwindow.rs  
  /home/jones/bindericon.rs  
  /home/jones/binderwindow.rs  
  /home/jones/blankkeys.tmp  
  /home/jones/calcalphakeypad.rs  
  /home/jones/calcanglesetting.rs  
  /home/jones/calcbinaryfuns.rs  
  /home/jones/calcicon.rs  
  /home/jones/calclogfuns.rs  
  /home/jones/calclogicalfuns.rs  
  /home/jones/calcmemoryreg.rs  
  /home/jones/calcmiscfuns.rs  
  (More files not shown in this example)  
  venus%  

Reducing Overloaded File Systems

When you have determined which file systems are nearing capacity, you then need to determine the best way to free up additional disk space. This section describes how to free additional space in these ways:

Truncating Files That Grow

A good way to limit the size of files that grow is to periodically truncate them, keeping only the most recent lines at the end of the file.
· How to Truncate a File
  1. Type ls -l filename and press Return.

  2. Record the permissions, user and group ownership, and size of the file you want to truncate.

  3. Become superuser.

  4. Type tail log-name > filename and press Return. The last 10 lines (by default) of the log file are saved in a temporary file. If you want to save more than the last 10 lines, type the number of lines as an option. For example, to save 50 lines, type tail -50 log-name > filename.

  5. Type mv filename log-name and press Return.

    The old log is replaced by the shorter one.

  6. Type ls -l log-name and press Return.

    The permissions, user and group ownership, and size of the log file are displayed.

  1. Check to be sure the permissions and group ownership have not been changed. If they have, change them back to the way they were.

    If you move the files as root, the group ownership may have been changed and members of the group will not be able to access the files until you change the group ownership back to its original value.

In this example, /var/adm/sulog is truncated to contain the 50 most recent entries:

  venus% su  
  Password:  
  # ls -l /var/adm/sulog  
  -rw-------   1 root     root      585872 Jan 29 16:49 /var/adm/sulog  
  # tail -50 /var/adm/sulog > /var/tmp/sulog  
  # mv /var/tmp/sulog /var/adm/sulog  
  # ls -l /var/adm/sulog  
  -rw-r--r--   1 root     other       1424 Jan 29 16:50 /var/adm/sulog  
  # chmod 600 /var/adm/sulog  
  # chgrp root /var/adm/sulog  
  # ls -l /var/adm/sulog  
  -rw-------   1 root     root        1424 Jan 29 16:50 /var/adm/sulog  
  #  

Deleting Old or Inactive Files

You can delete old or inactive files one by one by typing rm filename and pressing Return. Alternatively, you can create a file that contains a list of inactive files. Review the list to make sure the files are no longer needed or are backed up so they can be restored if needed later.
· How to Delete a List of Inactive Files
  1. Become superuser on the server for the file system.

    See NFS Administration Guide if you need information on NFS security.

  2. Type find directory -type f -mtime +nn -print > /var/tmp/deadfiles & and press Return. Files older than the time specified (in days) are listed in the file /var/tmp/deadfiles.

  1. Review the list to be sure all the files should be deleted. Remove the names of the files you want to retain.

  2. Type rm `cat /var/tmp/deadfiles` and press Return. The files listed in /var/tmp/deadfiles are removed.

In this example, all files not modified for more than 60 days listed in the file /var/tmp/deadfiles are removed:

  pluto% su  
  Password:  
  # find /home/jones -type f -mtime +60 -print > /var/tmp/deadfiles &  
  # rm `cat /var/tmp/deadfiles`  
  pluto%  

Clearing Out Temporary and Obsolete Files

The /tmp and /var/tmp directories store temporary files. By default, the /tmp directory is a TMPFS file system, so files in the /tmp directory do not take up space in the / file system. The files in the /tmp directory are deleted each time the file system is unmounted or the system is rebooted. See "The Temporary File System (TMPFS)" on page 4 for more information.
Files in /var/tmp take up file system disk space and are retained if the file system is unmounted or the system is rebooted. You should periodically clear out files in /var/tmp. In addition, look for obsolete files in the subdirectories of /var/spool, such as /var/spool/mail and /var/spool/uucppublic. If there are some files that need to be saved, delete the files individually by name rather than using the wild card *, as shown below.

Note - Unless your site has a specific policy about deleting old /var/spool/mail and /var/spool/uucppublic files, it is a good idea to check with the owner of these files before deleting them. If you need space in the file system, consider moving the entire file to the user's home directory and starting a new spooling file.

· How to Clear Out the /var/tmp Directory
  1. Become superuser.

  2. Type cd /var/tmp and press Return.


CAUTION Caution - Be sure you are in the right directory before using a potentially destructive command like rm -r *.

  1. Type rm -r * and press Return.

    All files and subdirectories are deleted.

  2. Change to subdirectories in /var/spool (for example, mail), look for obsolete files, and delete them.

Deleting core Files

From time to time a program may crash and leave a dump of what was in memory in a file named core. These core files can be useful to help the company that developed the software product to determine the cause of persistent problems. core files may be quite large. When a program crashes repeatedly, it overwrites any existing core file with the new information, so that, within any give directory, core files do not accumulate. core files can, however, be created in different directories depending on which program was running when the dump was done.

Note - Instruct users not to use core as a name for any of their files. If users create files named core, these files will be overwritten if a program crashes in that directory.

· How to Find and Delete core Files
  1. Become superuser.

  2. Change to the directory where you want to start the search.

  3. Type find . -name core -exec rm {} \; and press Return. Any core files found in the current directory and its subdirectories are removed:


  pluto% su  
  Password:  
  # cd /home/jones  
  # find . -name core -exec rm {} \;  
  #  

Removing Crash Dump Files

Crash dump files are core files that contain an image of the state of the operating system kernel at the time that it failed. This image can be used to look at the control structures, active tables, and other relevant information about the operation of the kernel. This information may be useful in reporting or tracking down kernel bugs. Some systems may be set up to automatically save information about kernel crashes in the /var/crash/system-name directory. To uniquely identify each crash dump, the files are named sequentially vmcore.n. The number n is incremented for each subsequent crash dump. If the system is experiencing kernel problems, the size of the crash dump directory can become quite large.
· How to Delete Crash Dump Files
  1. Become superuser.

  2. Type cd /var/crash/system-name and press Return.

  3. Type rm * and press Return.

See Common Administration Tasks for more information about crash dumps.

Creating Links Instead of Duplicating Files

Sometimes you need to have the same file in more than one place. For example, when files are moved you may want to retain the old path name so that software that uses an absolute path name can find them. Putting the files in both directories unnecessarily uses disk space. You can use links to provide alternative path names for individual files so the data is stored in only one place.
You can create two kinds of links:
  • Symbolic links can be located anywhere and provide a pointer to the name of the file they link to. Symbolic links can span physical devices and are thus very useful in a networked environment.
  • Hard links use the same inode number and must be used within the same file system. You cannot, for example, create a hard link between a file in the root directory and a file in a user's home directory.
See the ln(1) manual page for more information.
· How to Create a Symbolic Link
* Type ln -s source-filename linked-filename and press Return. source-filename is the name of an existing file and linked-filename is the name of the file to create as a symbolic link to source-filename.
· How to Create a Hard Link
* Type ln source-filename linked-filename and press Return. The file named by source-filename must exist and must be in the same disk slice (file system) as the file named by linked-filename.

Moving Directory Trees Between File Systems

As user needs change and file systems approach maximum capacity, you may need to move user accounts from one file system to another.
· How to Move Directory Trees From One File System to Another
  1. Notify affected users, preferably by email, that you plan to move their files and that path name dependencies may need to be changed.

  2. Become superuser.

  3. Type cd /filesystem1 and press Return.

  4. Type find username -print -depth | cpio -pdm /filesystem2 and press Return.

    The files are copied and symbolic links are preserved.

  5. To verify that the copy was successful, type cd /filesystem2/username;ls and press Return.

  6. To remove the old directory tree, type rm -rf /filesystem1/username and press Return.

  7. Use admintool to change the username default login directory in the Passwd Database.

    See User Accounts, Printers, and Mail Administration for information on how to use the Administration Tool.

Controlling Disk Space With Quotas

Disk space is always a limited resource. One way you can control available disk space is through the way you set up and allocate available file system space to your users. Another way to control disk space for UFS file systems is to set up and administer disk quotas. Disk quotas let you set limits for each user of a file system to control the maximum number of files each user can create and the maximum amount of disk space available to each user.
Each quota has two limits: a hard limit and a soft limit. Users other than root can never exceed the hard limit. When the hard limit is reached, the operating system notifies the user and refuses to allocate any more resources. Users can exceed the soft limit temporarily for a limited period of time. The user receives a warning message, and the operating system allocates the additional resources. If the disk use exceeds the soft limit at the next login, the warning message is repeated. Depending on how quotas are implemented, users who continue to exceed the soft limit will be denied access to additional resources until enough files are deleted to bring disk usage below the soft limit.
If you implement a quota system, you must decide which file systems need quotas. Usually, the file systems that contain user home directories are good candidates for quotas. You do not need to set quotas for /tmp file system or for the file systems reserved for public files (for example, the / and /usr file systems) unless they are writable and can grow.
Quotas have a slight impact on performance, require some administration, and may inconvenience users. Consider implementing quotas only if disk space is very limited and tight security is required at your site.
The quotas utility lets you:
  • Set up quotas for each user in a file system
  • Turn the enforcement of quotas on and off for each file system
  • Report on the quotas defined and the current disk use for each user of each file system
  • Synchronize the recorded use with the actual disk use

Setting Up and Administering Quotas

Before you begin to set quotas, you need to do some system configuration. The following steps briefly describe how to set up quotas. See "How to Configure File Systems for Disk Quotas" on page 198 for detailed instructions.
  1. Edit /etc/vfstab to flag file systems with an rq mount option.

  2. Create a quotas file in the top directory of each file system.

  3. Use the quotas editor edquota to set up the limits for the quotas.

  4. Use quotaon to turn on the quotas so they begin to be enforced.

When quotas are set up, you can administer them in these ways:
  • Turn quotas on and off for specified file systems
  • Change the time limit (that applies to all users)
  • Change the quotas (hard and soft limits on blocks and files) for individual users
  • Disable quotas for an individual user
  • Ensure the consistency of recorded disk use on specified file systems with actual disk use
  • Report on the current quotas and disk use for individuals or all users
Table 10-5 describes the commands you use to set up and administer disk quotas.
Table 10-5
CommandTask
edquota(1M)Set or change the hard and soft limits on the number of files and/or disk space for each user. In addition, define the time period for each file system that its soft limits can be exceeded by any user.
quot(1M)Display information for a specified file system on the number of files and 1024-byte blocks owned by each user on the system.
quota(1M)Display user quotas and current disk use. You can also display user over-quota use.
quotaon(1M)Turn on (enforce) the quotas for the specified file systems.
Table 10-5
CommandTask
quotaoff(1M)Turn off quotas for the specified file systems.
quotacheck(1M)Check the number of blocks and files owned by each user for a given file system and update the information in the quota file so that it is consistent with the current state of the disk.
repquota(1M)Display the quotas in force for each user and the current number of files and amount of space they own for the specified file systems.

How Quotas Affect Users

When users exceed the soft limit for blocks or inodes, the timer is started. No warning messages are displayed. If users then reduce usage to a level under the soft limit, the timer is turned off. If the user has not reduced usage to an appropriate level when the timer expires, error messages are displayed saying that the file system is full. Any further attempts by the user to acquire more file system resources fail. The messages persist until the user has reduced usage to a level below the soft limit.
Any time users try to exceed the hard limit, an error message is displayed saying that the file system is full. No further disk resources are allocated.
Users can run the quota command to find out how much file system space is available and whether they have exceeded the soft limit. Users should be encouraged to include quota in their .profile or .cshrc file so that it is run automatically when they log in.

How Disk Quotas Work

The quotas system uses a file named quotas to control available disk space for each file system. The edquota command generates information to set up or change the limits for specified users on specified file systems. The information from the edquota command is stored in the quotas file. The quotas file is used by the UFS utilities and the quotacheck command to record the actual use of disk space. Each user on the system has an entry in each quotas file, whether or not quotas have been imposed on them for that file system. These entries are indexed by user ID and are kept in binary form.
Each time you add or modify quotas for a specified user, edquota looks in /etc/mnttab to see which UFS file systems are mounted, and it checks the root directory of each file system for a quotas file. edquotas then creates a temporary text file from the binary quotas files. You edit the file and save the changes. The resulting file is then converted back to the binary format quotas file.
After quotas are set up, you must turn them on for each file system with the quotaon and quotaoff commands. The quotaon and quotaoff commands turn quotas on and off by changing the entry in the mntopts field of the mount table /etc/mnttab. When the entry is rq, it means read/write with quotas in effect. quotaon can turn on file systems specified on the command line or turn on all file systems that have rq in the mntopts field of the /etc/vfstab file. The latter option is normally used in a startup script (for example, /sbin/rc2) to turn on all quotas when the system boots up.
Figure 10-1 shows how disk quotas operate.

Графика

· How to Configure File Systems for Disk Quotas
You add entries to the /etc/vfstab file to activate quotas for specified file systems each time they are mounted, and create a file named quotas in the top-level directory of each file system for which you want to use quotas.
  1. Become superuser.

  2. Edit /etc/vfstab, enter rq in the mount options field for each UFS file system to have quotas, and save the changes.

    File systems with rq in the mount options field have quotas automatically turned on when the system boots.

  3. Change to the top directory of the file system.

    For example, to turn on quotas for the /home file system, type cd /home and press Return.

  4. Type touch quotas and press Return.

    A file named quotas is created.

  5. Type chmod 600 quotas and press Return. Permissions are changed to read/write for root only.

· How to Change the Default Time Limit
The default soft limit time is one week. After one week of repeated violations of the soft limit, users cannot access additional system resources. If you want to use a different time limit for a file system, you can change it by following the steps in this section. You can set the time limit only for an entire file system.
  1. Become superuser.

  1. Type edquota -t and press Return.

    The default editor opens a temporary file that includes a line for each mounted file system with a quotas file in its top directory. For example, if the file system /files is the only such mounted file system, this information is displayed:


  fs /files blocks time limit = 0 (default), files time limit = 0 (default)  

The 0 (default) value means that the default time limit of one week is used.
  1. Replace the 0 with a number and a unit.

    You can specify the units by month, week, day, hour, min, or sec. For example, to change the limit to one day, you could specify either 1 day or 24 hour.

  2. Exit the file, saving your changes.

· How to Set Up User Quotas
Before you set up user quotas, you need to determine how much space and how many files to allocate to each user. If you want to be sure the total file system space is never exceeded, you can divide the total size of the file system between the number of users. For example, if three users share a 100-Mbyte slice and have equal disk space needs, you could allocate 33 Mbytes to each. In environments where not all users are likely to push their limits, you may want to set individual quotas so that they add up to more than the total size of the file system. For example, if three users share a 100-Mbyte slice, you could allocate 40 Mbytes to each.
If all values are set to 0, quotas are disabled. Set both soft and hard block values in 1-Kbyte disk blocks, and set both soft and hard values for the total number of files (inodes).
  1. Type edquota username and press Return.

    The default editor opens a temporary file with one line for each mounted file system that has a quotas file in its top-level directory. For example, if the file system /files is the only one that has a quotas file in its top-level directory, this information is displayed:


  fs /files blocks (soft = 0, hard = 0) inodes (soft = 0, hard = 0)  


Note - Although you can specify multiple users as arguments to the edquota command, the information displayed does not show which user it belongs with, which could create some confusion.

  1. Enter the number of 1-Kbyte disk blocks, both soft and hard, and the number of inodes, both soft and hard.

  2. Exit the editor, saving your changes.

· How to Use a Prototype Quota for Multiple Users
When you have established quotas for one user, you can use those quotas as a prototype to set the same quotas for other users on the same file system.
  1. Become superuser.

  2. Type edquota -p user-with-quotas username1 username2 username3 ... and press Return.

    The quotas you already established for the prototype user are set for the additional users you specify.

For example, to apply the quotas established for user ignatz to users mercury and pluto, type:

  edquota -p ignatz mercury pluto  

· How to Initialize Quotas
Once you have configured file systems for quotas and established quotas for each user, you need to run the quotacheck command to initialize the quota files and check consistency with the file system before you turn quotas on.
  1. Become superuser.

  2. Type quotacheck -a and press Return.

    All file systems with an rq entry in the /etc/vfstab file are checked and assigned correct initial values.

You can run quotacheck on individual file systems by typing quotacheck /dev/dsk/filesystem and pressing Return. For example, to check quotas for /files on slice /dev/dsk/c0t4d0s2, type:

  quotaon /dev/dsk/c0t4d0s2  

· How to Turn Quotas On
The quotas you set up with edquota are not enforced until you turn them on. You can turn them on and off any time from a command line. You usually turn them on once after you set them up. If you have properly configured the quota files, quotas are automatically turned on each time a system is rebooted and the file systems are mounted.
  1. Become superuser.

  2. Type quotaon -a and press Return.

    All file systems with an rq entry in the /etc/vfstab file are turned on.

You can turn quotas on for individual file systems by typing quotaon filesystem filesystem ... and pressing Return. For example, to turn on quotas for /files on slice /dev/dsk/c0t4d0s2 and /snag on slice /dev/dsk/c0t3d0s2, type:

  quotaon /dev/dsk/c0t4d0s2 /dev/dsk/c0t3d0s2  

Administering Disk Quotas

This section describes how to perform these tasks for administering disk quotas:
  • Turn quotas on and off for specified file systems
  • Change the soft limit time for a file system
  • Change the quotas (hard and soft limits on blocks and files) for individual users
  • Disable quotas for an individual user
  • Ensure the consistency of recorded disk use with actual disk use
  • Report on the current quotas and disk use for individual or all users
· How to Turn Quotas Off
  1. Become superuser.

  2. Type quotaoff /dev/dsk/cntndnsn and press Return. Quotas are turned off for the file system you specify.

Alternatively, type quotaoff -a and press Return to turn off quotas for all file systems.
· How to Change the Soft Limit Time
  1. Become superuser.

  2. Type edquota -t and press Return.

    The default editor opens a temporary file that includes a line for each mounted file system with a quotas file in its top directory. For example, if the file system /files is the only mounted file system, this information is displayed:


  fs /files blocks time limit = 0 (default), files time limit = 0 (default)  

The 0 (default) value means that the default time limit of one week is used.
  1. Replace the 0 with a number and a unit.

    You can specify the units by month, week, day, hour, min, or sec. For example, to change the limit to one day, you could specify either 1 day or 24 hour.

  2. Exit the file, saving your changes.

· How to Change Quotas for Individual Users
  1. Type edquota username and press Return.

    The default editor opens a temporary file with one line for each mounted file system that has a quotas file in its top-level directory. For example, if the file system /files is the only one that has a quotas file in its top-level directory, this information is displayed:


  fs /files blocks (soft = 0, hard = 0) inodes (soft = 0, hard = 0)  


Note - Although you can specify multiple users as arguments to the edquota command, the information displayed does not show which user it belongs with, which could create some confusion.

  1. Enter the number of 1-Kbyte disk blocks, both soft and hard, and the number of inodes, both soft and hard.

  2. Exit the file, saving your changes.

· How to Disable Quotas for Individual Users
To disable quotas for individual users, follow the procedure for changing quotas, and change all values to zero.

Note - Be sure you change the values to zero. Do not delete the line from the text file.

· How to Check Quota Consistency
Information about disk quotas stored in the quota administration files can get out of synchronization with actual disk use. Just as general file system information can become inaccurate over time, abrupt system halts and crashes can degrade the quota information.
When setting up quotas, you should run the quotacheck command manually before turning quotas on. It is a good idea to periodically run the quotacheck command if systems are rebooted infrequently.

Note - To ensure accurate disk data, file systems should be quiescent when you run the checkquota command. You could create a cron script to perform this activity. See the cron(1M) manual page for more information.

  1. Become superuser.

  2. Type quotacheck -a and press Return.

    All file systems with an rq entry in the /etc/vfstab file are checked and assigned correct initial values.

You can run quotacheck on individual file systems by typing quotacheck /dev/dsk/filesystem and pressing Return. For example, to check quotas for /files on slice /dev/dsk/c0t4d0s2, type:

  quotacheck /dev/dsk/c0t4d0s2  

· How to Report on Quotas and Disk Use
To quickly find out if any quotas are being exceeded:
* Type quota and press Return. Warnings about mounted file systems where usage is over the quota for the current user are displayed.
To report the quotas and disk use for an individual user on file systems to which quotas apply:
  1. Become superuser.

    Only privileged users can display information about other users' quotas.

  1. Type quota -v and press Return.

    User quotas on all mounted file systems where quotas are enabled are displayed.

To report on quotas and disk use for all users on one or more file systems:
  1. Become superuser.

  2. Type repquota -v /dev/dsk/cntndnsn and press Return. All quotas for the specified file system are displayed, even if there is no usage.

Alternatively, use repquota -a to report on all file systems.
To display information about file ownership for a file system:
  1. Become superuser.

  2. Type quot /dev/dsk/cntndnsn and press Return. A list of users is displayed with the number of 1024-byte blocks currently owned by each user.


Note - The quot command and the quota command are two different commands. Use quot whether or not quotas are enabled to find out information about which users are accessing disk space in a file system. See the quot(1M) manual page for other options.


  pluto% su  
  Password:  
  # quot /dev/dsk/c0t3d0s0  
  /dev/dsk/c0t3d0s0 (/export/home):  
   7596   root  
   2402   bin  
    202   lp  
    178   adm  
     47   uucp  
     22   sys  
      8   jones  
      1   svvs  
  #