What are the basic steps for mounting, unmounting, automounting, and on-premises mounting my EFS file system?

6 minute read
0

What are the basic steps for mounting, unmounting, automounting, and on-premises mounting of my Amazon Elastic File System (Amazon EFS) file system?

Resolution

To mount your Amazon EFS file system, you can either install the nfs-utils package or the efs-utils package.

Mounting EFS with efs-utils tools

1.    Run the following command to install the efs-utils package:

Amazon Linux or Amazon Linux 2

$ sudo yum install -y amazon-efs-utils

Ubuntu and Debian-based distributions

$ sudo apt-get -y install ./build/amazon-efs-utils*deb./build-deb.sh
$ cd /path/to/efs-utils
$ git clone https://github.com/aws/efs-utils
$ sudo apt-get -y install git binutils
$ sudo apt-get update

Other Linux distributions

$ sudo yum -y install git
$ sudo yum -y install rpm-build
$ git clone https://github.com/aws/efs-utils
$ cd /path/efs-utils
$ sudo yum -y install make
$ sudo yum -y install rpm-build
$ sudo make rpm
$ sudo yum -y install ./build/amazon-efs-utils*rpm

2.    After the efs-utils package is installed, open the EFS console.

3.    Select File systems.

4.    Select the file system that you want to mount.

5.    Select Attach.

6.    Copy the command under using the EFS mount helper.

7.    Connect to the instance through SSH or AWS Systems Manager Session Manager and run the command you copied in step 6:

$ sudo mkdir -p /mnt/efs
$ sudo mount -t efs -o tls fs-12345678:/ /mnt/efs
$ sudo mount -t efs -o tls,accesspoint=fsap-12345678 fs-01233210 /mnt/efs

Note: Edit the preceding commands as required by replacing the file system id, mount point, and so on.

Mounting EFS with the NFS client

1.    Run the following command to install the nfs-utils package:

RHEL and CentOS-based distributions

$ sudo yum -y install nfs-utils

Ubuntu-based distributions

$ sudo apt install nfs-common

2.    After installing the nfs-utils package, navigate to the EFS console.

3.    Select File systems.

4.    Select the file system that you want to mount.

5.    Select Attach.

6.    Copy the command under using the NFS mount helper.

7.    Connect to the instance through SSH or Session Manager and run the command you copied in step 6:

$ sudo mkdir -p /mnt/efs
$ sudo mount -t nfs -o nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2,noresvport mount-target-DNS:/   ~/efs-mount-point

-or-

Run the following command to mount using an IP address:

$ sudo mount -t nfs -o nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2,noresvport mount-target-ip:/  ~/efs-mount-point

Note: Edit the preceding commands as required by replacing the file system id, mount point, DNS, IP address, and so on.

Unmounting an EFS file system

Run the following command to unmount the file system:

$ umount /mnt/efs

If the mount point is busy, then use the -l parameter with the umount command:

$ umount -l /mnt/efs

Auto-mounting a file system using /etc/fstab

Run the following commands to make an entry in /etc/fstab so that the EFS mount persists on reboot:

# vim /etc/fstab

Using efs-utils

fs-xxxxxxxx:/ /mnt/efs efs _netdev,nofail,noresvport,tls,iam 0 0

Using the NFS client

Modify the parameters in fstab as needed for your configuration.

fs-XXXXXXXX.efs.REGION.amazonaws.com:/ /mnt/efs nfs4 defaults,_netdev,nofail 0 0
# mount -a

For various mounting options using the mount helper, see Automatically mount EFS using /etc/fstab with EFS mount helper.

Note: You can mount your file system using an IP address of a mount target in a different Availability Zone than the client (Amazon Elastic Compute Cloud (Amazon EC2)). When you do this, consider factors such as cross-Availability Zone data transfer charges, and latency.

Mounting EFS on instance launch using the launch wizard

When launching EC2 instances you can use the launch wizard to add user data automatically for mounting of EFS.

1.    Open the EC2 console.

2.    Select Launch instances.

3.    Select an AMI and an instance type, and then select Next: Configure Instance Details.

4.    Configure various parameters as per your requirements. Make sure that you select the required VPC and subnet for EFS mounting.

5.    On the Configure instance page, under File systems, choose the EFS file system that you want to mount. The path shown next the file system ID is the mount point that the EC2 instance will use. You can change this path, if needed. User data is automatically generated for mounting EFS in the Advanced details section:

#cloud-config
package_update: true
package_upgrade: true
runcmd:
- yum install -y amazon-efs-utils
- apt-get -y install amazon-efs-utils
- yum install -y nfs-utils
- apt-get -y install nfs-common
- file_system_id_1=fs-0cae1679a766bcf49
- efs_mount_point_1=/mnt/efs/fs1
- mkdir -p "${efs_mount_point_1}"
- test -f "/sbin/mount.efs" && printf "\n${file_system_id_1}:/ ${efs_mount_point_1} efs tls,_netdev\n" >> /etc/fstab || printf "\n${file_system_id_1}.efs.us-east-1.amazonaws.com:/ ${efs_mount_point_1} nfs4 nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2,noresvport,_netdev 0 0\n" >> /etc/fstab
- test -f "/sbin/mount.efs" && grep -ozP 'client-info]\nsource' '/etc/amazon/efs/efs-utils.conf'; if [[ $? == 1 ]]; then printf "\n[client-info]\nsource=liw\n" >> /etc/amazon/efs/efs-utils.conf; fi;
- retryCnt=15; waitTime=30; while true; do mount -a -t efs,nfs4 defaults; if [ $? = 0 ] || [ $retryCnt -lt 1 ]; then echo File system mounted successfully; break; fi; echo File system not available, retrying to mount.; ((retryCnt--)); sleep $waitTime; done;>

-or-

To mount EFS on a custom AMI or with specific options, add custom user data with the required commands in the Advanced details section. For more information, see Run commands on your Linux instance at launch.

RHEL and CentOS-based distributions

#!/bin/bash
sudo mkdir -p /mnt/efs
sudo yum -y install nfs-utils

Ubuntu-based distributions

#!/bin/bash
sudo mkdir -p /mnt/efs
sudo apt install nfs-common
sudo mount -t nfs -o nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2,noresvport mount-target-ip:/  /mnt/efs

6.    Launch the instance.

Mounting EFS on-premises

To mount EFS on your on-premises servers, there must be connectivity between EFS and the on-premises servers. You can use AWS Direct Connect and VPN to establish this connectivity.

After establishing connectivity between the on-premises server and EFS's VPC, run the following commands to install the NFS client and mount EFS:

$ sudo yum -y install nfs-utils (Red Hat Linux)
$ sudo apt-get -y install nfs-common(Ubuntu)
$ mkdir ~/efs
$ sudo mount -t nfs -o nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2,noresvport mount-target-IP:/  ~/efs

For more information, see Mounting on your on-premises Linux client with the EFS mount helper over AWS Direct Connect and VPN.


AWS OFFICIAL
AWS OFFICIALUpdated 2 years ago