Previous Section
 < Day Day Up > 
Next Section


Mounting File Systems Automatically: /etc/fstab

File systems are mounted using the mount command, described in the next section. Although you can mount a file system directly with only a mount command, you can simplify the process by placing mount information in the /etc/fstab configuration file. Using entries in this file, you can have certain file systems automatically mounted whenever your system boots. For others, you can specify configuration information, such as mountpoints and access permissions, which can be automatically used whenever you mount a file system. You needn't enter this information as arguments to a mount command as you otherwise must. This feature is what allows mount utilities on GNOME or KDE to enable you to mount a file system simply by clicking a window icon. All the mount information is already in the /etc/fstab file. For example, when you add a new hard disk partition to your Linux system, you most likely want to have it automatically mounted on startup, and then unmounted when you shut down. Otherwise, you must mount and unmount the partition explicitly each time you boot up and shut down your system. To have Linux automatically mount the file system on your new hard disk partition, you only need to add its name to the fstab file. You can do this by directly and carefully editing the /etc/fstab file to type in a new entry.

An entry in an fstab file contains several fields, each separated from the next by a space or tab. These are described as the device, mountpoint, file system type, options, dump, and fsck fields, arranged in the sequence shown here:

<device> <mountpoint> <filesystemtype> <options> <dump> <fsck>

The first field is the name of the file system to be mounted. This entry can be either a device name or an ext2 or ext3 file system label. A device name usually begins with /dev, such as /dev/hda3 for the third hard disk partition. A label is specified by assigning the label name to the tag LABEL, as in LABEL=/ for an ext2 root partition. The next field is the directory in your file structure where you want the file system on this device to be attached. These are empty directories to be used for file systems, such as /dev/floppy. The third field is the type of file system being mounted. Table 30-7 provides a list of all the different types you can mount. The type for a standard Linux hard disk partition is ext3. The next example shows an entry for the main Linux hard disk partition. This entry is mounted at the root directory, /, and has a file type of ext3:

/dev/hda3    /     ext3    defaults   0   1

The following example shows a LABEL entry for the hard disk partition, where the label name is /:

LABEL=/     /      ext3   defaults   0   1

Auto Mounts

The file system type for a floppy may differ depending on the disk you are trying to mount. For example, you may want to read a Windows-formatted floppy disk at one time and a Linux-formatted floppy disk at another time. For this reason, the file system type specified for the floppy device is auto. With this option, the type of file system formatted on the floppy disk is detected automatically, and the appropriate file system type is used.

/dev/fd0  /mnt/floppy  auto   defaults,noauto   0 0
Table 30-7: File System Types

Types

Description

auto

Attempts to detect the file system type automatically.

minux

Minux file systems (filenames are limited to 30 characters).

ext

Earlier version of Linux file system, no longer in use.

ext3

Standard Linux file system supporting long filenames and large file sizes. Includes journaling.

ext2

Older standard Linux file system supporting long filenames and large file sizes. Does not have journaling.

xiaf

Xiaf file system.

msdos

File system for MS-DOS partitions (16-bit).

vfat

File system for Windows 95, 98, and Millennium partitions (32-bit).

reiserfs

A ReiserFS journaling file system.

xfs

A Silicion Graphics (SGI) file system.

ntfs

Windows NT, Windows XP, and Windows 2000 file systems (read-only access, write access is experimental and dangerous).

smbfs

Samba remote file systems, such as NFS.

hpfs

File system for OS/2 high-performance partitions.

nfs

NFS file system for mounting partitions from remote systems.

umsdos

UMS-DOS file system.

swap

Linux swap partition or swap file.

sysv

Unix System V file systems.

iso9660

File system for mounting CD-ROM.

proc

Used by operating system for processes (kernel support file system).

devpts

Unix 98 Pseudo Terminals (ttys, kernel interface file system).

shmfs and tmpfs

Linux Virtual Memory, POSIX shared memory maintenance access (kernel interface file system).

mount Options

The field after the file system type lists the different options for mounting the file system. You can specify a default set of options by simply entering defaults, or you can list specific options next to each other separated by a comma (no spaces). The defaults option specifies that a device is read/write (rw), that it is asynchronous (async), that it is a block device (dev), that it cannot be mounted by ordinary users (nouser), and that programs can be executed on it (exec). By contrast, a CD-ROM has only two options listed for it: ro and noauto. ro specifies that the device is read-only, and noauto specifies it is not automatically mounted. The noauto option is used with both CD-ROMs and floppy drives, so they won't automatically mount, because you don't know if you have anything in them when you start up. At the same time, the entries for both the CD-ROM and the floppy drive specify where they are to be mounted when you decide to mount them. On Red Hat, the kudzu option invokes the Red Hat Kudzu tool, which checks to see if the device has been installed on your system, and that the kernel is running the appropriate drivers for that CD-ROM or floppy disk. Table 30-8 lists the options for mounting a file system. An example of CD-ROM and floppy drive entries follows. Notice the type for a CD-ROM file system is different from that for a hard disk partition, iso9660.

/dev/hdc   /mnt/cdrom    iso9660  noauto,owner,kudzu,ro 0  0
/dev/fd0   /mnt/floppy   auto     noauto,owner,kudzu    0  0
Table 30-8: Mount Options for File Systems

Options

Description

async

Indicates that all I/O to the file system should be done asynchronously.

auto

Indicates that the file system can be mounted with the -a option. A mount -a command executed when the system boots, in effect, mounts file systems automatically.

defaults

Uses default options: rw, suid, dev, exec, auto, nouser, and async.

dev

Interprets character or block special devices on the file system.

kudzu

Checks that the device is installed and accessible.

noauto

Indicates that the file system can only be mounted explicitly. The -a option does not cause the file system to be mounted.

exec

Permits execution of binaries.

nouser

Forbids an ordinary (that is, nonroot) user to mount the file system.

remount

Attempts to remount an already mounted file system. This is commonly used to change the mount flags for a file system, especially to make a read-only file system writable.

ro

Mounts the file system as read-only.

rw

Mounts the file system as read/write.

suid

Allows set-user-identifier or set-group-identifier bits to take effect.

sync

Indicates that all I/O to the file system should be done synchronously.

user

Enables an ordinary user to mount the file system. Ordinary users always have the following options activated: noexec, nosuid, and nodev.

nodev

Does not interpret character or block special devices on the file system.

noexec

Does not allow execution of binaries on the mounted file systems

nosuid

Does not allow set-user-identifier or set-group-identifier bits to take effect.

Boot and Disk Check

The last two fields of an fstab entry consist of integer values. The first one is used by the dump command to determine if a file system needs to be dumped, backing up the file system. The second value is used by fsck to see if a file system should be checked at reboot, and in what order with other file systems. If the field has a value of 1, it indicates a boot partition, and 2 indicates other partitions. The 0 value means fsck needn't check the file system.

A copy of an /etc/fstab file is shown here. Notice the first line is a comment. All comment lines begin with a #. The entry for the /proc file system is a special entry used by your Linux operating system for managing its processes; it is not an actual device. To make an entry in the /etc/fstab file, you can edit the /etc/fstab file directly. You can use the example /etc/fstab file shown here as a guide to show how your entries should look. The /proc and swap partition entries are particularly critical.

/etc/fstab
Start example
# <device> <mountpoint> <filesystemtype> <options>            <dump><fsck>
/dev/hda3      /              ext3          defaults                 0    1
none           /proc          proc          defaults                 0    0
none           /dev/pts       devpts        gid=5,mode=620           0    0
none           /dev/shm       tmpfs         defaults                 0    0
/dev/hda2      swap           swap          defaults                 0    0
/dev/hdc       /mnt/cdrom     iso9660       noauto,owner,kudzu,ro    0    0
/dev/fd0       /mnt/floppy    auto          noauto,owner,kudzu       0    0
/dev/hda1      /mnt/windows   vfat          defaults                 0    0
End example

CD-ROM and Floppy Defaults

Red Hat creates entries in the fstab file for any CD-ROM and floppy devices you may have. It also creates directories where these drives can be mounted. For Red Hat, these are /mnt/cdrom for your CD-ROM and /mnt/floppy for your floppy disk. If you have several CD-ROMs or floppy drives, directories are created for them with sequential numbers. So on Red Hat, a second CD-ROM drive will use a directory named /mnt/cdrom1.

Partition Labels: e2label

Red Hat uses file system labels for ext2 and ext3 file systems on hard disk partitions. Thus in the /etc/fstab file previously shown, the first entry would use a label for its device name, as shown here. In this case, the label is the slash, /, indicating the root partition. You could change this device's label with e2label, but be sure to also change the /etc/fstab entry for it.

LABEL=/     /     ext3   defaults    0   1

For ext2 and ext3 partitions, you can change or add a label with the e2label tool or tune2fs with the -L option. Specify the device and the label name. If you change a label, be sure to change corresponding entries in the /etc/fstab file. Just use e2label with the device name to find out what the current label is. In the next example, the user changes the label of the /dev/hda3 device to TURTLE:

e2label /dev/hda3  TURTLE

Windows Partitions

You can mount either MS-DOS, Windows 95/98/ME, or Windows XP, NT, and 2000 partitions used by your Windows operating system onto your Linux file structure, just as you would mount any Linux file system. You have to specify the file type of vfat for Windows 95/98/ME, and msdos for MS-DOS. Windows XP, NT, and 2000 use the ntfs file type. You may find it convenient to have your Windows partitions automatically mounted when you start up your Linux system. To do this, you need to put an entry for your Windows partitions in your /etc/fstab file and give it the defaults option, or be sure to include an auto option. You make an entry for each Windows partition you want to mount, and then specify the device name for that partition, followed by the directory in which you want to mount it. The /mnt/windows directory would be a logical choice (be sure the windows directory has already been created in /mnt). The next example shows a standard Windows partition entry for an /etc/fstab file. Notice the last entry in the /etc/fstab file example is an entry for mounting a Windows partition.

/dev/hda1 /mnt/windows vfat defaults 0 0
Tip 

Linux kernel 2.4 systems currently can only reliably mount ntfs file systems (Windows NT, Windows 2000, and Windows XP) as read-only. They cannot write to these partitions, though experimental and unstable support is provided using the ntsf kernel module (see The Linux-NTSF Project at linux-ntfs.sourceforge.net).

Linux Kernel Interfaces

Your /etc/fstab file may also have entries for two special kernel interface file systems, devpts and tmpfs. Both provide kernel interfaces that are not supported by standard devices. The /dev/pts entry mounts a devpts file system for pseudo-terminals. The /dev/shm entry mounts the tmpfs file system (also known as shmfs) to implement Linux Virtual Memory, POSIX shared memory maintenance access. This is designed to overcome the 4GB memory limitation on current systems, extending usable memory to 64GB.

If your /etc/fstab file ever becomes corrupt—say, if a line gets deleted accidentally or changed—your system will boot into a maintenance mode, giving you read-only access to your partitions. To gain read/write access so that you can fix your /etc/fstab file, you have to remount your main partition. The following command performs such an operation:

# mount -n -o remount,rw /

noauto

File systems listed in the /etc/fstab file are automatically mounted whenever you boot, unless this feature is explicitly turned off with the noauto option. Notice that the CD-ROM and floppy disks in the sample fstab file earlier in this chapter have a noauto option. Also, if you issue a mount -a command, all the file systems without a noauto option are mounted. If you want to make the CD-ROM user-mountable, add the user option.

/dev/hdc /mnt/cdrom iso9660 ro,noauto,user 0 0
Tip 

The "automatic" mounting of file systems from /etc/fstab is actually implemented by executing a mount -a command in the /etc/rc.d/rc.sysinit file that is run whenever you boot. The mount -a command mounts any file system listed in your /etc/fstab file that does not have a noauto option. The umount -a command (which is executed when you shut down your system) unmounts the file systems in /etc/fstab.



Previous Section
 < Day Day Up > 
Next Section
This HTML Help has been published using the chm2web software.