EBS volume resizing

Crishantha Nanayakkara
5 min readApr 29, 2020

--

AWS EBS (Elastic Block Storage) is a network drive that you can easily attach to your EC2 instances. You can attach more than one EBS volume to an EC2 instance and even you can resize any of those attached volumes without a downtime of the EC2 instance.

This blog post, will basically explain the important steps that you need to follow when you are doing a volume resize. You may find a few blog posts related to this topic, but there is no blog, which explain all possible scenarios.

Steps

Step 01 : Create an EC2 instance (t2.micro) with two EBS (GP2) volumes (The ROOT volume and a Data volume).

Figure 1

The ROOT volume is 8 GB and Data Volume is 5 GB respectively (See Figure 1 and 2).

Figure 2

Step 02: Check available block devices in the instance now (See Figure 3).

Figure 3

If you analyze above carefully, you can see there are two EBS disk volumes (xvda and xvdb) created. The first volume (xvda) has a disk partition created already but the second volume (xvdb) does not.

P.Note: If you want to get the status of the current disk partitioning, you may execute fdisk -l command (see Figure 4).

Figure 4

Though we can store and retrieve data without partitioning the xvdb volume, it is essential to have a partition table created when you are trying to resize the volume in the future. So lets create a partition table for xvdb to initiate this process.

The above could be further confirmed by executing the file -s command (See Figure 5). The xvdb volume is shown as an empty volume (/dev/svdb: data) here.

Figure 5

Step 03: Create a disk partition table in the Data volume

Figure 6

Make sure to enter “n”, “p” and “w” at respective places in order to create a default partition. You may ignore Partition Number, First Sector and Last Sector fields by just pressing the ENTER key.

Once you create the partition table, you are required to update the Kernel by entering the partprobe command

Figure 7

Meantime, if you check available block devices using lsblk command, you would see both volumes (xvda and xvdb) and their partitions (xvda1 and xvdb1). That means both volumes have their partitions created.

Figure 8

Step 04 : Format the Data volume partition (xvdb1)

Figure 9

Step 05 : Create a mount point (/data folder) on the ROOT volume.

Figure 10

Then create some file(s) in the /data folder.

Figure 11

Step 06 : Mount the Data volume partition to EC2 instance now.

Figure 12

When you execute lsblk command, you would see xvdb1 partition is now mounted to the /data folder.

Step 07 : Update /etc/fstab to automate the mounting process while restarting the EC2 instance.

$ sudo /etc/fstab

Figure 13

Step 08 : Validate the /etc/fstab entry by executing the following.

$ sudo mount -a

If you wish, you can do a restart of the EC2 instance and see both volumes are mounted properly.

Step 09 : Lets resize one of the EBS volumes now.

We have selected the EBS Data volume in this example and its volume size is increased from 5GB to 15GB (See Figure 14).

Figure 14

Once you do the resizing, please run lsblk command again to see the current volume block allocation. You can clearly see the xvdb1 partition size has not been changed.

Figure 15

Step 10 : Increasing the Data volume partition size. You may use growpart command as shown below.

growpart <EBS volume> <partition-number> (See Figure 16).

Figure 16

Now, again we will check Volume block sizes using the lsblk command.

Figure 17

You can see both volume (xvdb) and its partition (xvdb1) are having the same size, which is 15GB.

However, resizing the partition does not mean that you have resized the file system as well. You can confirm this by executing the df -h command.

Figure 18

Step 11 : Resizing the partition file system to 15GB. You may execute resize2fs command as shown below.

Figure 19

Now, again you can recheck the volume file systems using df -h. You will see the data volume file system partition (xvdb1) has been increased to the maximum value, which is 15GB.

Figure 20

Congratulations! You have succeeded resizing an EBS volume, without a downtime.

References

  1. Initializing EBS Volumes: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-initialize.html

--

--

Crishantha Nanayakkara

Enterprise Architect, Consultant @ FAO (UN), Former CTO, ICTA Sri Lanka