10.4. Mounting and Unmounting Filesystems

The filesystem is best visualized as a tree, rooted, as it were, at /. /dev, /usr, and the other directories in the root directory are branches, which may have their own branches, such as /usr/local, and so on.

There are various reasons to house certain of these directories on separate filesystems. /var contains log, spool, and various types of temporary files, and as such, may get filled up. Filling up the root filesystem isn't a good idea, so splitting /var from / is often a good idea.

Another common reason to contain certain directory trees on other filesystems is if they are to be housed on separate physical disks, or are separate virtual disks, such as Network File System mounts, or CDROM drives.

10.4.1. The fstab File

During the boot process, filesystems listed in /etc/fstab are automatically mounted (unless they are listed with noauto).

The /etc/fstab file contains a list of lines of the following format:

    device	/mount-point	fstype	options	dumpfreq	passno

device is a device name (which should exist), as explained in the Disk naming conventions above.

mount-point is a directory (which should exist), on which to mount the filesystem.

fstype is the filesystem type to pass to mount(8). The default FreeBSD filesystem is ufs.

options is either rw for read-write filesystems, or ro for read-only filesystems, followed by any other options that may be needed. A common option is noauto for filesystems not normally mounted during the boot sequence. Other options in the mount(8) manual page.

dumpfreq is the number of days the filesystem should be dumped, and passno is the pass number during which the filesystem is mounted during the boot sequence.

10.4.2. The mount Command

The mount(8) command is what is ultimately used to mount filesystems.

In its most basic form, you use:

    # mount device mountpoint

There are plenty of options, as mentioned in the mount(8) manual page, but the most common are:

mount options

-a

Mount all filesystems in /etc/fstab, as modified by -t, if given.

-d

Do everything but actually mount the filesystem.

-f

Force the mounting the filesystem.

-r

Mount the filesystem read-only.

-t fstype

Mount the given filesystem as the given filesystem type, or mount only filesystems of the given type, if given the -a option.

"ufs" is the default filesystem type.

-u

Update mount options on the filesystem.

-v

Be verbose.

-w

Mount the filesystem read-write.

The -o takes a comma-separated list of the options, including the following:

nodev

Do not interpret special devices on the filesystem. Useful security option.

noexec

Do not allow execution of binaries on this filesystem. Useful security option.

nosuid

Do not interpret setuid or setgid flags on the filesystem. Useful security option.

10.4.3. The umount Command

The umount command takes, as a parameter, one of a mountpoint, a device name, or the -a or -A option.

All forms take -f to force unmounting, and -v for verbosity.

-a and -A are used to unmount all mounted filesystems, possibly modified by the filesystem types listed after -t. -A, however, doesn't attempt to unmount the root filesystem.