Hello my friends,

Today, I had an issue with my current EC2 Linux instance. I deployed the EC2 with EBS backed only, without any EBS data volume. The issue is:

  1. I combined data volume and boot volume into one single EBS.
  2. I will lost data if the boot volume has issue.
  3. Difficult to migrate to larger instance
  4. I have to backup full boot volume and data volume
  5. Not encrypt the data inside.

So, I want to improve a little bit by separating the data in boot and data volume. In this topic, I will share the steps to create new EBS volume, mount it into an existing EC2 and how to make it permanently.

Step 1 – Create an EBS volume under EC2 dashboard.

The default option is 100 GB for the storage. Please make a change to your suitable usage. I changed it into 10GB for my personal usage.

The volume type can be general purpose (gp), Provisioned IOPS (io), Cold HDD, Magnetic, Thruput Optimized HDD (St1)… Depend time, aws can release or discontinue some EBS volume types.

Tip: For hard core, you can use Provisioned IOPS for the EBS. Normally, Provisioned IOPS volume type is used for big database query, heavy workload.

Attention: You have to choose the EBS volume in same available zone with the EC2 linux instance.

Wait a few seconds for the creating process is completed. I recommend that you should do naming the EBS for easy of management.

Step 2 – Attach the created EBS to an existing EC2 linux instance

You still use the EC2 dashboard with Volumes management page (Under Elastic Block Storages).

Click on Action button / Choose Attach Volume / Choose the EC2 linux instance.

Step 3 – Check the new EBS volume

  • Login into EC2 linux instance by ssh
  • Checking command: lsblk (list blocks)
command: lsblk

PS: remember to switch to root account by using sudo -i command.

In this example, you can see 2 attached volumes:

  1. xvdf with 100GB
  2. xvdg with 10GB

I will use svdg 10GB for this demo.

Step 4 – Format the EBS volume with ext4 type

Command: mkfs -t ext4 /dev/xvdg

mkfs linux command

Step 5 – Mount the new EBS to EC2 linux instance

Command: mount /dev/xvdg /data

You have created the mount point /data in advance. It depends your needs.

mount command and df command

You also can use df command for checking the new mount point /data

Step 6 – Setup an automount after reboot.

As default, all mounted points will be released after rebooting. If you can to keep it as permanent, you need an additional steps to make this happen.

We will use fstab config file to satisfy this requirement.

  1. Backup the fstab file before making the changes. Command: cp /etc/fstab /etc/fstab.bk
  2. Open fstab configuration. Command: vi /etc/fstab
  3. Add an auto-mount configuration. Command: /dev/xvdg /data ext4 0 0
  4. Test the new configure: Command: mount -a

For action #3, the syntax is: source_physical_ebs_mount_point destination_logical_point_ec2 file_type fs_freq fs_passno