/etc/fstab is Linux's Filesystem Table. It tells Linux what filesystems it will automatically be mounted, where to mount a filesystem, format, any special options, and should it fsck it on boot. Once you understand this file, you will find this very easy to modify.


Adding/Removing a Filesystem

You can permemently add or remove filesystems from your system by adding or removing a line from fstab. This operation requires root to do this, as it effects all users.

When adding a file system to fstab, first add in the line in the same format as shown in the file (and described below). Then you can mount it using mount /mountpoint. If all goes well, the filesystem will mount.

To permemently remove a filesystem, delete the line that you don't want anymore. Remember to unmount the filesystem first, by umount /mountpoint.

Sample fstab

Below the fstab file from my machine:

/dev/hda5       /       ext2    defaults                1 1
none            /proc   proc    defaults                0 0
/dev/hda7       /mnt    hfs     user,umask=0000,rw      0 0
/dev/fd0        /floppy auto    noauto,user,umask=7055  0 0
/dev/hda6       swap    swap    defaults                0 0
/dev/hdc        /cdrom  auto    noauto,ro,user          0 0
/dev/scd0       /cdrw   auto    noauto,ro,user          0 0
/dev/sda        /mp3    ext2    defaults                1 1            

Understanding the Columns

Device Location

The first column represents the device you will be mounting. For everything, except /proc, this device will be in /dev/ somewhere.

Note: Linux expects /proc to have a device called none. /proc is a "virtual" filesystem created by the kernel to show users what's going on inside of the kernel. Some programs use it to figure out cpuload, memory usage, etc.

Mount Point

The second column represents the mount point -- the virtual place where you want the disk to appear. For example, I have setup /dev/scd0 to appear at /cdrw. Now when I mount /cdrw whatever filesystem that is on the SCSI CD 0 (/dev/scd0) device will appear in /cdrw.

Note: The root filesystem (your primary Linux partition), must always be mounted on /. /proc must always be mounted on /proc.

Filesystem Type

The third column tells Linux the type of filesystem it is mounting. Common ones include:

  • auto - Automagically detect filesystem. This is most useful on mount points where the filesystem type frequently changes, like most removable media.
  • ext - The Linux Filesystem
  • proc - /proc filesystem, displays system information
  • iso9660 - Commonly used on CD-ROMs, supported by almost all OS's the support CD-ROMs. This is the default filesystem for external media in Linux.
  • hfs - HFS Standard format, often used in Mac OS for smaller disks.
  • hfsplus - HFS Plus format, often used in Mac OS for larger disks. Requires a special patch to work, and is unreliable at this time.
  • fat - Microsoft Windows Disk Format, supporting 256 character long filesystem.
  • msdos - Old MS-DOS disks
  • ... and more such as: minix, ext, ext2, xiafs, iso9660, romfs ,ufs, ntfs, qnx4, bfs

    Special Options

    For ext2, swap or proc disks, you will most likely just need to put in defaults.

    For HFS, MSDOS and FAT disks don't support permissions, so you must tell Linux what do with them. The user option allows users to mount these disks. rw allows the filesystem to be read or written from. umask=0100 sets the permissions for the disk (owner read,write, everybody else nothing). If you want to exec Linux binaries from this disk, add the exec option.

    For Floppies, you should use the filesystem type of auto, make them user mountable (using the user option. You also need to use noauto, to prevent Linux from mounting this disk on boot.

    CD-ROMS should use the same options as floppies, except with the addition of ro for readonly, indicating that you won't be able to write to this disk.

    Backup Days

    The fifth column is a number representing the number of days, since you previously backed up the disk. This column can be used by the system admin to tell when he needs to backup, a script or a backup program.

    File System Check

    The final column is exclusively for ext2 disks, and when they should be checked. Your root filesystem (/) should use a 1 to indicate checking upon boot. Any other ext2 partitions or disks, should use a 2 to indicate a fsck on boot (if mounted upon boot) or upon mount.