Saturday, 9 September 2023

Configure EFS for Linux

 Configure Amazon Elastic File System (EFS) as a common storage for Linux Instances.


Step 1: Go to AWS console and search for EFS service. Click on Create file system.

Give the name as MyEFS. Note the VPC that this file system is created in.

Click on Create.

Ensure that the File system state is Available.


Step 2: Go to EC2 services and create a Linux Instance. Note the Subnet (AZ). For instructions and help in creating Linux Instance refer he the AWS EC2 Linux Instance document.


Step 3: Now create a new security group for the purpose of associating with the EFS.

In EC2, go to Network & Security -> Security Groups. Click on Create security groups.

In Basic details, name the group EFS-SG. Give appropriate description.

Scroll down to Inbound Rules. Click on Add Rule. Give the following attributes:

  • Type: NFS

  • Protocol: TCP, Port Range: 2049 (This is default selected)

  • Source: Linux SG (The security group associated with the created Linux Instance)

Scroll to Outbound rules and check the default All Traffic value under Type.

Click on Create security group button in bottom right corner. Confirm that it is created.


Step 4: Go to EFS console. Select the file system created above. Click on View details. Scroll down and select Network. Click on Manage.

Here all the AZs from the present Region are listed along with the security groups. The default selection is default SG.

Click on the x and remove the default security group. Search and add the custom EFS SG created in above step. Click on Save.


Step 5: SSH into the Instance.

Now install amazon-efs-utils package which has efs mount helper using the following command:

sudo yum install -y amazon-efs-utils

Step 6: After the utility installation are complete, make a directory for the mount point using the following command:

sudo mkdir efsdir

Mount the file system to the directory created in the above step using the following command.

Ensure that you replace the files system id that is marked blue in the below command with your own EFS ID:

sudo mount -t efs fs-8c1a7d5d:/ efsdir


Step 7: Change the directory to the mount point that is created above using the command:

cd efsdir

Create a new sub directory with following command:

sudo mkdir begin

Change the permissions of the above subdirectory with the following command:

sudo chown ec2-user begin

Change the directory to begin directory with following command:

cd begin

Create a sample text file:

touch myfile.txt

Run ls command to list the contents of directory.

Let this session be running.


Step 8: Now proceed to create one more Linux instance in a different subnet (AZ) than the first one.

Step 9: Follow Step 5 and Step 6 to SSH, install utils, create mount point directory and mount it.

Change the directory to the mount point that is created above using the command

cd efsdir and change to begin directory with cd begin.

Create a new file using touch command. List the contents with ls command.

The file created with first instance and second instance, both are visible in this session.


Step 10: Go back to the first session, run ls command and observe both the files, accessibility of which is possible because of the EFS created.

Note: Close both sessions, Terminate the instances and delete the Elastic File System if you no longer need them.

No comments:

Post a Comment