DEV Community

Cover image for Mount Up! A Step-by-Step Guide to Creating and Using Amazon EFS on Ubuntu
Kay Dee
Kay Dee

Posted on

Mount Up! A Step-by-Step Guide to Creating and Using Amazon EFS on Ubuntu

Amazon Elastic File System (EFS) provides a simple, scalable, and fully managed Network File System for use with AWS Cloud services and on-premises resources. This guide will walk you through the process of creating an EFS, mounting it on an Ubuntu instance, and adding files to it.

Prerequisites

  • An AWS account
  • An EC2 instance running Ubuntu in the same VPC as your EFS file system
  • Proper security group settings to allow NFS traffic

Step 1: Create an EFS File System

1.. Navigate to the EFS Dashboard

  • Open the AWS Management Console.
  • Go to the EFS dashboard.
  • Create a File System

2.. Click on "Create file system".

  • Follow the prompts to set up your EFS file system. You can choose the VPC, security group, and performance mode as per your requirements.

Step 2: Configure Security Groups

1.. EFS Security Group

  • Ensure the security group associated with your EFS allows inbound traffic on port 2049 (NFS).

2.. EC2 Security Group

  • Modify the security group associated with your EC2 instance to allow NFS traffic from the security group used by the EFS.

Step 3: Install NFS Client on Ubuntu

1.. Connect to Your EC2 Instance

  • Use SSH to connect to your EC2 instance.

2.. Install NFS Client using the following script:

- sudo apt-get update sudo apt-get install -y nfs-common


Step 4: Create a Mount Point

1.. Create a Directory to Mount EFS using the following script:

- sudo mkdir /mnt/efs


Step 5: Mount the EFS File System

1.. Mount the EFS File System using the following script:

- sudo mount -t nfs4 -o nfsvers=4.1 < file-system-id >.efs. < region >.amazonaws.com:/ /mnt/efs

Note: Be sure to replace file-system-id with your EFS file system ID and region with the appropriate AWS region (e.g., us-west-2).


Step 6: Verify the Mount

1.. Check the Mount Point using the following script:

- ls /mnt/efs


Step 7: Add Files to EFS

1.. Copy Files to the EFS using the following script:

- sudo cp /path/to/local/file /mnt/efs/

and / or

2.. Create Files Directly in EFS using the following script:

- echo "Hello, EFS!" | sudo tee /mnt/efs/hello.txt


Summary

There you have it! By following these steps, you can easily create an Amazon EFS, mount it on your Ubuntu instance, and add files to it. EFS provides a solution for storing files in the cloud, accessible from multiple instances as well as on-premises environments.

Let me know your thoughts by leaving a comment below. Thanks!

Top comments (0)