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
- Disk Read/Write operations
- Unmount Additional Volume
- Snapshot of EBS Volume
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
Click on Volumes in Elastic Block store which is present in left sidebar
After getting into volumes Click on Create Volume
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
Successfully volume created now it is available to attach to any instance
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 volume status will be in-use
Making disk usable
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/
Now it is successfully attached and we can use it for read and write operations
Unmount additional volume
# 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/
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
Click on Volumes and select a volume that you want to create a snapshot, go to actions and click on create snapshot
Enter Description and click on Create snapshot
Now go to snapshot section and you can see the list of snapshots
Select the snapshot click on actions and select create volume
Note: here size need to be >= volume size not less than volume
Select availability zone and click on create volume
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)