|< Day Day Up >|
Recipe 9.10. Configuring Filesystem Mounts with /etc/fstab
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.
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
These are the six fields that make up /etc/fstab:
Let's take a closer look at what goes in the options field. All these values belong to the defaults option:
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:
188.8.131.52 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
|< Day Day Up >|