2013-08-02

"/etc/fstab" file, how mounting of partitions is done by OS itself


Pranaam to all bhai ji _/\_
in this post we will discuss about , how system remember which partition has to mount and what will be its mount location so that whenever system boots, like boot partitions etc, its because of /etc/fstab file.
Linux system check for entries in this file during booting process and the mount the partitions according to the configuration specified in this file for each partition.
here is sample screenshot of that file


in this example , we have defined only /dev/sda1 partition properties for mounting it during booting i.e what is the partition name(its /dev/sd1) , where it has to mount(its / ), what is partition file system type( its ext4 ), what are the mount options for the partition (means does partition has read/write/permission of script execution/  etc ),dump value and file system check order

fstab file has 6 entries
1.device name
2.mount point
3.file system type
4.mount options
5.dump
6.file system check order



lests discuss about all of these

1.device name:-
as name represents, it is the name of the partition whose auto mounting we want during system startup by system itself.device name will be like this /dev/sda1 , /dev/sda2  , /dev/sda3
we can use "UUID" (universal unique id) too if our system is attached to other storage devices because every device has its unique id which prevent our system to identify devices clearly .
command for checking UUID of partition is    blkid


blkid command shows device name with its UUID and file system type.

2.mount point:-
  mount point is the place where our device/partition will be mounted.we have discussed about mount process and mount point in the article http://mannulinux.blogspot.com/2013/07/mounting-partitiondrive-in-linux.html .
for example we want that when system starts, partition /dev/sda2 should mount on our system under directory /new  , we will write down  /new for mounting /dev/sda2 to /new directory at system startup

3.file system stype:-
  its our partition file system type , whether our partition is ext4/NTFS/FAT/swap/iso9660.
we need to specify our partition file system in 3rd parameter so use blkid command to checkout file system type of partition . i will use /dev/sda2 partition and its file system type is ext4


 4.mount options:-
    mount option parameter is for defining properties of partition.we generally use option default if we have normal partition.we can also mount that partition with following options


auto -     Mount automatically at boot, or when the command mount -a is issued.
noauto - Mount only when you tell it to.
exec -    Allow execution of binaries on the filesystem.
noexec - Disallow execution of binaries on the filesystem.
ro -       Mount the filesystem read-only.
rw -      Mount the filesystem read-write.
user -    Allow any user to mount the filesystem. This automatically implies noexec, nosuid, nodev, unless  
             overridden.
users -  Allow any user in the users group to mount the filesystem.
nouser -Allow only root to mount the filesystem.
owner -Allow the owner of device to mount.
sync -   I/O should be done synchronously.
async - I/O should be done asynchronously.
dev -    Interpret block special devices on the filesystem.
nodev -Don't interpret block special devices on the filesystem.
suid -   Allow the operation of suid, and sgid bits. They are mostly used to allow users on a computer system
           to execute binary executables with temporarily elevated privileges in order to perform a specific task.
nosuid -       Block the operation of suid, and sgid bits.
noatime -    Don't update inode access times on the filesystem..
nodiratime -Do not update directory inode access times on the filesystem.
relatime -    Update inode access times relative to modify or change time. Access time is only updated if the
                  previous access time was earlier than the current modify or change time.
flush -        The vfat option to flush data more often, thus making copy dialogs or progress bars to stay up
                  until all data is written
defaults -    the default mount options for the filesystem to be used. The default options for ext4 are: rw,
                  suid, dev, exec, auto, nouser, async


 5.dump:- 
      this parameter tells dump utility about a file whether file has to backup or not. if  value is set to 0 , dump
    wont backup file. if your system dont have dump on your system then fill this parameter with value 0.

6.file system check order:-
     this parameter is to set file system check for partition when system boots.
it has 3 values :-  0,1,2
0 if device is unknown and not need to check like our CD ROM
1 for essential partition like /
2 normal partition like /root /home

ok now lets mount 2 partition
one is ext4 file system partition and second is swap \m/
currently i have only one partition mounted in my system


now we have to edit /etc/fstab file so that when ever we will boot our system, operating system will mount those partition automatically  ;)
open /etc/fstab file with vi editor using command   vi  /etc/fstab   and press enter


press i  when  to enter into edit mode of vi editor.

i am going to add entry for
 /dev/sda2 partition which is a etx4 file system type partition and want to mount it on directory /rr
/dev/sda3 partiton which is swap
swap doesnt mount any where. we need to type  swap   in mount parameter for swap partition
and in file system type too.
here is the screen shot



i have edited /etc/fstab file for  /dev/sda2  and /dev/sda3  partition automounting during system startup

after editing file , press escap to back to command mode in vi editor and then  type   :wq!
to save file and quite
and done :D  we have done

now type command mount -a to check whether our /etc/fstab file editing was ok or file has error
if by running command  mount -a  no error appear on terminal, we did it :D


now reboot your system and check your mounted partitions by running command df -hT


hell yesh \m/ our partitions are mounted as i logged into system :D
Thank you
Greetz to :- Guru ji zero and whole Team Indishell <3
Share this post

0 comments

:) :-) :)) =)) :( :-( :(( :d :-d @-) :p :o :>) (o) [-( :-? (p) :-s (m) 8-) :-t :-b b-( :-# =p~ :-$ (b) (f) x-) (k) (h) (c) cheer

© 2009 Start With Linux | Mannu Linux
Designed by cyb3r.gladiat0r
Posts RSSComments RSS
Back to top