I want to know how to mount, unmount, automount, and on-premises mount my Amazon Elastic File System (Amazon EFS) file system.
Resolution
Mount a file system
To mount your EFS file system, either install the amazon-efs-utils package. Or, install the nfs-utils package from the Mankier website.
Use amazon-efs-utils
-
To install the amazon-efs-utils package, run one of the following commands based on your distribution:
Amazon Linux or Amazon Linux 2
$ sudo yum install -y amazon-efs-utils
Ubuntu and Debian-based distributions
$ sudo apt-get update
$ sudo apt-get -y install git binutils rustc cargo pkg-config libssl-dev
$ git clone https://github.com/aws/efs-utils
$ cd efs-utils
$ ./build-deb.sh
$ sudo apt-get -y install ./build/amazon-efs-utils*deb
If your distribution doesn't provide a rust or cargo package, or provides versions that are earlier than 1.68, then use rustup to install rust and cargo:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh. "$HOME/.cargo/env"
To build and install an RPM, run one the following commands based on your distribution:
OpenSUSE or SLES
$ sudo zypper refresh
$ sudo zypper install -y git rpm-build make rust cargo openssl-devel
$ git clone https://github.com/aws/efs-utils
$ cd efs-utils
$ make rpm
$ sudo zypper --no-gpg-checks install -y build/amazon-efs-utils*rpm
All other distributions
$ sudo yum -y install git rpm-build make rust cargo openssl-devel
$ git clone https://github.com/aws/efs-utils
$ cd efs-utils
$ make rpm
$ sudo yum -y install build/amazon-efs-utils*rpm
-
Open the EFS console.
-
In the navigation pane, choose File systems.
-
Select your file system.
-
Choose Attach.
-
Use SSH or Session Manager, a capability of AWS Systems Manager, to connect to the instance. Then, run the following commands:
$ 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: Replace the example values with your values.
Use nfs-utils
-
To install the nfs-utils package, run one of the following commands based on your distribution:
RHEL and CentOS-based distributions
$ sudo yum -y install nfs-utils
Ubuntu-based distributions
$ sudo apt install nfs-common
-
Open the EFS console.
-
In the navigation pane, choose File systems.
-
Select your file system.
-
Choose Attach.
-
Use SSH or Session Manager to connect to the instance, and then run the following command:
$ 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-
To use an IP address to mount, run the following command:
$ sudo mount -t nfs4 -o nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2,noresvport mount-target-ip:/ ~/efs-mount-point
Note: Replace the example values with your values.
Unmount a file system
To unmount a file system, run the following command:
$ umount /mnt/efs
If the mount point is busy, then run the unmount command with the -l parameter:
$ umount -l /mnt/efs
Use /etc/fstab to automount a file system
To make an entry in /etc/fstab so that the Amazon EFS mount persists on reboot, run the following commands:
# vim /etc/fstab
Use amazon-efs-utils
fs-########:/ /mnt/efs efs _netdev,nofail,noresvport,tls,iam 0 0
Use nfs-utils
Configure your parameters in fstab:
fs-########.efs.REGION.amazonaws.com:/ /mnt/efs nfs4 defaults,_netdev,nofail 0 0
# mount -a
For mount options that use the mount helper, see Automatically mounting EFS file systems.
Note: You can use the IP address of mount target in a different Availability Zone from the client Amazon Elastic Compute Cloud (Amazon EC2) to mount. This mount method can incur cross Availability Zone data transfer charges and cause latency.
Use the Launch Wizard to mount a file system at instance launch
When you launch EC2 instances, you can use the launch wizard to automatically add user data to mount your file system.
Complete the following steps:
- Open the EC2 console.
- Choose Launch instances.
- Select an Amazon Machine Image (AMI) and an instance type, and then choose Next: Configure Instance Details.
- Configure the parameters for your use case. Make sure that you select the required virtual private cloud (VPC) and subnet for EFS mounting.
- On the Configure instance page, under File systems, select your file system. The path that's next to the file system ID is the mount point that the EC2 instance uses. You can change this path as needed. To mount your file system, user data is automatically generated 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 an Amazon EFS file system on a custom AMI or with specific options, run the following commands to add custom user data:
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 nfs4 -o nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2,noresvport mount-target-ip:/ /mnt/efs
For more information, see Run commands on your Amazon EC2 instance at launch.
- Launch the instance.
Mount a file system on-premises
To mount an Amazon EFS file system on your on-premises servers, there must be connectivity between Amazon EFS and the on-premises servers. To establish connectivity between the on-premises server and Amazon Virtual Private Cloud (Amazon VPC), use AWS Direct Connect and AWS VPN. Then, run the following commands to install the NFS client and mount your file system:
$ 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 Tutorial: Mounting with on-premises Linux clients.