Enabling automatic mounting on existing EC2 Linux instances
The /etc/fstab
file contains information about file systems. The
command mount -a
, which runs during instance start-up, mounts all the file
systems listed in /etc/fstab
. In this procedure, you will manually
update the /etc/fstab
on an EC2 Linux instance so that the
instance uses the EFS mount helper to automatically remount an EFS
file system when the instance restarts.
Note
Amazon EFS file systems do not support automatic mounting using /etc/fstab
with the EFS mount helper on Amazon EC2 Mac instances running macOS Big Sur or
Monterey. Instead, you can use NFS with
/etc/fstab to automatically mount your file system on
EC2 Mac instances running macOS Big Sur and Monterey.
This method uses the EFS mount helper to mount the file system. The mount
helper is part of the amazon-efs-utils
set of tools.
The amazon-efs-utils
tools are available for installation on Amazon
Linux and Amazon Linux 2 Amazon Machine Images (AMIs). For more information about
amazon-efs-utils
, see Installing the Amazon EFS client. If you are using another Linux distribution, such
as Red Hat Enterprise Linux (RHEL), manually build and install
amazon-efs-utils
. For more information, see Installing the Amazon EFS client on other Linux
distributions.
Prerequisites
The following requirements need to be in place before you can successfully implement this procedure:
You have already created the Amazon EFS file system that you want to be automatically remounted. For more information, see Quick create a file system that has recommended settings (console).
You have already created the EC2 Linux instance that you want to configure to automatically remount an EFS file system.
The EFS mount helper is installed on the EC2 Linux instance. For more information, see Installing the Amazon EFS client.
Update the /etc/fstab file
Perform the following steps to update the /etc/fstab on an EC2 Linux instance so that the instance uses the EFS mount helper to automatically remount an EFS file system when the instance restarts.
To update the /etc/fstab file on your EC2 instance
-
Connect to your EC2 instance. For more information, see Connect to your EC2 instance in the Amazon EC2 User Guide.
Open the
/etc/fstab
file in an editor.-
For automatic mounting using either IAM authorization or an EFS access point:
-
To automatically mount with IAM authorization to an Amazon EC2 instance that has an instance profile, add the following line to the
/etc/fstab
file.file-system-id
:/efs-mount-point
efs _netdev,noresvport,tls,iam 0 0 -
To automatically mount with IAM authorization to a Linux instance using a credentials file, add the following line to the
/etc/fstab
file.file-system-id
:/efs-mount-point
efs _netdev,noresvport,tls,iam,awsprofile=namedprofile
0 0 -
To automatically mount a file system using an EFS access point, add the following line to the
/etc/fstab
file.file-system-id
:/efs-mount-point
efs _netdev,noresvport,tls,iam,accesspoint=access-point-id
0 0
Warning
Use the
_netdev
option, used to identify network file systems, when mounting your file system automatically. If_netdev
is missing, your EC2 instance might stop responding. This result is because network file systems need to be initialized after the compute instance starts its networking. For more information, see Automatic mounting fails and the instance is unresponsive.For more information, see Mounting with IAM authorization and Mounting with EFS access points.
-
-
Save the changes to the file.
-
Test the
fstab
entry by using themount
command with the'fake'
option along with the'all'
and'verbose'
options.$
sudo mount -fav
home/ec2-user/efs : successfully mounted
Your EC2 instance is now configured to mount the EFS file system whenever it restarts.
Note
In some cases, your Amazon EC2 instance might need to start regardless of the status of
your mounted Amazon EFS file system. In such cases, add the nofail
option to your
file system's entry in your /etc/fstab
file.
The line of code you added to the /etc/fstab
file does the
following.
Field | Description |
---|---|
|
The ID for your Amazon EFS file system. You can get this ID from the console or programmatically from the CLI or an AWS SDK. |
|
The mount point for the EFS file system on your EC2 instance. |
|
The type of file system. When you're using the mount helper, this type is
always |
|
Mount options for the file system. This is a comma-separated list of the following options:
|
|
A nonzero value indicates that the file system should be backed up by
|
|
The order in which |