- Table of Contents
- Copyright
- About the Lead Authors
- About the Contributing Authors
- Acknowledgments
- Tell Us What You Think!
- Introduction
- I. Red Hat Linux Installation and User Services
- Chapter 1. Introduction to Red Hat Linux
- Chapter 2. Installation of Your Red Hat System
- Chapter 3. LILO and Other Boot Managers
- Chapter 4. Configuring the X Window System, Version 11
- Chapter 5. Window Managers
- Chapter 6. Connecting to the Internet
- Chapter 7. IRC, ICQ, and Chat Clients
- Chapter 8. Using Multimedia and Graphics Clients
- II. Configuring Services
- Chapter 9. System Startup and Shutdown
- Chapter 10. SMTP and Protocols
- Chapter 11. FTP
- Chapter 12. Apache Server
- Chapter 13. Internet News
- Chapter 14. Domain Name Service and Dynamic Host Configuration Protocol
- Chapter 15. NIS: Network Information Service
- Chapter 16. NFS: Network Filesystem
- Chapter 17. Samba
- III. System Administration and Management
- Chapter 18. Linux Filesystems, Disks, and Other Devices
- Chapter 19. Printing with Linux
- Chapter 20. TCP/IP Network Management
- Chapter 21. Linux System Administration
- Chapter 22. Backup and Restore
- Chapter 23. System Security
- IV. Red Hat Development and Productivity
- Chapter 24. Linux C/C++ Programming Tools
- Chapter 25. Shell Scripting
- Chapter 26. Automating Tasks
- Chapter 27. Configuring and Building Kernels
- Chapter 28. Emulators, Tools, and Window Clients
- V. Appendixes
- A. The Linux Documentation Project
- B. Top Linux Commands and Utilities
- C. The GNU General Public License
- D. Red Hat Linux RPM Package Listings
The mount Command
Use the mount command to mount a block device onto the filesystem. 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 should either 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 16). The mount-point should be an existing directory (or you get an error); 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 are read from /etc/fstab by mount.
Here is an example of the mount command being used:
# ls /mnt/floppy filesystem not mounted # mount -t vfat /dev/fd1 /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 listed the files in my /mnt/floppy mount point. I saw that no diskette was mounted, so I mounted a diskette containing a vfat filesystem at the mount point. I got an informational message telling me that the diskette was write-protected; if the diskette had not been write-protected, there would have been no message. The directory /mnt/floppy already existed. I used ls to see what was on the disk and unmounted it again using the umount command. 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 hint enables me to distinguish a written diskette from an empty diskette that is mounted. You can also use the df command to see what filesystems are mounted. For example:
# mount -t vfat /dev/fd0 /mnt/floppy # df /mnt/floppy/ Filesystem 1k-blocks Used Available Use% Mounted on /dev/fd0 1423 0 1423 0% /mnt/floppy # umount /mnt/floppy # df /mnt/floppy/ Filesystem 1k-blocks Used Available Use% Mounted on /dev/hda6 2028066 1850753 72493 96% /
As you see from the example, when a device is mounted on a mount point, df will output statistics for that device; otherwise it will output statistics about the device upon which the directory resides.
Mounting a vfat diskette as we did earlier causes the Linux kernel to automatically load the vfat driver into the kernel while it is needed. The kernel module handler loads these drivers, and when they become unused after the filesystem is unmounted, they are unloaded to recover the memory that they occupied. See Chapter 27, "Configuring and Building Kernels," for more information about kernel modules.
Potential Problems with mount
Any one of several things can cause the mount command to fail, for example:
- Incorrect device name— 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).
- Unreadable devices— Devices can be unreadable either because the devices themselves are bad (for example, empty diskette drives or bad media) or because you have insufficient permissions to mount them. Filesystems, other than those sanctioned by the administrator by listing them with the option user in /etc/fstab, are forbidden to ordinary users and require root privilege to mount them.
- Bad mount point— Trying to mount a device at a mount point that does not already exist will not work.
- Other errors— 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.
When you mount a filesystem, the mount point (the point at which the filesystem is to be mounted) must be a directory. This directory doesn't have to be empty, but after the filesystem is mounted, anything underneath it is inaccessible. Linux provides a singly rooted filesystem, which is in contrast to those operating systems that give each filesystem a separate drive letter. This is more flexible because the size of each block device (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 using the wrong drive letter after you install a new disk drive.
Many options govern 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 16.
Table 18.1 contains options useful for mount 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 command manual page for those.
Table 18.1. mount Options
| 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 rare with Linux. This option speeds up NFS filesystems to 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 diskette 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. It is more usual to use the negated version of exec—that is, 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 contains executable files of a format unsuitable for this machine (for example, intended for a different CPU). |
| noauto | Opposite of auto. |
| nodev | Opposite of dev. |
| noexec | Opposite of exec. |
| nosuid | Opposite of suid. |
| nouser | Opposite of user. |
| remount | Allows the mount command to change the flags for an already-mounted filesystem without interrupting its use. You can't unmount a filesystem that is currently in use, and this option is basically a workaround. The system startup scripts, for example, use the command mount -n -o remount,ro / to change the root filesystem from read-only (it starts off this way) to read/write (its normal state). The -n option indicates to mount that it shouldn't update /etc/fstab because it can't do this while the root filesystem is still read-only. |
| ro | Mounts the filesystem read-only. This is the opposite of the option rw. |
| rw | Mounts the filesystem read/write. This is the opposite of the option ro. |
| suid | Allows the set user ID and set group ID file mode bits to take effect. The opposite of this option is nosuid. The nosuid option is more usual; it is used for the same sorts of reasons that nodev is used. |
| sync | All write operations cause the calling program to wait until the data has been committed to the hardware. This mode of operation is slower but a little more reliable than its opposite, asynchronous I/O, which is indicated by the option async. |
| user | Allows ordinary users to mount the filesystem. When there is a user option in /etc/fstab, ordinary users indicate which filesystem they want to mount or unmount by giving the device name or mount point; all the other relevant information is taken from the /etc/fstab file. For security reasons, user implies the noexec, nosuid, and nodev options. |
Options are processed by the mount command in the order they appear on the command line (or in /etc/fstab). Thus, it is possible to allow users to mount a filesystem and then run set user ID executables by using the options user, suid in that order. Using them in reverse order (suid, user) wouldn't work because the user option would turn off the suid option again.
There are many other options available, but they are all specific to particular filesystems. All the valid options for mount are detailed in its manual page. An example is the umask flag for the vfat and fat filesystems, which allows you to make all the files on your MS-DOS or Windows partitions readable (or even writable if you prefer) for all the users on your Linux system.
Mounting with the User Mount Tool | Next Section

Account Sign In
View your cart