Bootstrap FreeKB - Linux Commands - Mount a partition or share using the mount command
Linux Commands - Mount a partition or share using the mount command

Updated:   |  Linux Commands articles

The mount command can be used to display the currently mounted partitions and to also mount

  • a partition
  • an NFS share
  • a CIFS share

 


The mount command with no additional command line options or flags can be used to display the currently mounted partitions, which will typically return something like this. In this example:

  • The /dev/mapper/fedora_fedora-root (which is an LVM volume) is mounted to the / (root) directory with the XFS file system
  • The network share //server1.example.com/share is mounted to the /mnt directory with the CIFS (Common Internet File System) file system
  • There is also a tmpfs (temporary file system) mounted to the /run directory
~]# mount
/dev/mapper/fedora_fedora-root on / type xfs
//server1.example.com/share on /mnt type cifs
tmpfs on /run type tmpfs

 


A partition may be mounted using the Universally Unique Identified (UUID) or Label of the partition. A partition can be a variety of different storage devices, such as a solid state drive, USB drive, CD/DVD drive, or hard disk. The e2label command can be used to label a partition. The blkid command followed by the path to the partition can be used to determine the UUID or Label of the partition.

blkid /dev/sda1
/dev/sda1: LABEL="MyLabel" UUID="7016c299-b6b1-40ad-80f0-e4dd0b3def65" TYPE="xfs"

 

The UUID of the partition may be listed in the /dev/disk/by-uuid directory.

ls -l /dev/disk/by-uuid
lrwxrwxrwx. 1 root root 10 Jun 27 19:15 7016c299-b6b1-40ad-80f0-e4dd0b3def65 -> ../../sda1

 


The mount -t or --types <file system> <partition to mount> <mount point> command can be used to mount a partition or NFS share or CIFS share

mount --types xfs /dev/mapper/myVG-myLV /mnt

 

Or, the Universally Unique Identified (UUID) can be used.

mount --types vfat 7016c299-b6b1-40ad-80f0-e4dd0b3def65 /home

 

Or, the Label can be used. The e2label command can be used to label a partition.

mount --types ext myLabel /mnt

 


-o or --options can be used to mount a parition with additional options. In this example, the partition is mounted as a ro (read only) parition.

mount --types xfs --options ro /dev/mapper/myVG-myLV /mnt

 


You may need to first install the CIFS utilities package using apt-get or dnf install or yum install before you can mount a CIFS share.

yum install cifs-utils

 

If the network drive is configured to permit guest access, meaning there is no need to provide a username and password to access the network drive, the following is all that should be needed to mount the CIFS share.

mount --types cifs //fs1.example.com/share /mnt

 

If a username and password is required to access the network drive, add the username and password options to the mount command.

mount --types cifs //fs1.example.com/share /mnt -o username=john.doe,password=MyPassword,vers=2.0

 

Additional options can also be selected, such as uid, gid, file_mode and dir_mode.

mount --types cifs //fs1.example.com/share /mnt -o username=john.doe,password=MyPassword,vers=2.0,domain=EXAMPLE,uid=root,gid=root,file_mode=0640,dir_mode=0750

 

If you have a firewall between the client and server (e.g. iptables or firewalld), you may need to open UDP ports 137 and 138 and TCP ports 139 and 445.

firewall-cmd --add-port=137/udp --permanent
firewall-cmd --add-port=138/udp --permanent
firewall-cmd --add-port=139/tcp --permanent
firewall-cmd --add-port=445/tcp --permanent
firewall-cmd --reload

 

If the share is running on Amazon Web Services (AWS), you may need to add inbound rules to the Security Group to allow UDP ports 137 and 138 and TCP ports 139 and 587.

 


You may need to first install the NFS utilities package using apt-get or dnf install or yum install before you can mount an NFS share.

yum install nfs-utils

 

You may also need to start and enable NFS using the systemctl command.

systemctl enable nfs
systemctl start nfs

 

If you have a firewall between the client and server (e.g. iptables or firewalld), you may need to open TCP port 2049.

firewall-cmd --add-port=2049/tcp --permanent
firewall-cmd --reload

 

If the share is running on Amazon Web Services (AWS), you may need to create or update Security Groups to allow incoming on port 2049.

 

Mount the share.

mount --types nfs fs1.example.com:/srv/nfs/share /mnt/example

 


If you want to mount an Amazon Web Services (AWS) Elastic File System (EFS), check out my article Mount an Elastic File System (EFS) on an EC2 Instance.

If you want to mount an Amazon Web Services (AWS) S3 Bucket, check out my article Mount S3 Bucket in Linux EC2 Instance using S3FS.

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


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