Skip to content

How to create Elastic Block Store (EBS) volume and mount it in an existing AWS instance?

If we have an Instance with an existing Elastic Block Store attached to it and we need additional storage attached to the instance then this post will explain how we can create an EBS volume, mount it to EC2 instance and create a file system in the EBS volume.

Let’s get started, this post assumes that you have an Active and running EC2 instance in AWS environment.

Go to the EC2 Dashboard in AWS environment and select EBS Volumes from the left. 

Here press Create Volume enter the details: 

Volume Type: Select the type of the volume you want to attach, for our demo purposes we are using “General Purpose SSD (gb2).

Size:  Your desired size

IOPS: we are selecting the default

Availability Zone: You can select your appropriate AZ where your Instance is hosted. 

Snapshot ID: we are not loading this from a Snapshot so we will leave it as default. 

Encryption: You can select this option if you have an Encryption requirement for compliance purposes, we are leaving it unchecked by default. 

Tag: We have to assign the name of the volume as per your company’s policy documentation. For our demo purposes, we are simply calling it EBSTestVolume.

Create Volume will create the volume in the allocated AZ. 

Now if you go and list the volumes it will show as available volume and it is not attached to any of the instances. We can attach the volume by right-clicking the volume and click Attach Volume. Select the instance from the AZ where you want to attach the volume and press Attach. (Note all only the instances in the AZ where the Volume is created will be listed)

The Device ID /dev/sdf will be used to identify the raw volume by Linux instance. We should remember we need to create a file system on this to be able to be used. Let see how it looks in from within this instance. 

Connect to your instance and you can list the block storage in the instance by issuing the command: lsblk




We can see the 8Gib block storage containing the file system on top of if that was created when we launched the instance and we have another 10 Gib block raw data block storage that we attached to it earlier which is called “xvdf”.

To check what is the status of the block storage we can issue command ” sudo file -s /dev/xvdf” that will display “data” that means the block store is raw data store and there is no file system in it. To make a xfs file system in the block store we can issue the command “sudo mkfs -t xfs /dev/xvdf” 

Now we have a file system we can mount it to our Linux Instance, for that we can create a folder where we want to mount the device into. To make the folder lets issue the command “sudo mkdir /ebstest”. We are planning to mount Elastic Block Store that we created into the folder “ebstest”.  Then issue the mount command “sudo mount /dev/xvdf /ebstest” to mount it.  Now it is mounted and we can test this by going into the folder “cd /ebstest/” and create a test file by issuing the command “sudo nano test.txt”. 

Now enter the test text in the test file and press ctrl + o to save it and ctrl + x to exit. 

We can test if the file exists in our mount volume by listing the file issuing the ls command “ls -la” and we can see the file that we just created. Let’s further test this to make sure our mount EBS volume and the file we created actually sticks to it even if we reboot the instance. 

Let’s reboot the instance by issuing the command “sudo reboot” then relaunch the instance. 

After the launching of the instance we can check the list of volumes in the instances we can issue “df -k”. In this list we cannot see the volume that we mounted earlier, this is because we didn’t set up to mount the volume at the start-up of the instance. To mount the volume at the startup we have to edit the configuration file. To edit the configuration file to mount the volume at startup we will need UUID of the volume. 

To get UUID of the volume we can issue the command “sudo blkid”, Copy the UUID of the corresponding volume. 

To edit the configuration file issue command “sudo nano /etc /fstab” which is the configuration file that controls all the file systems of the Linux instance. 

We can see there is one UUID already for the default EBS and now we need to create a new line with the new UUID with the folder name eg: “UUID = cc026e2f-30f4-469e-b89b-7d68b39d6a8a  /ebstest xfs defaults,nofail” and press Ctrl + O to save it and exit pressing Ctrl + X. Then issue the command “sudo mount -a” to mount all available volumes and check using “df -k” now we can see the list of mounted volumes. 

If we go to the folder cd /ebstest/ and list it “ls” then we can see the test file that we created in the mounted drive earlier. 

Now the EBS volume is created and is mounted the EBS volume. We can test this further by rebooting the device again. We can go further and test further by detaching from the instance and attaching it to another instance in the same AZ and we can see the text file we created earlier is always present in the EBS volume because EBS volumes are persistent. 

In the end, is you if created a demo or test EBS volume then you can go and detach the EBS volume and delete it if you no longer use it. 



Leave a Reply

Your email address will not be published. Required fields are marked *