How To Mount AWS EFS File System on EC2 Instance
Step 1: Check Requirements/Prerequisites
Before proceeding to mount the EFS file system, the user needs to have:
- An AWS Account.
- Created a user with permissions to create resources on the AWS Account.
- Created an EFS file system on the AWS account.
- Ensure that the security group of the EFS allows the security group of the EC2 instance on port 2049.
Step 2: Mount the EFS
We can mount an EFS on an existing EC2 instance. It can also be mounted when launching a new EC2 Instance. I have explained this below.
On the Elastic File system console, select the EFS you created.
Click attach.
Select Mount via DNS or Mount via IP. Should you have a VPC with DNS hostnames disabled, select the mount via IP option. Click User guide to get the guide on how to Install the mount helper. The amazon-efs-utils package. For example, for a Linux instance, run the below command to install the mount helper.
sudo yum install -y amazon-efs-utils
Your installation should look similar to below:
on your EC2 instance create a directory called efs.
sudo mkdir efs
The EFS will be mounted on your EC2 instance as per above image. You can confirm by running the below command.
df -h
To Mount the EFS on an Ubuntu instance, follow the below instructions.
Create a directory called efs
sudo apt-get -y install nfs-common
Run the below command to mount the EFS. Make sure to replace the command with your EFS specific mount instruction command.
sudo mount -t nfs4 -o nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2,noresvport fs-d3e98219.efs.eu-west-1.amazonaws.com:/ efs
Confirm that the file system has been mounted using the below command.
df -h
Mount on an EC2 Instance at Launch
When Launching an EC2 instance, on the configure instance page, under file systems select the file system you created. See below.
The EC2 will be launched with the file system mounted.
Mount EFS on EC2 Instance Automatically on Reboot
Using System Manager or SSH connect to your EC2 instance. edit the fstab file and add the below command. To edit the file use the command below.
$ sudo vi /etc/fstab
fs-d3e98219.efs.eu-west-1.amazonaws.com:/ usr/bin/efs nfs defaults,_netdev 0 0
See screenshot below:
N/B: Ensure that on the fstab file you use the exact path where your efs directory is. For this case, my efs is in /usr/bin/efs. Also, ensure your replace the file system identity with your specific file system.
To test use:
sudo mount -fav
If the fstab file is configured correctly, you should see the below:

You can now reboot your instance and the EFS will be mounted automatically. To unmount the EFS run the below command:
umount -f /usr/bin/efs
Again, ensure you replace the path to the efs directory with your own specific path.
Comments
Post a Comment