

# Automatically mounting EFS file systems
<a name="mount-fs-auto-mount-onreboot"></a>

You can use the EFS mount helper or NFS to configure an Amazon EC2 instance to automatically mount an EFS file system when the instance starts. 
+ Using the EFS mount helper:
  + Attach an EFS file system when you create a new EC2 Linux instance using the EC2 launch instance wizard.
  + Update the EC2 `/etc/fstab` file with an entry for the EFS file system.
+ Using [NFS without the EFS mount helper](https://docs.aws.amazon.com/efs/latest/ug/nfs-automount-efs.html) to update the EC2 `/etc/fstab` file, for EC2 Linux and Mac instances.

**Note**  
The EFS mount helper does not support automatic mounting on EC2 Mac instances running macOS Big Sur or Monterey. Instead, you can use [NFS to configure the /etc/fstab file on an EC2 Mac instance](nfs-automount-efs.md) to automatically mount an EFS file system.

**Topics**
+ [Enabling automatic mounting on new EC2 Linux instances](mount-fs-auto-mount-on-creation.md)
+ [Enabling automatic mounting on existing EC2 Linux instances](mount-fs-auto-mount-update-fstab.md)
+ [Enabling automatic mounting on EC2 Linux or Mac instances using NFS](nfs-automount-efs.md)

# Enabling automatic mounting on new EC2 Linux instances
<a name="mount-fs-auto-mount-on-creation"></a>

When you create a new EC2 Linux instance using the Amazon EC2 launch instance wizard, you can configure it to mount your Amazon EFS file system automatically. The EC2 instance mounts the file system automatically the instance first launched and also whenever it restarts.

This method uses the EFS mount helper to mount the file system update the /etc/fstab file on the EC2 instance. The mount helper is part of the [`amazon-efs-utils`](using-amazon-efs-utils.md) set of tools.

**Note**  
EFS file systems do not support mounting on EC2 Mac instances running macOS Big Sur or Monterey at instance launch.

**Note**  
You can't use Amazon EFS with Microsoft Windows–based EC2 instances.

Before you can launch and connect to an EC2 instance, you need to create a key pair. For more information, see [ Amazon EC2 key pairs and Amazon EC2 instances](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-key-pairs.html) in the *Amazon EC2 User Guide* to create a key pair. 

**To configure your EC2 instance to mount an EFS file system automatically at launch**

1. Open the Amazon EC2 console at [https://console.aws.amazon.com/ec2/](https://console.aws.amazon.com/ec2/).

1. Choose **Launch Instance**.

1. In **Step 1: Choose an Amazon Machine Image (AMI)**, find an Amazon Linux AMI at the top of the list and choose **Select**.

1. In **Step 2: Choose an Instance Type**, choose **Next: Configure Instance Details**.

1. In **Step 3: Configure Instance Details**, provide the following information: 
   + For **Network**, choose the entry for the same VPC that the EFS file system you're mounting is in.
   + For **Subnet**, choose a default subnet in any Availability Zone.
   + For **File systems**, choose the EFS file system that you want to mount. The path shown next the file system ID is the mount point that the EC2 instance will use, which you can change.
   + Under **Advanced Details**, the **User data** is automatically generated, and includes the commands needed to mount the EFS file systems you specified under **File systems**.

1. Choose **Next: Add Storage**.

1. Choose **Next: Add Tags**.

1. Name your instance and choose **Next: Configure Security Group**.

1. In **Step 6: Configure Security Group**, set **Assign a security group** to **Select an existing security group**. Choose the default security group to make sure that it can access your EFS file system.

   You can't access your EC2 instance by Secure Shell (SSH) using this security group. For access by SSH, later you can edit the default security and add a rule to allow SSH or a new security group that allows SSH. You can use the following settings:
   + **Type:** SSH
   + **Protocol:** TCP
   + **Port Range:** 22
   + **Source:** Anywhere 0.0.0.0/0

1. Choose **Review and Launch**.

1. Choose **Launch**.

1. Select the check box for the key pair that you created, and then choose **Launch Instances**.

Your EC2 instance is now configured to mount the EFS file system at launch and whenever it's rebooted.

# Enabling automatic mounting on existing EC2 Linux instances
<a name="mount-fs-auto-mount-update-fstab"></a>

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 Amazon EC2 Linux instance so that the instance uses the EFS mount helper to automatically remount an EFS file system when the instance restarts.

**Note**  
EFS file systems do not support automatic mounting using `/etc/fstab` with the EFS mount helper on EC2 Mac instances running macOS Big Sur or Monterey. Instead, you can use [NFS with `/etc/fstab`](nfs-automount-efs.md) 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](using-amazon-efs-utils.md). 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](installing-amazon-efs-utils.md#installing-other-distro).

## Prerequisites
<a name="mount-helper-fstab-prereqs"></a>

The following requirements need to be in place before you can successfully implement this procedure:
+ You have already created the EFS file system that you want to be automatically remounted. For more information, see [Quick create using the console](creating-using-create-fs.md#gs-step-two-create-efs-resources).
+ 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](using-amazon-efs-utils.md).

## Update the /etc/fstab file
<a name="update-fstab-file"></a>

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**

1. Connect to your EC2 instance. For more information, see [Connect to your EC2 instance](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/connect.html) in the *Amazon EC2 User Guide*.

1. Open the `/etc/fstab` file in an editor.

1. For automatic mounting using either IAM authorization or an EFS access point:
   + To automatically mount with IAM authorization to an 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,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](troubleshooting-efs-mounting.md#automount-fails).

   For more information, see [Mounting with IAM authorization](mounting-IAM-option.md) and [Mounting with EFS access points](mounting-access-points.md).

1. Save the changes to the file.

**Note**  
In some cases, your EC2 instance might need to start regardless of the status of your mounted 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 | 
| --- | --- | 
|  `file-system-id:/`  |  The ID for your EFS file system. You can get this ID from the console or programmatically from the CLI or an AWS SDK.  | 
|  `efs-mount-point`  |  The mount point for the EFS file system on your EC2 instance.  | 
|  `efs`  |  The type of file system. When you're using the mount helper, this type is always `efs`.  | 
|  `mount options`  |  Mount options for the file system. This is a comma-separated list of the following options: [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/efs/latest/ug/mount-fs-auto-mount-update-fstab.html)  | 
|  `0`  |  A nonzero value indicates that the file system should be backed up by `dump`. For EFS, this value should be `0`.  | 
|  `0`  |  The order in which `fsck` checks file systems at boot. For EFS file systems, this value should be `0` to indicate that `fsck` should not run at start-up.  | 

# Enabling automatic mounting on EC2 Linux or Mac instances using NFS
<a name="nfs-automount-efs"></a>

Using NFS without the EFS mount helper to update the Amazon EC2 `/etc/fstab` file, for EC2 Linux and Mac instances.

**To update the `/etc/fstab` file on your EC2 instance**

1. Connect to your EC2 instance. For more information, see [Connect to your EC2 instance](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/connect.html) in the *Amazon EC2 User Guide*.

1. Open the `/etc/fstab` file in an editor.

1. To automatically mount a file system using NFS instead of the EFS mount helper, add the following line to the `/etc/fstab` file.
   + Replace *file\$1system\$1id* with the ID of the file system you are mounting.
   + Replace *aws-region* with the AWS Region that the file system in, such as `us-east-1`.
   + Replace *mount\$1point* with the file system's mount point.

   ```
   file_system_id.efs.aws-region.amazonaws.com:/ mount_point nfs4 nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2,noresvport,_netdev 0 0
   ```

The line of code you added to the `/etc/fstab` file does the following.


| Field | Description | 
| --- | --- | 
|  `file-system-id:/`  |  The ID for your EFS file system. You can get this ID from the console or programmatically from the CLI or an AWS SDK.  | 
|  `efs-mount-point`  |  The mount point for the EFS file system on your EC2 instance.  | 
|  `nfs4`  |  Specifies the file system type.  | 
|  `mount options`  |  The comma-separated list of mount options for the file system: [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/efs/latest/ug/nfs-automount-efs.html)  | 
|  `0`  |  Specifies the `dump` value; `0` tells the `dump` utility to not back up the file system.  | 
|  `0`  |  Tells the `fsck` utility to not run at start-up.  | 