DEV Community

Ramu Ummadishetty
Ramu Ummadishetty

Posted on • Updated on

EBS-Elastic Block Store, Creating Additional Volume,Snapshots

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

Step1
First you need to have running instance to attach a volume to it
If you don't have running instance please check this

to create EC2 instance

Alt Text
Click on Volumes in Elastic Block store which is present in left sidebar
Alt Text

Alt Text

After getting into volumes Click on Create Volume
Alt Text

Alt Text

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

Successfully volume created now it is available to attach to any instance
Alt Text

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

Alt Text

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

Alt Text

Now volume status will be in-use
Alt Text

Making disk usable

Now connect to your instance using ssh and execute following cmd

# sudo fdisk -l
Enter fullscreen mode Exit fullscreen mode

you can see
Disk /dev/xvda - root volume
Disk /dev/xvdf - additional volume

Alt Text

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
Enter fullscreen mode Exit fullscreen mode
# mkdir myfolder
# sudo mount /dev/xvdf myfolder/
Enter fullscreen mode Exit fullscreen mode

Alt Text

Now it is successfully attached and we can use it for read and write operations
Alt Text

Unmount additional volume

# umount myfolder/
Enter fullscreen mode Exit fullscreen mode

Don't detach additional volume directly from EBS please unmount it in specific instance

you can cross-check again
Alt Text

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

Alt Text

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

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/
Enter fullscreen mode Exit fullscreen mode

Snapshot of EBS volume

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
Click on Volumes and select a volume that you want to create a snapshot, go to actions and click on create snapshot
Alt Text
Enter Description and click on Create snapshot
Alt Text
Now go to snapshot section and you can see the list of snapshots
Alt Text
Select the snapshot click on actions and select create volume
Alt Text

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

Alt Text
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

Top comments (0)