Automatically Mounting Partitions In Linux Using /etc/fstab

Discussion in 'Linux' started by pradeep, Nov 20, 2007.

  1. pradeep

    pradeep Team Leader

    Joined:
    Apr 4, 2005
    Messages:
    1,645
    Likes Received:
    87
    Trophy Points:
    0
    Occupation:
    Programmer
    Location:
    Kolkata, India
    Home Page:
    http://blog.pradeep.net.in

    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.
     
    Last edited: Nov 20, 2007
  2. Izaan

    Izaan New Member

    Joined:
    Oct 16, 2007
    Messages:
    215
    Likes Received:
    2
    Trophy Points:
    0
    I am a windows guy
     
  3. coderzone

    coderzone Super Moderator

    Joined:
    Jul 25, 2004
    Messages:
    736
    Likes Received:
    38
    Trophy Points:
    28
    So...

    By the way good article.
     
  4. Safari

    Safari New Member

    Joined:
    Oct 16, 2007
    Messages:
    183
    Likes Received:
    17
    Trophy Points:
    0
    This is not for windows but a good one.
     
  5. janu03

    janu03 Banned

    Joined:
    Jun 25, 2009
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    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
     
  6. napster_hacker17

    napster_hacker17 New Member

    Joined:
    Nov 24, 2009
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    thnx dude gud article... very helpful
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice