How to do it…

Follow these steps to create an Elastic Block Store (EBS) volume and attach it to an instance. EBS is the AWS service that provides disk storage to EC2 instances. While some instance types come with local disk storage, in the vast majority of cases, you will be working with EBS. You can think of EBS as being similar to a Storage Attached Network (SAN) or Network Attached Storage (NAS), but there are significant advantages to EBS over those technologies, which will be covered later:

  1. Create a volume:
      aws ec2 create-volume --availability-zone us-east-1a --size 8
Take note of the returned VolumeId in the response. It will start with vol-followed by alphanumeric characters.
  1. Attach the volume to the instance using the volume ID we noted in the previous step and the instance ID you started with:
      aws ec2 attach-volume 
--volume-id <your-volume-id>
--instance-id <your-instance-id>
--device /dev/sdf
  1. Run the lsblk command on the instance. You will see that the device name has been changed from /dev/sdf to /dev/xvdf:
sh-4.2$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
xvda 202:0 0 8G 0 disk
`-xvda1 202:1 0 8G 0 part /
xvdf 202:80 0 8G 0 disk
  1. On Amazon Linux 2, you can see that /dev/sd* is linked to /dev/xvd*:
sh-4.2$ ls -l /dev/sd*
lrwxrwxrwx 1 root root 4 Jun 17 20:12 /dev/sda -> xvda
lrwxrwxrwx 1 root root 5 Jun 17 20:12 /dev/sda1 -> xvda1
lrwxrwxrwx 1 root root 4 Jun 17 20:15 /dev/sdf -> xvdf

  1. Create a filesystem on the device with the mkfs command. Make sure that you use the correct identifier for the new, unformatted device, as you might corrupt an existing data drive if you get it wrong:
sudo mkfs -t xfs /dev/xvdf
  1. Create a new directory and run the mount command on the instance to mount the volume device:
sudo mkdir /mydata  
sudo mount /dev/xvdf /mydata

After running those commands, the new EC2 volume will be mounted to /mydata and will be available for use.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset