Mounting and Unmounting FreeBSD Filesystems


Now, we will discuss how the versatility of UNIX-style filesystems can really shine. Let's say your system outgrows its single disk (/dev/ad0), and you install another disk as the primary slave so that it appears as /dev/ad1 (a SCSI disk would be available as /dev/da0, and so on). After you partition and label the disk (a procedure that is described in detail in Chapter 20), you have one or more new filesystems you can add to your system's directory structure at any point, like grafting a new branch onto the trunk of a tree.

The mount Command

Suppose, for instance, you have a system in which you have been adding new users left and right, and they keep uploading large files into their home directories. You notice (through the use of df and du) that the /usr partition is almost full, almost entirely because of the growing /usr/home. What you want to do is add another pool of storage space and dedicate it to your users and their home directories.

Caution

The instructions in this section are best followed when your system is in single user mode, so that no remote users or applications disturb the filesystems you're working on. Be sure to work directly at the system's console rather than from a remote terminal, and boot your system in single user mode (choose option 4 at the loader screen) before you start reconfiguring your filesystems.


You therefore buy a new 400GB disk and divide it into three BSD partitions within the single FreeBSD slice; they are available as /dev/ad1s1e (10GB), /dev/ad1s1f (50GB), and /dev/ad1s1g (300GB). You make the third partition the largest because it's the one you want to make into the new home for your users; the other two partitions are chunks of space you want to add to other parts of the system. But for now, all you're interested in doing is turning /home into a new 300GB partition for nothing except users' home directories.

Right now, /home is most likely a symbolic link to /usr/home, so you will first want to use rm /home to get rid of the symlink. (The actual /usr/home directory that the symlink points to is not touched by this command.) If /home in your system is not a symlink but is instead a plain directory, use something like mv /home /home.old to move it temporarily out of the way for this process.

Now, create a mount point for the new filesystem. Mount points (also known as nodes) must be plain directories. They don't need to be empty, but after a device is mounted on a non-empty directory, whatever was originally located in that directory will no longer be accessible. To have the files and the mounted filesystems simultaneously accessible, union filesystems are needed, but this feature is not fully supported as of this writing. Therefore, to create the new mount point, issue mkdir /home.

You're now ready to mount the new filesystem. For standard FreeBSD filesystems, you do this with the mount command. Your 300GB partition is labeled /dev/ad1s1g, so give the following command:

# mount /dev/ad1s1g /home


If the command executes without any errors, you should be able to use the new filesystem immediately. Check df to see if it worked:

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


The /home partition is now mountedit looks like it's ready to go! You can now move the files from /usr/home (or /home.old, depending on where your home directories have been sitting in the interim) into the new /home filesystem, and your users will be free to upload to their hearts' content.

It isn't always this easy, however. Mounting filesystems is one of the areas of system administration that has the most potential pitfalls for the unwary. You may get the error message "Incorrect super block," for instance, or you may get an even less informative message, such as "Invalid argument." These messages usually stem from improperly specifying the name of the device on the mount command line; the device naming conventions used by the FreeBSD labeling system can lead to serious confusion. A filesystem might be labeled as /dev/ad1s1e or /dev/ad1s1, depending on whether it is being addressed in "slice mode" or "dedicated mode," and certain device names with suffixes can be interchangeable with shorter names. This disk geometry esoterica is discussed thoroughly in Chapter 20.

The mount command has the -f option, which will force a mount operation even in circumstances where it might otherwise fail. However, if a filesystem won't mount, it's usually for a good reason. It's a much better idea to find the cause for any error and fix it rather than use the -f option. Some of these causes might include an unformatted disk, a filesystem of an unrecognized type, or a "dirty" filesystem that was not shut down properly. In the latter case, the filesystem might have some inconsistencies that must be repaired using fsck (as you learn in "Checking and Repairing Filesystems with fsck," later in this chapter) before the filesystem can be mounted.

One other useful argument to note is the options field, in which you can specify any code words (flags) from a large list of code words, separated by commas. Most useful are the ones specifying whether the filesystem is read-only or read/write; it is read/write by default, but you can use the -r or rdonly option to make it read-only. See man mount for a full list of mount options.

You also use mount whenever you insert a CD-ROM, DVD, or floppy disk into the system; if you don't, you won't be able to access the media. See "Mounting and Unmounting CD-ROM and Floppy-Based Filesystems" later in this chapter for more information.

Note

Mounting filesystems is typically something that only the root user can do. This isn't a big deal for hard disk partitions (you don't want regular users mucking around with your filesystem hierarchy while the system is running), but it can present problems if you're using FreeBSD as a console user under KDE or GNOME, and you want to mount a CD-ROM or audio CD. This intricacy will be covered later in this chapter.


The umount Command

There will also come the time when you have to "unmount" a filesystem; the command for this is umount (rather than unmount). To unmount the /home filesystem, issue the following command:

# umount /home


You can also use umount /dev/ad1s1g to accomplish the same result, or even umount -a to unmount everything except for the root filesystem.

Unmounting filesystems is a much simpler procedure than mounting them, with only one major complicating factor: For a filesystem to be unmounted, it must be quiescentin other words, it cannot be in use by the kernel, any daemon, or any user process. This means that to unmount filesystems such as /usr and /var, you will almost certainly have to be in single-user mode. For the /home partition in the example in the previous section, any connected users will likely be working in their home directories, so they will have to be kicked off the system before /home can be unmounted. The shell, keeping current tabs on your present working directory, makes whatever filesystem you're in "busy." This factor leads to the most common surprise most users find when first experimenting with mount and umount: You can't be inside a filesystem you're trying to unmount! If you are, you'll get a "Device busy" error message. To be safe, be in the habit of entering cd / before you attempt to unmount a filesystem.

Like mount, umount has the -f option to force an unmount. But again, it's best to avoid using it unless absolutely necessary; filesystem operations have the potential to destabilize the system if done in a messy manner.




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