Mounting an EFS File System
This guide provides step-by-step instructions for mounting an Amazon EFS file system on an Amazon EC2 instance. This will allow your EC2 instance to access the shared file system.
Prerequisites
Section titled “Prerequisites”Before you begin, you will need:
- An active University of Oregon AWS account.
- An existing EFS file system. You can create one by following our EFS Overview guide.
- An running EC2 instance in the same VPC as your EFS file system. You can create one by following our Introduction to EC2 guide.
- The ID of your EFS file system.
Step 1: Connect to Your EC2 Instance
Section titled “Step 1: Connect to Your EC2 Instance”First, connect to your EC2 instance using SSH. You will need the public IP address or DNS name of your instance and your private key.
ssh -i /path/to/your-key.pem ec2-user@your-instance-ipStep 2: Install the EFS Mount Helper
Section titled “Step 2: Install the EFS Mount Helper”The EFS mount helper is a utility that simplifies mounting and unmounting EFS file systems. It is recommended to use the mount helper to mount your file systems.
To install the EFS mount helper on Amazon Linux 2, use the following command:
sudo yum install -y amazon-efs-utilsFor other Linux distributions, please refer to the official AWS documentation.
Step 3: Create a Directory for the Mount Point
Section titled “Step 3: Create a Directory for the Mount Point”Next, create a directory that you will use as the mount point for your EFS file system.
sudo mkdir /mnt/efsStep 4: Mount the EFS File System
Section titled “Step 4: Mount the EFS File System”Now you can mount the EFS file system to the directory you just created. Replace fs-12345678 with the ID of your EFS file system.
sudo mount -t efs fs-12345678:/ /mnt/efsYou can verify that the file system is mounted correctly by running the df -h command.
df -hYou should see your EFS file system listed in the output.
Step 5: Automatically Mount the File System on Boot
Section titled “Step 5: Automatically Mount the File System on Boot”To ensure that your EFS file system is automatically mounted whenever your EC2 instance reboots, you should add an entry to the /etc/fstab file.
Open the /etc/fstab file in a text editor:
sudo nano /etc/fstabAdd the following line to the end of the file, replacing fs-12345678 with your file system ID:
fs-12345678:/ /mnt/efs efs _netdev,tls 0 0Save and close the file. Now your EFS file system will be automatically mounted on boot.
Troubleshooting
Section titled “Troubleshooting”- Mount command fails: Ensure that your EC2 instance’s security group allows outbound NFS traffic (port 2049) to the security group of your EFS mount targets.
- Connection timed out: Verify that your EC2 instance and EFS mount targets are in the same VPC and that the route tables are configured correctly.
Next Steps
Section titled “Next Steps”Now that you have mounted your EFS file system, you can start using it to store and share data between your EC2 instances.
- Learn how to use EFS Access Points to manage application access to your file system.