Online Book Reader

Home Category

Classic Shell Scripting - Arnold Robbins [235]

By Root 947 0
layered on top of an arbitrary existing directory of another filesystem. This action is called mounting, and the commands mount and umount, respectively, mount and unmount filesystems.

When another filesystem is mounted on top of a directory, any previous contents of that directory become invisible and inaccessible; they are exposed again when the unmount is done.

Filesystem mounting gives the illusion of a single filesystem tree that can grow without limit, simply by adding more, or larger, storage devices. The regular file-naming convention /a/b/c/d/... means that human users, and software, are completely isolated from the irrelevant notion of devices, unlike several other operating systems that embed the device name in the pathname.

A fair amount of information is needed to complete a mount command, so a system manager stores the details in a special file, usually called /etc/fstab or /etc/vfstab, depending on the Unix flavor. As with most Unix configuration files, it is an ordinary text file, and its format is documented in the manual pages for fstab(4 or 5) or vfstab(4).

When shared magnetic disks were the only filesystem media available, mounting and unmounting required special privileges—normally those accorded only to system management. However, with user-owned media such as floppy disks, CD-ROMs, and DVDs, ordinary users with desktop computers need to be able to do this themselves. Many Unix systems have now been extended so that certain devices can be flagged as permitting mounts and unmounts by unprivileged users. Here are some examples from a GNU/Linux system:

$ grep owner /etc/fstab | sort

Which devices allow user mounts?

/dev/cdrom /mnt/cdrom iso9660 noauto,owner,kudzu,ro 0 0

/dev/fd0 /mnt/floppy auto noauto,owner,kudzu 0 0

/dev/sdb4 /mnt/zip100.0 auto noauto,owner,kudzu 0 0

These make the CD-ROM, floppy disk, and Iomega Zip disk available for user mounts, which might be done like this:

mount /mnt/cdrom Make the CD-ROM available

cd /mnt/cdrom Change to its top-level directory

ls List its files

...

cd Change to home directory

umount /mnt/cdrom Release the CD-ROM

The mount command issued without arguments requires no special privileges: it simply reports all of the currently mounted filesystems. Here is an example from a standalone web server:

$ mount | sort

Show sorted list of mounted filesystems

/dev/sda2 on /boot type ext3 (rw)

/dev/sda3 on /export type ext3 (rw)

/dev/sda5 on / type ext3 (rw)

/dev/sda6 on /ww type ext3 (rw)

/dev/sda8 on /tmp type ext3 (rw)

/dev/sda9 on /var type ext3 (rw)

none on /dev/pts type devpts (rw,gid=5,mode=620)

none on /dev/shm type tmpfs (rw)

none on /nue/proc type proc (rw)

none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)

none on /proc type proc (rw)

This shows, for example, that the root filesystem is mounted on disk device /dev/sda5. Other filesystems are mounted over /boot, /export, and so on.

A system manager could unmount the /ww tree by issuing the command:

# umount /ww Here, # is the root prompt

The command would fail if any files in the /ww subtree were still in use. The list-open-files command, lsof,[14] can be used to track down processes that are preventing the unmount.

Filesystem Implementation Overview

The details of how filesystems are implemented are interesting, but are quite complex and beyond the needs of this book; for examples, see the excellent books The Design and Implementation of the 4.4BSD Operating System [15] and UNIX Internals: The New Frontiers.[16]

There is one aspect of the filesystem implementation that is useful to know about at a higher level, however, because it is responsible for several user-visible aspects of Unix filesystems. When a filesystem is created, a table of manager-specified fixed size[17] is created on disk to hold information about the files in the filesystem. Each file is associated with one entry in this table, and each entry is a filesystem data structure called an inode (a contraction of index node, and pronounced eye node). The contents of inodes depend on the particular

Return Main Page Previous Page Next Page

®Online Book Reader