Home Cloud How to Mount the EBS volume to EC2 Ubuntu Instance via CLI

How to Mount the EBS volume to EC2 Ubuntu Instance via CLI

85
2
SHARE

In this post, we will learn about how to mount your EBS volume to your EC2 instance via Ubuntu Command Line. Before that it is important to learn something more about EBS volume.

To get information about EBS volume you can view descriptive information for it at a time in your AWS Management Console. You can also view its detailed information including the size, volume type, whether it is encrypted or not, to which instance it is attached etc.

To view information about EBS volumes via Console:

  • Open up the Amazon EC2 Console
  • Choose Volumes from the navigation pane
  • Select the volume you want to get information about

To view about EBS volumes via CLI:

These volumes provide you with several benefits which is not supported by instance store volumes:

  • Data Persistence
  • Data Availability
  • Data Encryption
  • Snapshots

There are various EBS volume types which differ in their performance and prices so that you can use them according to your need and your application’s need. I will be covering those volume types in the further post. Now, follow the steps to attach your volume to your EC2 instance.

An additional security feature of elastic volume is EBS Encryption which is used to encrypt data on the ebs volume. It is benefited in a way that a person who has the access to the key pair which was used for the encryption, can read that data. To be able to use this feature, you will go through the Amazon Management Console to select the data to be encrypted and mention the key pair is to do the encryption. The moment you encrypt the ebs volume and attach it to an instance type, the data on the volume and the snapshots created from the volume will all be encrypted.

Making an Amazon EBS Volume Available for Use

After you attach an Amazon EBS volume to your instance, it is used as a block device. Before mounting you can format up the volume within any file system. After you make the EBS volume available for use, you can access it in the same ways as you access any other volume.

To mount an EBS volume to your instance via CLI

  • Connect to your instance using SSH.
  • Use the lsblk command to view your available disk devices and their mount points to determine the correct device name to use
$ lsblk

ebs

  • This step assumes that you are mounting an empty volume. If you are mounting a volume that already has data on it, don’t use mkfs command it will format everything in the volume.
$ sudo mkfs -t ext4 /dev/xvdf
  • Create a mount point directory for the volume using the following command.
$ sudo mkdir /mnt
  • Mount the volume you created using the following command.
$ sudo mount /dev/xvdf /mnt
  • With the following command make it mount automatically on system start.
$ sudo vim /etc/fstab

and add this:

/dev/xvdf       /mnt1   auto    defaults,nobootwait     0       0

Now, the volume has been mounted.

2 COMMENTS

LEAVE A REPLY

Please enter your comment!
Please enter your name here

five × 5 =