The mount Command
File systems are mounted with the mount command and unmounted, curiously enough, with the umount command.
During the installation, you have the opportunity to decide where and how your partitions will be mounted. You indicate your choices, and Fedora automatically stores them in /etc/fstab, the file system table, for you. The mount command looks at /etc/fstab and mounts the file system according to those set preferences. You learn more about the file system table later in this section.
The syntax for mount is:
mount -t type file system_to_be mounted mount_point
Here are the components of the mount command, and a brief explanation of each:
► type — Always preceded by the -t argument and followed by a space, and then the type of file system you are mounting. Typical file system types are ext2, ext3, vfat, iso9660, hpfs, hfs, ntfs, and others. For many file systems, mount can detect what type they are automatically, and the -t argument is superfluous (and is replaced with auto).
► file system_to_be mounted (as represented by the partition on which it resides) — This is the device name of the file system you want to mount, typically in the form of /dev/hdx, /dev/scx, or /dev/fdx.
► mount_point — The place in the directory tree where you want to mount the file system. Curiously, you can mount a file system over part of an existing file system. For example, if you have an existing directory at /foo with a single file named bar, and you mount a file system at /foo that includes a file named snafu, a listing of the directory /foo does not show the file bar, but only the file snafu. To show both files is a feature called transparency, which unfortunately is not in the current Linux repertoire.
The only real restriction to "mount anything anywhere" is that the critical system files in /bin, /etc, /lib, /dev, /proc, and /tmp need to be accessed at bootup, which typically means that they need to be on the same physical disk. If they cannot be accessed at bootup, Linux does not load and run.
Here are a few examples of using the mount command:
Mounting a floppy:
# mount -t vfat /dev/fd0 /mnt/floppy
Mounting a CD-ROM:
# mount -t iso9660 /dev/scd0 /mnt/cdrom
Mounting a Network File System (NFS) volume:
# mount -t nfs remote_host:/dir [options] mount_point
Numerous mount options exist. These options are used primarily in the /etc/fstab file. You can invoke a mount option by preceding it (or a comma-delimited string of options) with the -o switch. The mount options are listed in the fstab section of this chapter.
The umount Command
To unmount a file system, use the umount command with the following syntax:
umount mount_point
You can also unmount by device name:
umount device_name
Do not use umount -a to unmount everything that the system does not require to run (or is not currently using). Unmounting everything is a particularly bad idea on a multiuser, networked system because your users are certain to lose access to some or all of their files. So, as any good sysadmin will tell you, do not do that.
Mounting Automatically with /etc/fstab
A special file, /etc/fstab, exists to provide the system with predetermined options and mount points so that the file systems can be automatically or manually mounted with minimal typing and without having to recall arcane Linux syntax.
The /etc/fstab file can only be written to by the super-user. The commands fsck, mount, and umount all read information from /etc/fstab. Each file system gets its own line with the information separated by tabs.
On each line of fstab, the first field indicates the block device or remote file system that will be mounted. The second field identifies the mount point on the local system where the file system will be mounted. The third field is the file system type, and the fourth field is a comma-delimited list of mount options. Options include:
► exec — If this option is specified, binaries can be executed from this file system.
► noauto — This means that the -a option does not cause the file system to be mounted and it is not mounted at bootup.
► noexec — If this option is specified, binaries cannot be executed from this file system.
► nosuid — This option does not permit set-user-identifier or set-group- identifier bits to take effect.
► ro — This option mounts the file system as read-only.
► rw — This option mounts the file system as read/write.
► sync — Reading from and writing to the files are done synchronously.
► user — This option allows a regular (not just root) user to mount the file system, but it includes the options noexec, nosuid, and nodev by default unless they are overridden by exec, dev, and suid.
For iso9660 file systems, the interesting option is unhide, which shows hidden and associated files.
The fstab man pages contain an in-depth description of fstab and its options.
The fifth field of /etc/fstab is used by dump (a traditional Unix backup program) to determine whether the file system should be dumped (backed up); 1 is yes, and 0 is no. Default values are set for you during the initial installation. They are of concern only if you actually use dump; then you would set the value to 1 for the file systems you wanted to back up.
The sixth field is used by fsck to determine how fsck needs to interact with the file system — 0 means that fsck is never run on the file system (a FAT32 file system, for example); 1 means that fsck will be run on the drive at a predetermined time. 2 is recommended for nonroot file systems so that fsck is not run on them as frequently.
Here is a simple /etc/fstab file from a system with a RAID0 ext3 root partition and dual-booted with MS Windows:
LABEL=/12 / ext3 defaults 1 1