Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Absolute BSD - The Ultimate Guide To FreeBSD (2002).pdf
Скачиваний:
25
Добавлен:
17.08.2013
Размер:
8.15 Mб
Скачать

When you open the hard drive's case you'll find a stack of round disks, commonly called platters. When the disk drive is on, these platters (commonly made of glass or plastic) spin at thousands of revolutions per minute (RPM). The RPM count on hard drives is a measure of platter rotation speed.

The platters are covered with a layer of magnetic material, which itself is usually covered in iron oxide.[2] This magnetic material is arranged in thousands of circular rings, called tracks, that extend from the platter's inner core to its outer edge, much like growth rings in a tree. These tracks hold data as strings of zeros and ones. Each track is subdivided into sectors, and each sector on the outer tracks holds more data than that same sector on an inner track, and it takes less time to read the same amount of data on an outer track than on an inner track because any point on an outer track is moving faster.

Heads sit over each platter, and all data written to or read from the platters passes through those heads. As a rule, these heads can read and write data quickly, but they have to wait for the disk to move into the proper position under them so that the data can be transferred. Drive performance basically boils down to how quickly those rusty platters can move under the drive heads, which is why RPM is so important.

Each track holds blocks of data, the size and placement of which restricts how efficiently the filesystem works and what sorts of files it can best handle. Each filesystem uses its own particular index to record the placement of data on the platters, and one operating system can't necessarily read another's index. (DOS used a single File Allocation Table (FAT), later expanded to FAT12, FAT16, FAT32, and so on.) The UNIX Fast File System (FFS) uses many scattered index nodes, or inodes, instead.

[2]Yes, iron oxide is rust. Please do not add rust to your platters to make them hold more data; I proved it doesn't work many years ago.

The Fast File System

FreeBSD's filesystem, the Fast File System (FFS) is a direct descendant of the filesystem shipped with BSD4.4. (In fact, as of this writing, one of the original filesystem authors is still developing the FreeBSD filesystem, adding a lot of the nifty features we'll discuss shortly.) FFS is sometimes called UFS for UNIX File System, and many system utilities still call FFS partitions UFS.

Note FFS has moved from BSD into several other vendors. If a UNIX vendor doesn't specifically tout their "improved, advanced" filesystem, they're almost certainly running the BSD filesystem.

FFS is designed to be fast and reliable, and to handle the most common (and uncommon) situations as effectively as possible. FreeBSD ships FFS configured to be as widely useful as possible on relatively modern hardware, but you can choose to optimize it for trillions of small files or a half−dozen 30GB files, if you choose. You don't have to know a huge amount about FFS's internals, but you should know a few basics. To begin with, it helps to know that FFS divides the disk into inodes and blocks.

Inodes Inodes contain very basic information about files, including permissions, size, and so on, as well as a list of the blocks in the file. Collectively, the data in an inode is known as metadata, which is simply data about data.

Blocks Blocks contain the file's actual data.

370

While inodes contain lots of different information, all you need to know is that they're the index of the file on the disk. They are what allows the operating system to find the information it's attempting to retrieve.

Vnodes

Inodes and blocks worked wonderfully back in the early days of UNIX. As years passed, however, it became normal to swap disks between different machines and even different operating systems. CD−ROMs, with their unique layout, became popular; floppy disks slowly converged on FAT32 as a standard; and other UNIXes developed their own variant filesystems. Because BSD needed to speak to all these different systems, another layer of abstraction was needed.

That abstraction was the virtual node, or vnode. You never manipulate vnodes directly, but you'll see references to them throughout the system documentation, so it's important to know what they are. The vnode is a translator between the kernel and whatever sort of filesystem you've mounted. When you write a file to an FFS filesystem, the vnode talks to an inode. When you write a file to a Microsoft−style FAT filesystem, the vnode talks to the file allocation table. (Vnodes are actually used for far more than talking to the filesystem, but we won't get into that here.)

Every tool that reads and writes to disks actually does so through vnodes, which map the data to the appropriate filesystem for the underlying media. You'll see references to inodes only when dealing with FFS filesystems, but you'll see vnodes when you deal with any filesystem.

FFS Mount Types

Unlike Windows or Macintosh filesystems, FFS partitions can be treated in several different ways depending on how they're mounted. The manner in which a partition is mounted is called the mount type. Remember that, as discussed in "Device Nodes," earlier in this chapter, you must know a filesystem's physical device name in order to mount it. And an unmounted filesystem cannot be accessed. You cannot read it, write to it, or see it in any way. You're stuck.

To change the boottime mount options on a partition, add the options to the appropriate line in /etc/fstab in the "options" column.

Read−Only Mounts

If you only want to look at the contents of a disk, and not write to it, you can mount the partition as read−only (or rdonly). This is unquestionably the safest way to mount a disk, and one of the most useless ways to mount a disk for many server uses, because you cannot alter the data or write new data.

Many systems administrators mount the root partition, and perhaps even /usr, as read−only to minimize any potential system damage from a loss of power. Even if you lose the physical hard drive due to a power surge or some other hardware failure, the data on the platters remains intact. That's the advantage of read−only mounts; the disadvantage is that it makes maintenance far more difficult because you can't write to read−only mounted disks!

Synchronous Mounts

Synchronous (or sync) is the old−fashioned way of mounting a filesystem. When a disk is synchronously mounted, you can read from it much as you would expect, but when you write to it, the kernel waits to see whether the write is actually completed before telling the program that the

371

write is completed. If it isn't completed, the program can choose to act appropriately.

Synchronous mounting provides the greatest data integrity in the case of a crash, but it is also slow. ("Slow" is a relative term these days, when even a cheap disk can outperform what was the top end several years ago.) Consider using synchronous mounting when you wish to be truly pedantic on data integrity, but in most cases it's truly overkill.

Asynchronous Mounts

For faster access at a higher risk of data loss, mount your partitions asynchronously (async). When a disk is asynchronously mounted, the kernel writes data to the disk, and tells the program that the write was successful without waiting for the disk to confirm that the data was actually written. Asynchronous is fine on disposable machines, but don't use it with important data.

Noasync Mounts

Finally, we have a method that combines sync and async, called noasync; this is FreeBSD's default. When using noasync, data that affects inodes is written to disk synchronously, while the actual data is handled asynchronously. Noasync is used in combination with soft updates (see the "Soft Updates" section later in the chapter) to create a truly robust filesystem.

FFS Mount Options

FreeBSD supports several mount options in addition to the mount types. While you don't need to know the details of all of the mount options, you should at least know that they exist, should you encounter a circumstance that requires one.

noatime Every file on FFS includes an access−time stamp, called the atime, which records when the file was last accessed. If you have a large number of files and don't need this data, you can mount the disk noatime and not have this time−stamp updated.

noexec The noexec mount option prevents any binaries from being executed on this partition. Mounting /home noexec can help to prevent users from installing and running their own programs, but for it to be effective, be sure to also noexec mount /tmp, /var/tmp, and any other places that they can write files.

nosuid The nosuid option prevents setuid programs from running on your system. Setuid programs allow users to run programs as if they're another user. For example, some programs (such as login(1)) must be run by root, but if you make login setuid, anyone can run it and it will work.

Setuid programs obviously must be carefully written so that they can't be exploited and used to get unauthorized access to your system. As such, many administrators habitually disable all unneeded setuid programs. You can use nosuid to do so, but it will be useless if you have a script wrapper that allows you to run scripts as setuid, such as suidperl, on the system.

nosymfollow The nosymfollow option disables symlinks, or aliases, to files. (Symlinks are mainly used to create aliases to files that reside on other partitions, anyway.) To create an alias to another file on the same partition mounted nosymfollow, use a regular ln(1)−style link.

nodev Finally, the nodev option disallows using any device nodes on the filesystem, which can help prevent mistakes if you're accessing a drive used by another UNIX. Disallowing device nodes

372