Previous Section  < Day Day Up >  Next Section

Recipe 9.10. Configuring Filesystem Mounts with /etc/fstab

9.10.1 Problem

Users need to make their own backups on CDs, and use USB memory sticks and other types of removeable media. You don't want to give them root privileges just so they can mount these devices. But only root can use the mount command we discussed in Recipe 9.9. And you also want to control which filesystems are automatically mounted at boot.

9.10.2 Solution

Add entries to /etc/fstab, defining mountpoints and access permissions.

This example shows a Linux partition, two Windows partitions, and removeable media:

#<device> <mountpoint>  <type>    <options>                  <dump> <pass>

/dev/hda6  /rh-data     reiserfs  defaults,user,noauto       0      1

/dev/hda1  /win2k       ntfs      defaults,user,ro,gid=win2k 0      0

/dev/hda2  /win98       vfat      defaults,user,gid=win98    0      0

/dev/hdc0  /cdrom       auto      defaults,user,noauto,ro    0      0

/dev/fd0   /floppy      auto      defaults,user,noauto       0      0

/dev/sda1  /memstick    auto      defaults,user,noauto       0      0

Once a device has an entry in /etc/fstab, it can be mounted by using the mountpoint:

$ mount /cdrom

$ mount /memstick

And unmounted the same way:

$ umount /cdrom

9.10.3 Discussion

These are the six fields that make up /etc/fstab:


The device name assigned by the kernel.


The directory to which the filesystem is attached, which is user-defined.


The filesystem type. It's okay to use "auto" in this field for most filesystems. See mount(8) for the supported filesystem types.


Command options in a comma-delimited list. See mount(8) for a complete list


If you're using the dump command for backups, this tells dump the backup interval, in days. 1 means every day, 2 means every other day, and so on.


This tells fsck which filesystem to check first at boot up, if it ever needs to. Make your root filesystem 1, any other Linux filesystems 2, and non-Linux filesystems 0.

Let's take a closer look at what goes in the options field. All these values belong to the defaults option:




Allow setuid and setgid bits to operate.


Interpret block and character devices.


Allow execution of binaries.


This is used in boot scripts (Debian uses /etc/init.d/; Red Hat uses /etc/rc.d/rc.sysinit), indicating which filesystems are to be started at boot up.


Non-root users cannot mount or unmount the filesystem.


Asynchronous I/O, which is standard for Linux.

The defaults values are overridden by appending additional options, as on the win2k line in the /etc/fstab example above (defaults,user,ro,gid=win2k). The options are:


Non-root users can mount and unmount the device, provided they were the ones who mounted it.


Any user can unmount the device.


The device must be explicitly mounted by a user and does not automatically mount at boot.


The device is read-only. Be sure to use this for NTFS volumes.


Do not update the "time accessed" file attribute. This speeds up filesystem performance. It also extends the life of CD-RWs and DVD-RWs that use packet-writing, and of USB storage media, by reducing the number of writes.


Assign group membership, if you are controlling access with groups. Mounting filesystems, not devices

We tend to think of mounting devices and partitions, but strictly speaking, only filesystems are mounted. "Mount" and "attach" mean the same thing, if you want a different word to use. Some Linux distributions, such as Red Hat, use the /mnt directory. Debian uses top-level directories, such as /floppy or /cdrom. There's no hard-and-fast rule; put them wherever it suits you. Just be careful not to mount two filesystems in the same directory. If you do, the existing files will disappear until the intruder filesystem is unmounted.

Usually it's not necessary to specify the filesystem type, because mount will figure it out. First, it will probe the superblock. Currently adfs, bfs, cramfs, ext, ext2, ext3, hfs, hpfs, iso9660, jfs, minix, ntfs, qnx4, reiserfs, romfs, udf, ufs, vxfs, xfs, and xiafs are supported. If that fails, it will try each filesystem listed in /proc/filesystems, which shows all the filesystems supported by your kernel.

9.10.4 See Also

  • mount(8), fstab(5)

    Previous Section  < Day Day Up >  Next Section