Permanently mount partition or share in /etc/fstab in Linux

Home > Search
  by

This assume you are able to use the mount command to mount a storage device. With the mount command, if the operating system is restarted, the shared network drive will no longer be mounted. Us humans, we are so prone to forgetfulness. Adding an entry to /etc/fstab will mount the storage device at boot.

 


UUID or Label

A local hard disk drive or solid state drive is often mounted using the Universally Unique Identified (UUID) or Label of the storage device. The blkid command will display the UUID and Label (if a label has been created) of the device. The e2label command can be used to label a storage device.

[john.doe@server1 ~]# blkid /dev/sda1
/dev/sda1: LABEL="MyLabel" UUID="7016c299-b6b1-40ad-80f0-e4dd0b3def65" TYPE="xfs"

 


Mounting a local hard disk drive or solid state drive

The entry in /etc/fstab will have 6 fields: <storage device> <directory> <file system> <options> <dump> <fschk>. There are numerous options for each field.

  1. Device
    • Path, such as /dev/sda1
    • LVM label, such as /dev/mapper/vg_vg00_root
    • Label, such as VAR
    • UUID, such as 7016c299-b6b1-40ad-80f0-e4dd0b3def65
  2. Mount point
    • This can be any directory. Popular mount points are /home and /var. There are many mount points that should not be used, such as /bin, /sbin, /usr, /sys, and /proc, just to name a few.
  3. File system
    • auto (attempt to automatically detect the filesystem)
    • ext2
    • ext3
    • ext4
    • reiserfs
    • btfs
    • vfat
    • xfs
    • swap
  4. Options
    • Default
    • auto = automatically mount the system during boot
    • noauto = Do not automatically mount the system during boot
    • ro = read only
    • rw = read / write
    • usrquota = quota for users
    • grpquota = quota for groups
    • users = allow non-root users to mount and umount
  5. Dump
    1. 0 = Do not back up the device
    2. 1 = Back up the device
  6. FSCK
    • 0 = do not perform fsck
    • 1 = perform fsck on first priority
    • 2 = perform fsck on second priority

 

 

In this example, the storage device with UUID 7016c299-b6b1-40ad-80f0-e4dd0b3def65 is mounted on the /home directory with the xfs file system.

7016c299-b6b1-40ad-80f0-e4dd0b3def65  /home  xfs  defaults  0  0

 


Mounting a shared network drive using CIFS (common Internet file system)

If using CIFS, use apt-get or yum to install the CIFS utilities package.

[root@server1 ~]# yum install cifs-utils

 

In this example, the storage device named share on the fs1.example.com server is mounted on the /mnt directory using the cifs file system, and there are many options included.

//fs1.example.com/share  /mnt  cifs  username=example,password=example,domain=EXAMPLE,uid=root,gid=root,file_mode=0640,dir_mode=0750  0  0

 

Breaking down the example:

  • //fs1.example.com/share is the UNC path to the share. If you do not have a DNS server in your network, replace fs1.example.com with the IP address of the computer that is sharing the share.
  • /mnt is a directory on the local machine
  • username=example
    • If the network drive is shared using Samba on Linux, and the /etc/samba/smb.conf file has security = user and passdb backend = tdbsam, you will user a username and password of an account from the remote Samba server
    • If the network drive is shared using Samba on Linux, and  the /etc/samba/smb.conf file has security = ADS and realm = your.domain.com and password server = your.domain.com, you will use a username and password of an Active Directory account that is a member of the Administrators group.
    • If the network drive is shared using Windows, the username is typically Everyone.
  • password=example is the password from the remote PC for username=example.
  • domain=EXAMPLE is only needed if the /etc/samba/smb.conf file has security = ADS and realm = your.domain.com and password server = your.domain.com. If this is true, the domain name will be the name of the workgroup in the /etc/samba/smb.conf file.
  • uid=root is only needed if the remote share is on a Linux machine.
  • gid=root is only needed if the remote share is on a Linux machine.
  • file_mode=0640 gives read & write permission to the owner, read permission to the group, and no permission to other.
  • dir_mode=0750 gives read, write, & execute permission to the owner, read and execute permission to the group, and no permission to other.

 


Mounting a shared network drive using NFS (network file system)

To add the a shared storage device to /etc/fstab using NFS:

fs1.example.com:/srv/nfs/share   /mnt/nfs/share   nfs   rsize=8192,wsize=8192,timeo=14,intr   0   0

 

Remount all.

~]# mount -a

 

After the restart, the remote share should automatically be mounted. If the remote share is not automatically mounted, use the following command to view the mount events in the boot log.

~]# cat /var/log/messages | grep mount

 



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




Please enter in the box below so that we can be sure you are a human.




Comments