Extend disk for Linux Instances on AWS without a reboot


For Linux instances running on AWS, we can resize the EBS volume in use with a guaranteed zero downtime. This comes in handy as most Linux instances are prompted with 8 GB storage as default. When applications running or generating logs for specific use cases, this default storage runs out very quickly. The resizing procedure should not affect any application operation in progress. Below is the step by step guide.

Step: 1 – Resize Boot volume

Log in to AWS console and select your Linux machine. Now follow the below navigation and change the volume size from 8 to 20 GB or whichever value we need.

Scroll down and locate the Root/Block Device/volume info under the Instance description. Now Click on the Volume which generally is denoted by “/dev/xvda”. We can first click and then right-click on the EBS ID to open the specific volume in another tab for easy operations. Now that we have the volume in front of us, click Actions> Select Modify Volume> Edit Required Size in GB> Click Modify. Now we should confirm that we want to grow the disk and we would receive a success message.

Step: 2 – Log in to the Instance via SSH and extend partition.

We should now SSH into our Linux Instance using a tool of preference & keypair and check the below details about our Instance.

Command- df -ht This lists out file system for each volume. For example: We can find both boot and additional volume with an XFS file system. The naming convention /dev/nvme(0-26)n1 means that our volumes are exposed as NVMe block devices.

Command- lsblk This helps us check if our volume has a partition that we must extend. Here we can clearly see that our root volume, /dev/xvda, has a partition, /dev/xvda1. While the size of the volume is 20 GB, the size of the partition is still 8 GB and must be extended.

Command- sudo growpart /dev/xvda 1
or sudo growpart /dev/xvdf 1 Depending on the partition. Notice that there is a space between the device name and the partition number. This command will extend the partition.

Reuse the following commands to verify-
lsblk : partitions reflect the increased volume size
df -h : size of the file system for each volume

Command- sudo xfs_growfs -d /
or sudo xfs_growfs -d /data Depending on the partition. Note that  / and /data are the volume mount points shown in the output for df -h. We can also use the same df -h command again to verify that each file system is reflecting the extended volume size correctly.

Bonus Points-
If our instance does not have XFS tools installed, we can use: sudo yum install xfsprogs
If our volume is ext4, we should use resize2fs command: sudo resize2fs /dev/xvda1

Reference Links- https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/recognize-expanded-volume-linux.html

Leave A Comment

Your email address will not be published. Required fields are marked *