How to Create/Remove EBS Volume Using AWS Web-console/CLI

Create/Remove an EBS Volume using the AWS Web-console

1) Open the EC2 Instance and check the Instance ID.

After Login on the AWS Web-console, Go to Service –> EC2 –>choose Instances, refer below screen shot.

2) Create the AWS EBS Volume.

On the left side the navigation pane, select Volumes option and then click on the create volume option, Refer below screen-shot.

Now we have to select various option’s while the creating the EBS volume like; Volume type, Size, Availability zone, Snapshot ID.

Note: For Availability Zone, choose the Availability Zone in which to create the volume. EBS volumes can only be attached to EC2 instances within the same Availability Zone.

Select additional tags to add tags to the EBS volume, then select “create volume” option.

Once the volume successfully created, it will show the Volume ID (vol-07b903704b503376e in our case), then select click on “close” button. The status for state is “available”(Blue Colour).

3) Attach the EBS volume with AWS EC2 Instance.

After Creating the EBS Volume, Then Select volume and click on Actions –> Attach Volume, refer below screen-shot.

On the Attach Volume window, Put the Instance ID on Instance box for attach the volume to the Instance, then mention suggested device name.

Now you can check the status for state is “in-use”(Green Colour), refer below screen shot.

Check on EC2 Instance the EBS volume is attached or not, using below commands..

4) De-attach the EBS Volume from an Instance.

Before any De-attaching the EBS Volume from any EC2 Instance, first we must unmount the volume from the EC2 Instance, if that instance is running, use the following command to umount the volume.

#umount <Device/remote Filesystem>

Then Go to Actions –> click on “Detach Volume”, refer below screen-shot.

Once you click on Detach Volume, then it will ask for the confirmation. Click on the “Yes,Detach” option.

Once you Detach the volume the state has been changed to “available”.

Create an EBS volume using the CLI (Command Line)

As previous we have learnt about how to accessing the command line interface of AWS, refer the link.

Install and Configure AWS Command Line Interface (CLI)

1)  Create an EBS Volume using CLI.

We are using “create-volume” command to create the volume. As below command will creates an 5 GiB General Purpose (SSD) volume in the Availability Zone ap-east-1a with “ITT_BackVolume_CLI” tag Name.
Note: The EBS volume that can be attached to an instance in the same Availability Zone.

$ aws ec2 create-volume --size 5 --region ap-south-1 --availability-zone ap-south-1a --volume-type gp2 --tag-specifications 'ResourceType=volume,Tags=[{Key=Name,Value=ITT_BackupVolume_CLI}]'
{
    "AvailabilityZone": "ap-south-1a", 
    "Tags": [
        {
            "Value": "ITT_BackupVolume_CLI", 
            "Key": "Name"
        }
    ], 
    "Encrypted": false, 
    "VolumeType": "gp2", 
    "VolumeId": "vol-0066b73396798b333", 
    "State": "creating", 
    "Iops": 100, 
    "SnapshotId": "", 
    "CreateTime": "2017-10-23T07:22:39.132Z", 
    "Size": 5
}
$

2) Attach an EBS Volume with to EC2 Instance using CLI.

Using “attach-volume” command we can attach an EBS volume to a running (or stopped instance). Following command will attaches a volume (vol-0066b73396798b333) to an instance (i-086cd7398eb817d5f) as /dev/sdf.

$ aws ec2 attach-volume --volume-id vol-0066b73396798b333 --instance-id i-086cd7398eb817d5f --device /dev/sdf
{
    "AttachTime": "2017-10-23T07:44:59.660Z", 
    "InstanceId": "i-086cd7398eb817d5f", 
    "VolumeId": "vol-0066b73396798b333", 
    "State": "attaching", 
    "Device": "/dev/sdf"
}

Now using following command you can check the Description all of your volumes in the default region.

$ aws ec2 describe-volumes
{
    "Volumes": [
        {
            "AvailabilityZone": "ap-south-1a", 
            "Attachments": [
                {
                    "AttachTime": "2017-10-23T06:29:03.000Z", 
                    "InstanceId": "i-086cd7398eb817d5f", 
                    "VolumeId": "vol-0f33fe26b15637787", 
                    "State": "attached", 
                    "DeleteOnTermination": true, 
                    "Device": "/dev/xvda"
                }
            ], 
            "Tags": [
                {
                    "Value": "ITT_OriginalVolume", 
                    "Key": "Name"
                }
            ], 
            "Encrypted": false, 
            "VolumeType": "gp2", 
            "VolumeId": "vol-0f33fe26b15637787", 
            "State": "in-use", 
            "Iops": 100, 
            "SnapshotId": "snap-00f9cc4c608053854", 
            "CreateTime": "2017-10-23T06:29:03.343Z", 
            "Size": 8
        }, 
        {
            "AvailabilityZone": "ap-south-1a", 
            "Attachments": [
                {
                    "AttachTime": "2017-10-23T07:44:59.000Z", 
                    "InstanceId": "i-086cd7398eb817d5f", 
                    "VolumeId": "vol-0066b73396798b333", 
                    "State": "attached", 
                    "DeleteOnTermination": false, 
                    "Device": "/dev/sdf"
                }
            ], 
            "Tags": [
                {
                    "Value": "ITT_BackupVolume_CLI", 
                    "Key": "Name"
                }
            ], 
            "Encrypted": false, 
            "VolumeType": "gp2", 
            "VolumeId": "vol-0066b73396798b333", 
            "State": "in-use", 
            "Iops": 100, 
            "SnapshotId": "", 
            "CreateTime": "2017-10-23T07:22:39.132Z", 
            "Size": 5
        }
    ]
}

3) Detach the EBS Volume from an instance using CLI.

Before any De-attaching the EBS Volume from any EC2 Instance, first we must unmount the volume from the EC2 Instance, if that instance is running, use the following command to umount the volume.

#umount <Device/remote Filesystem>

Then using “detach-volume” command you can detach an EBS volume from an instance.

$ aws ec2 detach-volume --volume-id vol-0066b73396798b333
{
    "AttachTime": "2017-10-23T07:44:59.000Z", 
    "InstanceId": "i-086cd7398eb817d5f", 
    "VolumeId": "vol-0066b73396798b333", 
    "State": "detaching", 
    "Device": "/dev/sdf"
}
$

4) Delete the EBS volume using CLI.

Using delete-volume command we can deletes an available volume. If the command succeeds, no output is returned.

$ aws ec2 delete-volume --volume-id vol-0066b73396798b333

Hope this post will help Linux/Unix beginners. Please share you feedback and Comments. Stay tune for more updates with ittroubleshooter.in …!!!

Leave a Reply

Be the First to Comment!

Notify of
avatar
wpDiscuz