How to create EBS volume and attach and mount to amazon linux EC2

How to create EBS volume and attach and mount to amazon linux EC2

ยท

2 min read

Amazon EBS (Elastic Block Store) provides persistent block storage for using with Amazon instances. Each Amazon EBS volume offering high availability and durability. It has capability to automatically replicate in its Availability Zone to protect you from component failure.

Step 1: Create an EC2 instance using configure storage

using the default gp3 EBS volume type storage for our EC2 machine

Step 2: Create an EBS Volume

First we need to login to AWS EC2 dashboard. After login navigate to following location and create an EBS volumes of preferred size. Below screenshots will provide you help about this.

  • AWS Account >> EC2 Dashboard >> Volumes >> create volume

  • Note that the EBS volume and the EC2 instance should be in the same availability zone.

Here i have created one EBS volume named as Demo-EBS-volume which is type gp3 having size 5gb and the other one is my Root Volume which is attached to my EC2 instance.

Before attach EBS Volume the volume status is available.

Now, we can see a new volume not listed your system because it is not attached. You can check this using lsblk command.

Step 3: Attach EBS Volume

As you have created an EBS volume in your account, lets attach this in your instance of your choice. Follow below navigation option to find the options.

  • Select New Volume >> Actions Menu >> Select Attach Volume

After attached EBS Volume the volume status is In-use

Step 4: Mount EBS Volume in Server

After completing above step, Now new volume will list your system. we able to see the named xvdf type disk using lsblk command.

Now use following command to create new filesystem to newly attached EBS volume, Run below command with care and make sure you are formatting right volume.

$ mkfs /dev/xvdf

After creating filesystem, Lets mount this disk on your mount point using following command.

  1. I create a directory using mkdir command.

  2. mount /dev/xvdf /<name of the directory>

For Unmounting

Go to the volume that you have attached previously, from the console, use the option detach volume to detach the EBS volume from the EC2 instance

After Detach volume, it is not showing listed

Thanks For Reading! :)

ย