Automatically Mounting Partitions In Linux Using /etc/fstab

pradeep's Avatar author of Automatically Mounting Partitions In Linux Using /etc/fstab
This is an article on Automatically Mounting Partitions In Linux Using /etc/fstab in Linux.

Introduction



The file /etc/fstab (it stands for "file system table") contains descriptions of filesystems that you mount often. These filesystems can then be mounted with a shorter command, such as mount /cdrom. You can also configure filesystems to mount automatically when the system boots. You'll probably want to mount all of your hard disk filesystems when you boot.

Example



Look at this file now, by typing more /etc/fstab. It will have two or more entries that were configured automatically when you installed the system. It probably looks something like this:

Code:
  # /etc/fstab: static file system information.
  			   
  /dev/hda1			/			   ext2	defaults	0	   1
  /dev/hda3			none			swap	sw		  0	   0
  proc				 /proc		   proc	defaults	0	   0
    
  /dev/hda5			/tmp			ext2	defaults	0	   2
  /dev/hda6			/home		   ext2	defaults	0	   2
  /dev/hda7			/usr			ext2	defaults	0	   2
    
  /dev/hdc			 /cdrom		  iso9660 ro		  0	   0
  /dev/fd0			 /floppy		 auto	noauto,sync 0	   0
The first column lists the device the filesystem resides on. The second lists the mount point, the third the filesystem type. Notice that the swap partition (/dev/hda3 in the example) has no mount point, so the mount point column contains none.

The last three columns may require some explanation.

The fifth column is used by the dump utility to decide when to back up the filesystem.

The sixth column is used by fsck to decide in what order to check filesystems when you boot the system. The root filesystem should have a 1 in this field, filesystems which don't need to be checked (such as the swap partition) should have a 0, and all other filesystems should have a 2.

Column four contains one or more options to use when mounting the filesystem. Here's a brief summary (some of these probably won't make much sense now - they're here for future reference):

async and sync



Do I/O synchronously or asynchronously. Synchronous I/O writes changes to files immediately, while asynchronous I/O may keep data in buffers and write it later, for efficiency reasons.

ro and rw


Mount the filesystem read-only or read-write. If you don't need to make any changes to the filesystem, it's a good idea to mount it read-only so you don't accidentally mess something up. Also, read-only devices (such as CD-ROM drives and floppy disks with write protection tabs) should be mounted read-only.

auto and noauto


When the system boots, or whenever you type mount -a, mount tries to mount all the filesystems listed in /etc/fstab. If you don't want it to automatically mount a filesystem, you should use the noauto option. It's probably a good idea to use noauto with removable media such as floppy disks, because there may or may not be a disk in the drive. You'll want to mount these filesystems manually after you put in a disk.

dev and nodev


Use or ignore device files on this filesystem. You might use nodev if you mount the root directory of another system on your system - you don't want your system to try to use the devices on the other system.

user and nouser


Permit or forbid ordinary users to mount the filesystem. nouser means that only root can mount the filesystem. This is the normal arrangement. You might use the user option to access the floppy drive without having to be root.

exec and noexec


Allow or do not allow the execution of files on this filesystem. Probably you won't need these options.

suid and nosuid


Allow or do not allow the suid bit to take effect. Probably you won't need these options.

defaults


Equivalent to: rw, dev, suid, exec, auto, nouser, async. You can specify defaults followed by other options to override specific aspects of defaults.

fstab Syntax


Code:
  [Device] [Mount Point] [File_system] [Options] [dump] [fsck order]
Device = Physical location.
/dev/hdxy or /dev/sdxy.
x will be a letter starting with a, then b,c,....
y will be a number starting with 1, then 2,3,....
Thus hda1 = First partition on the master HD.
Izaan's Avatar, Join Date: Oct 2007
Skilled contributor
I am a windows guy
coderzone's Avatar, Join Date: Jul 2004
Team Leader
Quote:
Originally Posted by Izaan
I am a windows guy
So...

By the way good article.
Safari's Avatar, Join Date: Oct 2007
Ambitious contributor
This is not for windows but a good one.
janu03's Avatar
Banned
etc/fstab is commonly used by the command 'mount' ,which reads fstab to ... Create a directory under Linux using mkdir e.g.: mkdir /mnt/windows ... Linux will automatically mount all partitions or devices which we have
napster_hacker17's Avatar, Join Date: Nov 2009
Newbie Member
thnx dude gud article... very helpful