How to create and attach EBS volume to Linux EC2 Instance

Steps:

  1. Create EBS Volume
  2. Attach volume to EC2 Instance
  3. Create file system on the new volume
  4. Create mount point
  5. Mount the new volume
  6. Add entry to fstab

Login to the AWS Management console and open EC2 service. Choose the instance that you need to add EBS volume to and copy the instance ID. Also, make note of the Availability Zone that the EC2 instance is running in.

Choose Volumes under ELASTIC BLOCK STORE and paste the Instance ID in search bar and hit enter. You will see a list of all the volumes currently attached to the Instance. Choose Create Volume

In the next screen, choose the Volume Type and type in the size of the EBS volume. Choose the same availability zone as the instance and choose Create Volume. You may also optionally add a name tag to the EBS volume.

You will see the below confirmation message after successful creation of volume. Click on the Volume ID.

Right click on the volume and choose Attach Volume.

On the next screen, select the instance that you would like to attach the volume to and choose Attach.

SSH into the EC2 Instance and type lsblk command as root to list all the block devices. You will see the newly added device in the list.

Verify if there is a file system on the device. Since I created a new volume (not form a snapshot) there is no file system on the volume.

Below image shows that the xvdg volume is currently not mounted.

Create file system on the volume with the command mkfs -t xfs /dev/xvdg where xfs is the type of file system and /dev/xvdg is the device.

See also  How to drop a materialized view in Redshift database

Create a mount point /u02 with command mkdir /u02 and mount the volume with command mount /dev/xvdg /u02

Run df -h and lsblk commands to view the device and mount points.

For the device to be mounted after system reboot, uuid of the device should be added to /etc/fstab file. Find uuid of the volume using command blkid and copy the uuid. Add an entry for the new device to the file /etc/fstab as shown below.