Using ephemeral volumes in EC2
In some of the AWS EC2 instances you can use an ephemeral volume, be careful with the data you plan to store in it, when the instance is restarted, stopped or terminated all the data is permanently deleted
You can check the complete list of EC2 instances with ephemeral volumes and his types.
Some of them will require to install an additinal package to use it.
For this example we are going to launch a g4dn.xlarge with CentOS 7 using the AWS Console, as you can see in “Step 7: Review Instance Launch”.
There are two volumes, one EBS and one Ephemeral.
Connect to the instance using SSH and use the df-h command to view the volumes that are formatted and mounted.
Use the lsblk to view any volumes that were mapped at launch but not formatted and mounted
As you can see, the name of the ephemeral volume is nvme1n1, so we can move forward and format and mount it, but before that we are going to install the package nvme-cli.
sudo yum -y install nvme-cli;
sudo mkfs.xfs /dev/nvme1n1;
sudo mkdir -p /mnt/ephemeral;
sudo mount /dev/nvme1n1 /mnt/ephemeral;
sudo chown centos:centos /mnt/ephemeral;
Download the GitHub Gist format-and-mount-nvme-volumes.sh
Now we can use the ephemeral storage mounted at /mnt/ephemeral
, e.g: for swapping/caching purposes (don’t to do that on EBS Volumes, cost and IOPS will be affected).
Tags:
Found a snippet that saved your day? Consider dropping a tip!