How to create an EBS Volume

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

How to create an EBS Volume

Using Amazon Elastic Block Store (EBS), you can use block-level storage for your EC2 instances. Any currently running instance of EC2 can attach an EBS volume as primary storage for databases, file systems, or apps that require frequent updates.

Let’s create an EBS volume

  • Log in to AWS Management Console with your credentials and click on ServicesEBS Volume

 

  • You will be taken to the EC2 Dashboard by selecting EC2 from ComputeEBS Volume

 

  • Click on Instances on the left side of the dashboardEBS Volume
  • On the next screen, click the launch instances option

 

  • 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.

  • 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.

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

  • 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

  • Click on Next: Configure Security group
  • Create a new Security Group name as EC2-SG and 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

  • 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 Volume

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
  • You will now see that instances are in a pending state, but wait a few seconds and they will appear to be running

 

EBS volume

  • 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

  • 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)

  • 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

  • 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

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

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

 

  • 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

  • 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)

  • 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 data folder
  • 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 lsEBS 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” 

EBS 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)

  • So to check if mounted or not  Type cat /etc/fstab (press enter) output will show it is mountedEBS Volume
  • 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.

Leave a Reply