DEV Community

Mohammad Moallemi
Mohammad Moallemi

Posted on • Edited on • Originally published at mmoallemi99.com

How to auto mount NVMe EBS Volumes on EC2?

How to auto mount NVMe EBS Volumes on EC2?

Image used from AWS youtube channel: https://www.youtube.com/watch?v=77qLAl-lRpo

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

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
Enter fullscreen mode Exit fullscreen mode

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

sudo mkfs -t ext4 /dev/nvme1n1
Enter fullscreen mode Exit fullscreen mode

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

sudo file -s /dev/nvme1n1
Enter fullscreen mode Exit fullscreen mode

The result is something like this:
/dev/nvme1n1: Linux rev 1.0 ext4 filesystem data, UUID=<br>

/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
Enter fullscreen mode Exit fullscreen mode

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

sudo mount -a
Enter fullscreen mode Exit fullscreen mode

You can checkout your mounted volumes using:

The result is something like this:
Getting a report of mounted file systems and disk space usage<br>

Getting a report of mounted file systems and disk space usage

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!

Originally published at https://mmoallemi99.com on April 28, 2021.

Top comments (0)