Skip to content

How do I mount or unmount my Amazon EFS file system?

6 minute read
0

I want to mount, automatically mount, or perform an on-premises mount of my Amazon Elastic File System (Amazon EFS) file system. Or, I want to unmount my EFS file system.

Resolution

Note: To mount your EFS file system, use the Amazon EFS client amazon-efs-utils or the NFS utilities package nfs-utils. For information on the NFS utilities package, see Package nfs-utils from the Mankier website.

Use the Amazon EFS client to mount an Amazon EFS file system

Install the Amazon EFS client for your distribution

To install amazon-efs-utils, run one of the following commands based on your distribution:

Amazon Linux 1, Amazon Linux 2, and Amazon Linux 2023 (AL2023):

sudo yum install -y amazon-efs-utils

AL2023 Amazon Machine Image (AMI) without yum:

sudo dnf install -y amazon-efs-utils

Ubuntu and Debian:

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

Note: Some Ubuntu and Debian distributions don't include rust or cargo in their package repositories, or might include versions earlier than 1.70. If the apt-get install command fails because of a missing or outdated Rust toolchain, then run the following commands before you run build-deb.sh:

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
. "$HOME/.cargo/env"

OpenSUSE or SUSE Linux Enterprise Server (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

Connect your Amazon EFS file system to your Amazon EC2 instance

Complete the following steps:

  1. Open the Amazon EFS console.
  2. In the navigation pane, choose File systems.
  3. Select your EFS file system.
  4. To see the Mount command, choose Attach.
  5. Use SSH or Session Manager, a capability of AWS Systems Manager, to connect to your Amazon Elastic Compute Cloud (Amazon EC2) instance.
  6. To create mount point directories and mount an EFS file system to them, run the following commands:
    sudo mkdir -p /mnt/efs
    sudo mkdir -p /mnt/efs-ap
    sudo mount -t efs -o tls fs-12345678:/ /mnt/efs
    sudo mount -t efs -o tls,accesspoint=fsap-12345678 fs-01233210 /mnt/efs-ap
    Note: Replace fs-12345678 and fs-01233210 with your EFS file system IDs. Replace fsap-12345678 with your EFS access point ID.

Use the NFS utilities package to mount an Amazon EFS file system

Install the NFS utilities package for your distribution

To install the nfs-utils package, run one of the following commands based on your distribution:

RHEL and CentOS:

sudo yum -y install nfs-utils

Linux bindles that don't include yum:

sudo dnf install -y nfs-utils

Ubuntu:

sudo apt install nfs-common

Connect your Amazon EFS file system to your Amazon EC2 instance

  1. Open the Amazon EFS console.
  2. In the navigation pane, choose File systems.
  3. Select your EFS file system.
  4. To see the Mount command, choose Attach.
  5. Use SSH or Session Manager to connect to your EC2 instance.
  6. To mount an EFS file system to a local directory, run the following commands:
    sudo mkdir -p /mnt/efs  #creating the efs-mount-point
    sudo mount -t nfs -o nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2,noresvport mount-target-DNS:/   /mnt/efs
    Note: Replace mount-target-DNS with the DNS name of the EFS mount target in your virtual private cloud (VPC).
    Or, to use an IP address to mount the file system, 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:/  /mnt/efs
    Note: Replace mount-target-ip with the IP address of the EFS mount target in your VPC.

Automatically mount an Amazon EFS file system

You can mount an EFS file system for running or new EC2 instances.

Use running EC2 instances

If you already have a running EC2 instance, use /etc/fstab to automatically mount your EFS file system.

Complete the following steps:

  1. To launch the Vim text editor, run the following command:

    vim /etc/fstab
  2. To automatically mount your EFS file system at boot, run either the efs type entry or nfs4 type entry command based on your configuration.
    For the amazon-efs-utils package, run the following command:

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

    For the nfs-utils package, run the following command:

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

    Note: Replace fs-######## with your EFS file system ID.

  3. To immediately apply the configuration without rebooting, run the following command:

    mount -a

For mount options that use the mount helper, see Automatically mounting EFS file systems.

Note: To mount your EFS file system, you can use the IP address of a mount target in a different Availability Zone from the client instance. This mount method can incur cross Availability Zone data transfer charges and cause latency.

Use new EC2 instances

If you create a new EC2 instance, then use the Amazon EC2 launch instance wizard to automatically mount your EFS file system. When you configure the EC2 instance, take the following actions:

  • Under File systems, select your file system. The path next to the file system ID is the mount point that the EC2 instance uses. You can change this path based on your requirements.
  • Be aware that AWS automatically generates the user data in the Advanced details section to mount the EFS file system.
  • Choose the default security group to make sure that the EC2 instance can access your EFS file system. To allow SSH access, edit the default security group. Then, add a rule with Type set to SSH, Protocol set to TCP, Port Range set to 22, and Source set to Anywhere (0.0.0.0/0).

Or, to mount an EFS file system on a custom AMI or with specific options, run the following commands to add custom user data:

RHEL and CentOS:

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

Ubuntu:

#!/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

Then, launch your EC2 instance.

Mount an Amazon EFS file system on-premises

To mount an EFS file system on your on-premises servers, you must have connectivity between Amazon EFS and your on-premises servers. To establish connectivity between your 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)
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-IP:/ /mnt/efs

Unmount an Amazon EFS file system

To unmount a file system, run the following umount command:

sudo umount /mnt/efs

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

sudo umount -l /mnt/efs

Related information

Package management tool

Tutorial: Mounting with on-premises Linux clients

Run commands when you launch an EC2 instance with user data input

AWS OFFICIALUpdated 4 months ago
3 Comments

In a few places there should be a line feed that is missing from the list of commands:

Example 1:

$ sudo mkdir -p /mnt/efs$ sudo mount -t efs -o tls fs-12345678:/ /mnt/efs

Should be

$ sudo mkdir -p /mnt/efs
$ sudo mount -t efs -o tls fs-12345678:/ /mnt/efs

Example 2:

#cloud-configpackage_update: true

Should be:

#cloud-config
package_update: true

Example 3:

Note: This is broken the same in 2 places

#!/bin/bashsudo mkdir -p /mnt/efs

Should be

#!/bin/bash
sudo mkdir -p /mnt/efs

Example 4:

$ sudo yum -y install nfs-utils (Red Hat Linux)$ sudo apt-get -y install nfs-common(Ubuntu)

Should be:

$ sudo yum -y install nfs-utils # For (Red Hat Linux)
$ sudo apt-get -y install nfs-common # For (Ubuntu)

replied 2 years ago

Thank you for your comment. We'll review and update the Knowledge Center article as needed.

AWS
EXPERT

replied 2 years ago

This article was reviewed and updated on 2026-03-06.

AWS
MODERATOR

replied 4 months ago