Skip to content

Instantly share code, notes, and snippets.

@RobertoC27
Last active June 21, 2020 19:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RobertoC27/5be43649e0baac2a5d8acc70fb3ed80c to your computer and use it in GitHub Desktop.
Save RobertoC27/5be43649e0baac2a5d8acc70fb3ed80c to your computer and use it in GitHub Desktop.
EBS volumes cheatsheet

How to create a filesystem on an EBS volume attached to EC2 instance and make ec2-user owner

Based on the docs found here

Find the device name

$ lsblk # Nitro based output
NAME          MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
nvme0n1       259:0    0   8G  0 disk
├─nvme0n1p1   259:1    0   8G  0 part /
└─nvme0n1p128 259:2    0   1M  0 part
nvme2n1       259:4    0  40G  0 disk /home/ec2-user/data
nvme1n1       259:3    0  10G  0 disk

only for Amazon Linux 1

$ sudo yum install xfsprogs # to avoid getting an error on the next step

Create the filesystem

$ sudo mkfs -t xfs /dev/xvdf # Traditional based mount point
$ sudo mkfs -t xfs /dev/nvme1n1 # Nitro based mount point
$ sudo file -s /dev/<volume-name> # to check that filesystem was properly created

Create mountpoint and mount the volume

$ mkdir ~/my-mountingpoint
$ sudo mount /dev/<volume-name> ~/my-mountingpoint 

Make ec2-user owner of the mounting point folder

$ sudo chown -R ec2-user /home/ec2-user/my-mountingpoint

Mount the volume on boot (optional)

$ sudo blkid # check for the volumeid you used previously
$ sudo nano /etc/fstab #make a copy first!
# Add the following to the end of the file
UUID=<insert uuid here>  /data  xfs  defaults,nofail  0  2
$ sudo reboot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment