Monitoring Filesystem Usage


FreeBSD's filesystem is a single large directory hierarchy beginning at /, the root level. Each partition of your hard disk (or disks) is assigned its own local hierarchy, and the partitions are attached to FreeBSD's filesystem structure at different designated mount points. To keep an eye on how much disk space is being used by your data, you need to look at each mounted filesystem in turn, beginning at each one's mount point.

The idea of mount points is an aspect of UNIX-style operating systems that is quite foreign to Windows users. In Windows/DOS, each disk in your system is assigned a drive letter (such as C:), and each drive has its own independent filesystem. For example, a machine with two hard drives and a CD-ROM drive might have C:, D:, and E: drives between which the user can switch. In UNIX, there is only one systemwide directory structure, and all disks in the system are mounted at different points in the structure, at the administrator's discretion. An appropriate analogy would be that a Windows system resembles an orchard, with a row of similar trees, whereas a UNIX system is more like a single large tree, with smaller trees grafted onto its trunk and branches. All the grafted elements on the UNIX "tree" form a single hierarchical structure (see Figure 12.2).

Figure 12.2. Diagrams of the FreeBSD (UNIX) and Windows filesystem structures, using the "tree" analogy.


The advantage of this type of structure is that it's really easy to add more disk space to your system. To increase the pool of storage available to some part of the hierarchy, you just mount a new disk or partition there (as you'll learn later in this chapter). However, a corresponding disadvantage is that it's much harder in a filesystem like this to move the entire contents of a disk wholesale to another disk. In Windows or Mac OS, you can move your entire system to a new larger disk with a simple drag-and-drop operation because each disk is a separate filesystem. This task is more cumbersome in FreeBSD. The hierarchical structure is better suited to a server machine with a long lifetime on the same hardware than to a desktop computer where the data often outlives the hardware.

The df (Disk Free) Command

Using the df (disk free) command is the most direct way of finding out the status of your system's disk usage. A df reading is part of every daily status check (more on this in Chapter 15, "Performance Monitoring, Process Control, and Job Automation," in the section "Using the Periodic Task Scheduler"), and it nicely encapsulates all the relevant information about your different filesystems and their respective device names.

When you enter the command df, you get output similar to this:

Filesystem  1K-blocks     Used    Avail Capacity  Mounted on /dev/ad0s1a    128990    74314    44358    63%    / devfs               1        1        0   100%    /dev /dev/ad0s1f    257998       44   237316     0%    /tmp /dev/ad0s1g   8027686  1990866  5394606    27%    /usr /dev/ad0s1e    257998    30586   227694    14%    /var


Each disk slice or partition is regarded as a "filesystem" and can be mounted at any point in the directory structure. The preceding output shows that this system has four BSD partitions on its main IDE disk (/dev/ad0) and that they are mounted at /, /tmp, /usr, and /var. This is the default setup for a FreeBSD installation. Note that the / filesystem has only about 128MB allocated to it and that /var and /tmp each have about 256MB; all the rest of the disk is allocated to /usr. This means that the system defaults expect very little to be placed into the directories other than /usr or /var, and still less to go into /var.

The numbers in the df output will not necessarily calculate out the way you might expect. The figures you see are subject to a number of delays and estimations due to caching and other issues. They are as accurate as possible in a system where this information must be gathered on an ongoing basis from many constantly changing sources.

Caution

Allocating a small /var partition can be dangerous because log files traditionally go into /var/log, and log files are notorious for growing out of control. Many administrators choose to move /var to /usr/var and create a /var symlink to point to it. We will discuss the pros and cons of different styles of partitioning in Chapter 20.


The du (Disk Usage) Command

Aside from the df command, you also need to have a more specific method for monitoring disk usage, especially if you're running a network server and you have a lot of users, any of whom might suddenly dump gigabytes of data into their home directories. For this, the tool of choice is du (disk usage). Here's an example:

# du -h -d 1 /home/  23M    /home/bob   9K    /home/fred  31K    /home/alice 1.5M    /home/tom 664K    /home/pat


The du command tells you the size, recursively, of every directory below the one you're currently in (or the one you specify on the command line). You can specify the -d switch along with a number, which tells du to recurse only down to that depth (a necessity unless you want to be flooded with output); the h switch (for "human readable") formats the sizes of the directories into kilobytes and megabytes. You can also use the -s option, which forces "summary" mode. In this mode, you only get a single line of output, listing the aggregate size of everything in the directory you specified. You can find more options to du, including controls for the way it handles symbolic links, in man du.

All this, of course, places the burden of watching the filesystems on you, the administrator. Wouldn't it be great if you could rely on the system to keep tabs on these things for you? Fortunately, you canwith quotas, which you'll learn about in "Setting and Enforcing User Disk Usage Quotas," later in this chapter.




FreeBSD 6 Unleashed
FreeBSD 6 Unleashed
ISBN: 0672328755
EAN: 2147483647
Year: 2006
Pages: 355
Authors: Brian Tiemann

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net