15
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
Step1
First you need to have running instance to attach a volume to it
If you don't have running instance please check this
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
Now select additional volume and click on attach then select Attach Volume
Select the instance that you want to attach and click on attach
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
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/
# umount myfolder/
Don't detach additional volume directly from EBS please unmount it in specific instance
Now go to the EBS volumes tab and select additional volume and detach it
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
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/
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
Note: here size need to be >= volume size not less than volume
Select availability zone and click on create volume
As it is not new volumes you can directly mount it to any instance with out formatting it
15