Hi! In this journal I want to discuss about EBS services on AWS. EBS or Elastic Block Storage is a storage service on AWS that is at the block level, which is like raw and unformated-devices. We can create a volume on EBS, attach it to an EC2 instance, partition and format it, then mount it to a folder so that it can be used to store data, for example mount to /data. EBS volumes are long-term, which means that data on EBS will not be deleted as long as the volume is still there. We can detach / detach a volume from one EC2 instance and then attach the volume to another EC2. For more details about the features of EBS, it will be explained in a separate journal! here we will try the handon EBS in a simple way. Let’s try. There are several ways that we can take to create an EBS volume. The first is when creating an instance, especially when a display like the following appears.
We can add an EBS volume by clicking Add New Volume. Set it to what device, for example /dev/vdb, specify the size, type, and can directly Next. The EBS volume will be created with the EC2 instance and the volume will be directly attached to the instance.
We can verify the EBS volume in the details of the instance, the Storage tab as follows.
In addition to using the above method, we can create an EBS volume through the Elastic Block Storage menu. Click the Volumes section and to create a new volume, click Create Volume.
We specify the type, size, AZ (adjust to the AZ location of the EC2 instance), we can add keys, tags, and if it’s OK we can click Create Volume.
When successfully created, a notification like the following will appear.
And if you look at the EBS dashboard, a new volume will appear with the status available, which means the volume has not been attached to any instance.
To attach a volume to an instance, select the volume, click Action > Attach Volume
Select the instance and device that is the target volume, for example /dev/vdc then click Attach.
Can be verified on the dashboard. It looks like the status has changed to in-use.
We can verify from within the instance too. You can use the lsblk command and as shown in the image below, there is a new disk named xvdb (the first EBS volume created with the instance), and xvdc (the second EBS volume created from the EBS dashboard).
Before using the volume, you can partition for example with the fdisk command.
And format the partition, for example below the partition is formatted using the xfs file system and mounted to the /data folder
lsblk mkfs.xfs /dev/xvdc1 mkdir /data mount /dev/xvdc1 /data/ lsblk df -hT
Until this step, the volume is ready to use. We can save data in the /data/ folder and the data will go to the EBS volume.
To detach/detach a volume from an instance, make sure the disk is not mounted first. Use the umount /folder command for unmounting.
Then return to the EBS dashboard, click the volume you want to remove, Action > Dettach Volume
There will be a pop-up to confirm and we can click Yes, Detach.
The status of the volume will change back to available.
To delete a volume, select a volume, Action > Delete Volume
And a conformation pop-up will appear, and click Yes, Delete
Then the volume will be deleted and disappear from the EBS dashboard.
Note: Be careful when you want to delete the volume, because the data in the volume will also be deleted.