How to create an EBS Volume?

  • Post category:Solutions
  • Reading time:18 mins read

“One of the most powerful features of Amazon EC2 is the ability to attach storage volumes to instances. EBS volume acts like any other disk that one might install in a physical server, and they can be used for many purposes: file storage, databases, or even swap space.”

What is AWS EBS Volume?

An Amazon EBS volume is storage that persists independently from an instance’s life cycle. An Amazon EBS volume does not have any single point of failure, and with its flexible volumes, you can launch as many instances using the same volume as you need.

Amazon Elastic Block Store (EBS) provides block-level storage volumes for use with EC2 instances in Amazon Web Services. EBS allows users to connect virtual devices (volumes) to a network that is available only when your system or instance is running. This makes it possible to configure systems or servers, save data on them reliably, and keep the configuration even if the server has been stopped for any reason.

You can attach an EBS volume to one EC2 instance. Then you can use it as a normal hard drive or partition. You can format the file system on it, store data on it, and delete volumes when they are no longer needed.

EBS volume is designed to provide very high throughput and IOPS (Input/output operations per second) which scales automatically depending upon the size of your volume.

Amazon EBS volume allows users to snapshot their volume. A Snapshot contains all blocks currently in use by a particular volume at a given point in time and saves that information into Amazon S3 storage which you can later use to restore the volume’s state and contents during your maintenance window.

Let’s create an EBS volume

EBS Volume

  • You will be taken to the EC2 Dashboard by selecting EC2 from Compute.

ebs volume types

  • Click on Instances on the left side of the dashboard

ebs types

  • On the next screen, click the launch instances option

ebs performance

  • Select the Amazon Machine Image (AMI) option.
  • Instances in the cloud are based on Amazon Machine Images (AMIs), which contain all the information necessary for their launch.
  • Amazon Linux 2 AMI is eligible for the Free tier and you will not incur any charges on your AWS account if you choose this.

ec2 volume

  • Now we need to select the instance type. The default selection is t2.micro, and since that’s within the free tier, we will move forward with it.

ebs volume

  • Click on Next: Configure Instance Details
  • Increase the number of instances to 2

types of ebs

  • Click on Next: Add Storage, and all the settings will stay the same
  • Click on Next: Add Tags without adding storage.

EBS Volume

  • As shown in the following picture, we will name it

ebs volume types

  • Click on Next: Configure Security group
  • Create a new Security Group name as EC2-SG  keep the description as same and then click on Add rule, from the list select HTTP and select the sources as Anywhere for both SSH and HTTP
  • Click on Review and Launch

ebs types

  • After Reviewing click on Launch 
  • During the next step, you will be asked whether to create a new key pair or use a previously created key pair
  • Here we will create a new key pair. Click on Create a new key pair and give it a name as EC2-key and then click on Download key pair
  • After clicking on the Download key pair click on Launch instances

ebs performance

Note: Please remember to download the key pair before launching the instance. Once the instance is running you will not be able to download the key pair.

  • Click on View Instances

ec2 volume

  • You will now see that instances are in a pending state, but wait a few seconds and they will appear to be running

ebs volumes

  • Click Volumes in the left-hand panel. Because you’ve created 2 EC2 instances, you’ll find 2 root volumes over there, each attached to an instance. All are of 8GB

 

types of ebs

EBS Volume

  • Click on Create volume, which will then be attached to a specific instance. Verify that the volume you are creating is in the same Availability Zone (AZ) as the instances (go to the EC2 instances you’ve launched and check)
  •  Leave the volume type as General Purpose SSD and enter the size as 10GB (demo purpose)

ebs volume types

 

  • Add tags and give it a name of your choice. {So this is going to be the data volume where we will store data} 
  • Click on Create volume
  • Since there is no EC2 instance attached to the volume, it will display as Available mode.

ebs types

 

  • Select the volume, click Actions, and then select Attach Volume
  • When it asks you to select an instance, just pick the instance of your choice [but remember, if you created the volume in a different AZ, then you won’t be able to choose any instance}. 
  • When you select the instance and click Attach, the volume will be shown as in-use

 ebs performance

 ec2 volume

  • Once again, select Instance-1 from Instances and click Connect

ebs volumes

  • Your Amazon login will have the username ec2-user and will display the instance-id and IP address of the instance
  • Click on Connect

types of ebs

  • The first thing you will see after you log in is a black window with your username as ec2-user.

EBS Volume

  • Now we’ll use some Linux commands here and you should enter the commands carefully because Linux is case-sensitive.
  • Type “lsblk“(press enter) and you will get “xvdf” as the disk name.

ebs volume types

  • To mount it, we must first access it
  • Type sudo file -s /dev/xvdf (press enter)
  • This output will give us data that means there is no file system on the device and we have to create one. So, for this, we will use another command
  • Type sudo mkfs -t ext4 /dev/xvdf (press enter) (ext4 is for formatting)

ebs performance

  • Type sudo mkdir /data (press enter)
  • “data folder is created” and it will show as “xvdf/data”
  • Now to mount it
  • Type sudo mount /dev/xvdf /data (press enter) 
  • To confirm type “lsblk” and press enter and you will see “xvdf” is mounted to the data folder.

ec2 volume

  • Go to data folder by typing “cd /data
  • Now we will make a file
  • Type sudo touch Hello.txt (press enter)
  • To confirm it is created or not type “sudo ls

EBS Volume

  • Now to edit that file type we will use VI editor here
  • Type sudo vi Hello.txt (press enter)
  • Editing mode is enabled now, Press “i” for inserting the command and {move your cursor below the UUID path given there}
  • Type “hello world” and press escape (ESc key) and then type ” :w ” (press enter) and then type ” :q! ” (press enter and you will be out of the editor)
  • To check if hello world is there
  • Type cat Hello.txt (press enter) output will show “hello world” 

ec2 volume

  • Now we will add entry and mount our file to the specified mount point
  • Type sudo vi  /etc/fstab
  • Again press “i” for insert mode and {move your cursor below the UUID path given there}
  • Type /dev/xvdf /data ext4 defaults,nofail  0  2 {remember there is double space after nofail and also after 0} (press enter)
  • Press escape (ESc Key) and then type ” :w ” (press enter) then type ” :q! ” (press enter and you will be out of the editor)

ebs volumes

  • So to check if mounted or not  Type cat /etc/fstab (press enter) output will show it is mounted

ebs performance

 

  • To verify the file system is formatted or not
  • Type sudo file -s /dev/xvdf
  • Now to unmount the data firstly come out of the folder by using cd ../
  • Type sudo umount /data (remember command is “umount” not unmount)
  • To confirm type “lsblk” and you will see that it is unmounted
  • Now we will test our fstab file
  • Type sudo mount -a (press enter)
  • To confirm type “lsblk” and press enter and output will show that data has become the specified mount point

Congratulations!! You have created and Formated an EBS volume. See you in the next Lab.

Conclusion:

After reading this blog post, you should now know how to create an EBS volume and be able to do so in the AWS console. We also provided a step-by-step guide for accomplishing this task with Terraform. If anything is unclear or if you want more information on any of these topics, please don’t hesitate to reach out! Our team is always happy to help our customers succeed. In addition, we offer training courses and Blogs designed specifically for AWS users like yourself. Check them out here Thinkcloudly.com.



Interview Prepration Quiz

Category : Quiz
AWS Database Interview Questions | Elastic Load Balancer Interview Questions | Auto Scaling Group Interview Questions | Basics of Cloud Interview Questions | IAM Interview Questions | Introduction to Cloud Computing Interview Questions | Azure Services Interview Questions | Basic ure Concepts Interview Questions | Azure Storage Interview Questions | Management Tools on Azure Interview Questions | Introduction to Comput Networking Interview Questions | Authentication and Authorization Interview Questions | Elastic Block Storge Interview Questions | Elastic File System Interview Questions | S3 Interview Questions | Simple Queue Service Interview Questions

Leave a Reply