Skip to content

Instantly share code, notes, and snippets.

@ryanmaclean
Last active March 4, 2024 18:15
Show Gist options
  • Save ryanmaclean/c873c9a86f0bc3ee3a260882e73edecb to your computer and use it in GitHub Desktop.
Save ryanmaclean/c873c9a86f0bc3ee3a260882e73edecb to your computer and use it in GitHub Desktop.
Mount EFS on Ubuntu Linux

EFS Mounting on Ubuntu

Get EFS ID

aws configure set preview.efs true
aws efs describe-file-systems --profile TEST --region us-east-2
{
    "FileSystems": [
        {
            "SizeInBytes": {
                "Timestamp": 71990.0, 
                "Value": 614
            }, 
            "Name": "Shared-Storage-TEST", 
            "CreationToken": "console-ac435345", 
            "CreationTime": 14723446.0, 
            "FileSystemId": "fz-83A2", 
            "NumberOfMountTargets": 2, 
            "LifeCycleState": "available", 
            "OwnerId": "3423349"
        }
    ]
}

To get only the ID: aws efs describe-file-systems \ --profile TEST \ --region us-east-1 | \ grep FileSystemId | \ cut -f 4- -d '"' | \ cut -f -1 -d '"'

Or with jq installed:

aws efs describe-file-systems --profile TEST --region us-east-1 | jq -r ".FileSystems[] | .FileSystemId"

Install NFS Client

sudo apt-get install nfs-common

Mount the EFS Storage

mkdir efs-mount-point
sudo mount -t nfs4 -o vers=4.1 $(curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone).file-system-id.efs.$(curl -s http://169.254.169.254/latest/dynamic/instance-identity/document|grep region|awk -F\" '{print $4}').amazonaws.com:/   ~/efs-mount-point

For example:

sudo mount -t nfs4 -o vers=4.1 $(curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone).fs-ebeb2f234242.efs.$(curl -s http://169.254.169.254/latest/dynamic/instance-identity/document|grep region|awk -F\" '{print $4}').amazonaws.com:/ ~/efs-mount-point2
@ahmadmayahi
Copy link

Why don't you get the EFS IP address and mount it as follows:

sudo apt install amazon-efs-utils

mkdir -p /mnt/efs

sudo mount -t nfs4 EFT_IP_ADDRESS_HERE:/ /mnt/efs

#Make sure it works
df -h

@jonin
Copy link

jonin commented Sep 10, 2019

Why don't you get the EFS IP address and mount it as follows:

sudo apt install amazon-efs-utils

Because it's not available in the Ubuntu distribution?

apt install amazon-efs-utils
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package amazon-efs-utils

@kani-rifluxyss
Copy link

Here is the steps to install the utilities from the repository for Ubuntu

https://docs.aws.amazon.com/efs/latest/ug/using-amazon-efs-utils.html

Check under this section: Installing the amazon-efs-utils Package on Other Linux Distributions

@willcode4food
Copy link

You can also build from source

sudo apt install git

git clone https://github.com/aws/efs-utils

sudo apt install make

sudo apt install binutils

./build-deb.sh

sudo apt install ./build/amazon-efs-utils*deb

@kvndecker
Copy link

I have a question here.. We used EFS to encrypt a driectory. The sd card was on a PI it was moved to another PI and all the files were there to be seen. Any reason that the /home directory should not be seen??

@regevbr
Copy link

regevbr commented Jul 25, 2020

Thanks @willcode4food it works!

@IgorDePaula
Copy link

This don't work for me. With DNs name is not resolve.

@benbieler
Copy link

Run this on ubuntu:

sudo apt-get update && \
sudo apt-get -y install git binutils && \
git clone https://github.com/aws/efs-utils && \
cd efs-utils && \
./build-deb.sh && \
sudo apt-get -y install ./build/amazon-efs-utils*deb 

@samazgor
Copy link

Run this on ubuntu:

sudo apt-get update && \
sudo apt-get -y install git binutils && \
git clone https://github.com/aws/efs-utils && \
cd efs-utils && \
./build-deb.sh && \
sudo apt-get -y install ./build/amazon-efs-utils*deb 

Ya this one is more accurate.

@alanivey
Copy link

alanivey commented Dec 8, 2023

I used docker to keep from adding the build-related packages to my system:

# Build and install amazon-efs-utils deb
# https://docs.aws.amazon.com/efs/latest/ug/installing-amazon-efs-utils.html#installing-other-distro

EFS_DEB_BUILD="$( mktemp --directory )"

docker run --rm -v "$EFS_DEB_BUILD":/deb ubuntu:22.04 bash -c 'apt-get update && apt-get install -y binutils git && git clone https://github.com/aws/efs-utils && cd efs-utils && ./build-deb.sh && cp -v build/amazon-efs-utils-*.deb /deb/'

# Prevents error about user '_apt' from not having access
chmod --changes a+rx "$EFS_DEB_BUILD"

apt-get install -y "$EFS_DEB_BUILD"/amazon-efs-utils-*.deb

rm -rvf "${EFS_DEB_BUILD:?}"

unset EFS_DEB_BUILD

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment