Tuesday, September 30, 2008

Contents of /etc/fstab

fstab
*****

fstab is a configuration file that contains information of all the partitions and storage devices in your computer. The full path to this file is /etc/fstab.

/etc/fstab contains information of where your partitions and storage devices should be mounted and how. If you can't access your Windows partition from Linux, aren't able to mount your CD or write to your floppy as a normal user, or have problems with your CD-RW, you probably have a misconfigured /etc/fstab file. So, you can usually fix your mounting problems by editing your fstab file.

/etc/fstab is just a plain text file, you must have the root privileges before editing fstab. So, in order to edit the file, you must either log in as root or use the su command to become root.

Overview of the file

Contents of /etc/fstab will be different on different systems. But the basic structure of fstab is always the same. Here's an example of the contents of /etc/fstab:

/dev/hda2 / ext2 defaults 1 1
/dev/hdb1 /home ext2 defaults 1 2
/dev/cdrom /media/cdrom auto ro,noauto,user,exec 0 0
/dev/fd0 /media/floppy auto rw,noauto,user,sync 0 0
proc /proc proc defaults 0 0
/dev/hda1 swap swap pri=42 0 0

Every line (or row) contains the information of one device or partition. The first column contains the device name, the second one its mount point, third its filesystem type, fourth the mount options, fifth (a number) dump options, and sixth (another number) filesystem check options. Let's take a closer look at this stuff.

1st and 2nd columns: Device and default mount point

The first and second columns should be pretty straightforward. They tell the mount command exactly the same things that you tell mount when you mount stuff manually: the device or partition, and the mount point. The mount point specified for a device in /etc/fstab is its default mount point. That is the directory where the device will be mounted if you don't specify any other mount point when mounting the device.

For example the default mount point of floppy disk drive is /media/floppy. ie, executing the following command:
# mount /dev/fd0

will mount floppy drive into /media/floppy, because that's the default mount point specified in
/etc/fstab. If there is no entry for /dev/fd0 in my fstab when I issue the command above, mount gets very confused because it doesn't know where to mount the floppy.

You can freely change the default mount points listed in /etc/fstab, just make sure the mount point is a directory that already exists on your system. If it doesn't, simply create it.

Some partitions and devices are also automatically mounted when your Linux system boots up. For example, have a look at the example fstab above. There are lines that look like this:

/dev/hda2 / ext2 defaults 1 1
/dev/hdb1 /home ext2 defaults 1 2

these lines mean that /dev/hda2 will be mounted to / and /dev/hdb1 to /home. This is done automatically when your Linux system boots up...

3rd column: Filesystem type

The third column in /etc/fstab specifies the filesystem type of the device or partition. Some of the most common filesystem types are explained below:

ext2 and ext3 : Very likely your Linux partitions are Ext3. Ext2 used to be the standard filesystem for Linux, but these days, Ext3 and ReiserFS are usually the default filesystems for almost every new Linux distro. Ext3 is a newer filesystem type that differs from Ext2 in that it's journaled, meaning that if you turn the computer off without properly shutting down, you shouldn't lose any data and your system shouldn't spend ages doing filesystem checks the next time you boot up.

reiserfs : Your Linux partitions may very well be formatted as ReiserFS. Like Ext3, ReiserFS is a journaled filesystem, but it's much more advanced than Ext3. Many Linux distros (including SuSE) have started using ReiserFS as their default filesystem for Linux partitions.

swap : The filesystem type "swap" is used in your swap partitions.

vfat and ntfs : Windows partitions are probably either Vfat or NTFS. The 9x series (95, 98, ME) all use Vfat (more widely known as FAT32), and the NT series (NT, 2000, XP) use NTFS. 2000 and XP partitions may be formatted as Vfat, too. If you want to be able to write to your Windows partitions from Linux, I suggest formatting them as Vfat, because Linux's support for writing to NTFS partitions is a bit shabby at this moment.

auto No, this isn't a filesystem type :-) The option "auto" simply means that the filesystem type is detected automatically.

4th column: Mount options

The fourth column in fstab lists all the mount options for the device or partition. This is also the most confusing column in the fstab file. There are many options available, but some of the most widely used ones are as follows :

auto and noauto
With the auto option, the device will be mounted automatically at bootup. If you take a look at the example fstab above, you'll see that the floppy and CD-ROM both have "auto" as their filesystem type, because their filesystem type may vary. One floppy might be formatted for Windows and the other for Linux's Ext2. That's why it's wise to let the system automatically detect the filesystem type of media such as floppies and cdroms. auto is the default option. If you don't want the device to be mounted automatically, use the noauto option in /etc/fstab. With noauto, the device can be mounted only explicitly.

user and nouser
These are very useful options. The user option allows normal users to mount the device, whereas nouser lets only the root to mount the device. nouser is the default, which is a major cause of headache for new Linux users. If you're not able to mount your cdrom, floppy, Windows partition, or something else as a normal user, add the user option into /etc/fstab.

exec and noexec
exec lets you execute binaries that are on that partition, whereas noexec doesn't let you do that. noexec might be useful for a partition that contains binaries you don't want to execute on your system, or that can't even be executed on your system. This might be the case of a Windows partition. exec is the default option, which is a good thing.

ro
Mount the filesystem read-only.

rw
Mount the filesystem read-write. Again, using this option might cure the headache of many new Linux users who are tearing their hair off because they can't write to their floppies, Windows partitions, or something else.

sync and async
How the input and output to the filesystem should be done. sync means it's done synchronously. If you look at the example fstab, you'll notice that this is the option used with the floppy. In plain English, this means that when you, for example, copy a file to the floppy, the changes are physically written to the floppy at the same time you issue the copy command.

However, if you have the async option in /etc/fstab, input and output is done asynchronously. Now when you copy a file to the floppy, the changes may be physically written to it long time after issuing the command. This isn't bad, and may sometimes be favorable, but can cause some nasty accidents: if you just remove the floppy without unmounting it first, the copied file may not physically exist on the floppy yet!

async is the default. However, it may be wise to use sync with the floppy, especially if you're used to the way it's done in Windows and have a tendency to remove floppies before unmounting them first.

defaults Uses the default options that are rw, suid, dev, exec, auto, nouser, and async.

5th and 6th columns: Dump and fsck options

dump is a backup utility and fsck is a filesystem check utility.

The 5th column in /etc/fstab is the dump option. Dump checks it and uses the number to decide if a filesystem should be backed up. If it's zero, dump will ignore that filesystem. If you take a look at the example fstab, you'll notice that the 5th column is zero in most cases.

The 6th column is a fsck option. fsck looks at the number in the 6th column to determine in which order the filesystems should be checked. If it's zero, fsck won't check the filesystem.

That's it....
ref: http://www.tuxfiles.org/linuxhelp/fstab.html