-->

Previous | Table of Contents | Next

Page 198

Many different filesystems are supported by Linux; the ext2 filesystem is used most because it is designed for Linux and is very efficient. Other filesystems are used for compatibility with other systems; for example, it's common to use the msdos and vfat filesystems on floppies. (These are the native filesystems of MS-DOS and Windows 95.) Under Red Hat Linux 4.2, some filesystems are built into the kernel:


$ cat /proc/filesystems

        ext2

        msdos

nodev   proc

And some filesystems are available as loadable modules:


$ ls /lib/modules/`uname -r`/fs

ext.o     isofs.o   ncpfs.o   smbfs.o   ufs.o     vfat.o

hpfs.o    minix.o   nfs.o     sysv.o    umsdos.o  xiafs.o

Some of these (nfs, ncpfs, and smbfs) are network filesystems that don't depend on block devices. Network filesystems are covered in Chapter 13, "TCP/IP Network Management." There are more filesystems that are supported by Linux but not provided by the standard kernel (for example, NTFS).

The mount Command

To mount a block device into the filesystem, use the mount command. You need to specify what device contains the filesystem, what type it is, and where in the directory hierarchy to mount it.

A mount command looks like this:


mount [-t type] [-o options] device mount-point

device must be a block device, or, if it contains a colon, it can be the name of another machine from which to mount a filesystem (see Chapter 13). mount-point should be an existing directory; the filesystem will appear at this position. (Anything previously in that directory will be hidden.) The filesystem type and options are optional, and the variety and meaning of options depend on the type of filesystem being mounted. If the filesystem you want to mount is specified in the /etc/fstab file, you need to specify only the mount point or the device name; the other details will be read from /etc/fstab by mount. Here is an example of the mount command being used:


# mount /dev/fd1 -t vfat /mnt/floppy

mount: block device /dev/fd1 is write-protected, mounting read-only

# ls /mnt/floppy

grub-0.4.tar.gz

# umount /mnt/floppy

# ls /mnt/floppy

filesystem not mounted

In this example, I mounted a floppy containing a vfat filesystem at the mount point /mnt/floppy (and got an informational message). The directory /mnt/floppy already existed. I used

Page 199

ls to see what was on the disk and unmounted it again. I then ran ls again and the response I got was simply the name of a file that I leave in the directory /mnt/floppy on my hard disk to remind me that there currently is nothing mounted there. This enables me to distinguish this from having an empty floppy mounted.

Mounting a vfat floppy like this caused the Linux kernel to automatically load the vfat driver into the kernel while it was needed. These drivers are loaded by the system daemon kerneld, and when they become unused after the filesystem is unmounted, they are unloaded to recover the memory that they occupied. See Chapter 5, "Configuring and Building Kernels," for more information about kernel modules.

Any one of several things can cause the mount command to fail. It is possible to specify an incorrect device name (that is, a device file that does not exist or one for which a driver is not available in the kernel or for which the hardware is not present). Other error conditions include unreadable devices (for example, empty floppy drives or bad media) and insufficient permissions (mount commands other than those sanctioned by the administrator by listing them with the option user in /etc/fstab are forbidden to ordinary users). Trying to mount a device at a mount point that does not already exist will also not work. Still more error conditions are possible but unlikely (for example, exceeding the compiled-in limit to the number of mounted filesystems) or self-explanatory (for example, most usage errors for the mount command itself). There are some more unlikely error messages that chiefly relate to the loopback devices.

In order to mount a filesystem, the point at which it is to be mounted (that is, the mount point) must be a directory. This directory doesn't have to be empty, but after the filesystem is mounted, anything "underneath" it will be inaccessible. Linux provides a singly rooted filesystem, in contrast to those operating systems that give each filesystem a separate drive letter. Although this might seem less flexible, it is more flexible, because the size of each block device (that is, hard disk or whatever) is hidden from programs, and things can be moved around. For example, if you have some software that expects to be installed in /opt/umsp, you can install it in /big-disk/stuff/umsp and make /opt/umsp a symbolic link. There is also no need to edit a myriad of configuration files that are now using the wrong drive letter after you install a new disk drive, for example.

There are many options governing how a mounted filesystem behaves; for example, it can be mounted read-only. There are options for filesystems such as msdos that don't have any concept of users. The filesystems enable you to give each file a particular file mode (for security or to allow access by everyone). When you mount an nfs filesystem, there is so much flexibility available that the options have a separate manual page (man nfs), although the defaults are perfectly reasonable. The nfs filesystem is explained in more detail in Chapter 13.

Table 11.1 contains options useful for mount, given in alphabetical order. Unless otherwise indicated, these options are valid for all filesystem types, although asking for asynchronous writes to a CD-ROM is no use! Options applicable only to NFS filesystems are not listed here; refer to the nfs manual page for those.

Page 200

Table 11.1. mount options.

mount Option Description
async Write requests for the filesystem normally should wait until the data has reached the hardware; with this option, the program continues immediately instead. This does mean that the system is slightly more prone to data loss in the event of a system crash, but, on the other hand, crashes are very rare with Linux. This option speeds up NFS filesystems by a startling extent. The opposite of this option is sync.
auto Indicates to mount that it should mount the device when given the -a flag. This flag is used by the startup scripts to make sure that all the required filesystems are mounted at boot time. The opposite of this option is noauto.
defaults Turns on the options rw, suid, dev, exec, auto, nouser, and async.
dev Allows device nodes on the system to be used. Access to devices is completely determined by access rights to the on-disk device node. Hence, if you mount an ext2 filesystem on a floppy and you have previously placed a writable /dev/kmem device file on the disk, then you've just gained read/write access to kernel memory. System administrators generally prevent this from happening by mounting removable filesystems with the nodev mount option.
exec Indicates to the kernel that it should allow the execution of programs on the filesystem. This option is more frequently seen as noexec, which indicates to the kernel that execution of programs on this filesystem shouldn't be allowed. This is generally used as a security precaution or for NFS filesystems mounted from another machine that contain executable files of a format unsuitable for this machine (for example, being intended for a different CPU).
noauto Opposite of auto; see above.
nodev Opposite of dev; see above.
noexec Opposite of exec; see above.
nosuid Opposite of suid; see below.
nouser Opposite of user; see below.

Previous | Table of Contents | Next