EBS-Elastic Block Store, Creating Additional Volume,Snapshots
Tags: aws, tutorial, devops, cloud
Published: 2021-06-28 14:54:28

EBS is a **storage volume** for an EC2 instance.

By default while creating EC2 instance root volume is used 
EBS is something like hard disk

Root volumes are set to deleted when instance is terminated.
In this case we can use additional volumes which can be attached and detached at any time from the instance and it is not deleted by default when instance is deleted
Additional volumes can be attached to running instance in same availability zone
Table Of Contents
 * [Creating Additional Volume for instance](#chapter-1)
 * [Disk Read/Write operations](#chapter-2)
 * [Unmount Additional Volume](#chapter-3)
 * [Snapshot of EBS  Volume](#chapter-4)

### Creating additional volume <a name="chapter-1"></a>

**Step1**
First you need to have running instance to attach a volume to it
If you don't have running instance please check this {% link https://dev.to/ramushetty/aws-creating-an-ec2-instance-29fl %} to create EC2 instance

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/toq89gpck0mxprcf5fqe.png)
Click on Volumes in Elastic Block store which is present in left sidebar
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/csqcuzrbx2ld4j1osh2d.png)

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/42aji8mrc8vqevvpewv0.png)

After getting into volumes Click on **Create Volume**
 ![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qjm3a8ufy6xcbb9iu8mt.png)

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lqyc9ft593s20q8hzn0y.png)

Make sure you select the current available zone of which your instance is running.Select the additional volume size
Add tag nothing but your additional volume name and then click on create volume

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/27chvlmhwyrpwqed1p7q.png)

Successfully volume created now it is available to attach to any instance
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lioayoacru0145qrmeu8.png)

Now select additional volume and click on attach then select Attach Volume

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lw6no1d3x3ryg93jqgvb.png)

Select the instance that you want to attach and click on attach 

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hpg1g4amzemfz0vypq9p.png)

Now volume status will be in-use
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mldmk05nacspv5qzjqiv.png)
### Making disk usable <a name="chapter-2"></a>
Now connect to your instance using ssh and execute following cmd

```
# sudo fdisk -l
```
you can see 
Disk /dev/xvda - root volume
Disk /dev/xvdf - additional volume

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ybnrmkisxu51t0glhvcj.png)

Its not enough that attaching a volume doesn't make that additional volume usable.
It just like new pen drive we need to format and mount it

```
# sudo mkfs.ext4 /dev/xvdf
``` 
```
# mkdir myfolder
# sudo mount /dev/xvdf myfolder/
```

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bklrwm0izri5tr6fol1g.png)

Now it is successfully attached and we can use it for read and write operations
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/b13avf9f088g7otqqcwl.png)
### Unmount  additional volume <a name="chapter-3"></a>

```
# umount myfolder/
```
Don't detach additional volume directly from EBS please unmount it in specific instance

you can cross-check again 
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fxv13i54z08k9o0g4hv3.png)

Now go to the EBS volumes tab and select additional volume and detach it 

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/18ftyefideifq6p7gmvj.png)

Now the detached volume will be available for use and data created in it will be also persisted and we can also attach it to another running instance 

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/eid15qm5z4th05xfvjdr.png)

Note: Please don't use this below cmd if you want data to be persisted while attaching the volume to another instance 
```sudo mkfs.ext4 /dev/xvdf```
If you use the above cmd again means data will be erased 
use the above cmd only when it is new volume

just use below cmds and mount the additional volume in any instance
```
# mkdir myfolder
# sudo mount /dev/xvdf myfolder/
```
### Snapshot of EBS volume <a name="chapter-4"></a>
Note: Your created additional volume can be used only for one instance at a time and can not be used for multiple instances parallel

When you want to share one volume data to multiple instance then create a snapshot of that volume and create another new volume using that snapshot as template

Here snapshot is nothing but "image" of am EBS volume, which can be used as backup of volume or used to create a duplicate.
You need to be clear that snapshot can not be attached and detached to an EC2 instance it is not an active EBS volume
But, one can create EBS volume using this snapshot

**Creating snapshot**

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zlkijl9pvi79m794r3up.png)
Click on Volumes and select a volume that you want to  create a snapshot, go to  actions and click on create snapshot
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0nn6bsn9490nt0mbf5au.png)
Enter Description and click on Create snapshot
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8bocmzzd0pb89ptv6ric.png)
Now go to snapshot section and you can see the list of snapshots 
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/addpx6pkxqdaze9avd1u.png)
Select the snapshot click on actions and select create volume
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f2ozgw0n486x3llx3qsb.png)

Note: here size need to be >= volume size not less than volume
Select availability zone and click on create volume

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7a672nfu60iziasres7i.png)
Go to Volumes you find new volume created you use add tag for specifying names to volumes while creating it or else you can also edit directly on double click on Name of volume

As it is not new volumes you can directly mount it to any instance with out formatting it