How to auto mount NVMe EBS Volumes on EC2?

How to auto mount NVMe EBS Volumes on EC2?

In this tutorial, we’re going to mount an NVMe EBS volume to an EC2 instance and add it to /etc/fstab so it automatically mounts the volume after reboots.

First list block devices using lsblk:
sudo lsblk
You will see a result similar to this:

List block devices in order to see all available NVMe devices

The NVMe volumes names follow the pattern below:

/dev/nvme0n1
/dev/nvme1n1
/dev/nvme2n1
.
.
.
/dev/nvme[0-26]n1

Then build a Linux file system of your choice, I picked ext4 here:

sudo mkfs -t ext4 /dev/nvme1n1

Verify the build using the file command and copy the UUID value:

sudo file -s /dev/nvme1n1

The result is something like this:

/dev/nvme1n1: Linux rev 1.0 ext4 filesystem data, UUID=

Now edit /etc/fstab with the editor of your choice (I prefer nano xD) and add the following line to it:

UUID="<copied-uuid-value>" <mount-directory-path> ext4 defaults 0 0

Now we use the mount utility to verify and mount the volume.

sudo mount -a

You can checkout your mounted volumes using:

df -t ext4
Getting a report of mounted file systems and disk space usage

I hope you enjoyed it, feel free to drop a comment if you have any questions.
Happy Engineering!

Published by

Mohammad Moallemi

Software Engineer by day, Technical Lead by night https://www.linkedin.com/in/mmoallemi99/

Leave a Reply

Your email address will not be published. Required fields are marked *