INTRODUCTION
The Elastic Block Storage(EBS) device is a mountable device for the AWS Elastic Compute Cloud for storage of data that are intended to persists beyond the life of the EC2 server.
The Elastic Block Storage could run out of memory due to couple of circumstances. For a production application, this will result to ample down time, especially during continuous deployment and continuous delivery type of architecture.
While it is easy to resize an EBS storage, usually, the file system does not pick the resizing automatically due to it’s complexity. This can be frustrating especially if you are managing your Elastic Block Storage (EBS) device with an infrastructure as a code like Terraform.
The steps below will guild to extend the File System of an Elastic Block Storage (EBS) on an XFS or ext4 device.
Step 1. Check the type of partition that your machine (EC2 server) is using.
Start with checking your file partition hypervisor type.
$aws ec2 describe-instance-types --instance-type instance_type --query "InstanceTypes[].Hypervisor"
Replace the instance_type with your instance type e.g t2.small
$aws ec2 describe-instance-types --instance-type t2.medium --query "InstanceTypes[].Hypervisor"
Step 2. If your hypervisor type is Xen
Check if the volume has partition. The partition is the the volume under the main volume. In this case, the partition is xvda1.$sudo lsblk
Result should look like below:NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
xvda 202:0 0 16G 0 disk
└─xvda1 202:1 0 8G 0 part /
xvdf 202:80 0 24G 0 disk
Check if the partition size is smaller than the volume size, continue to the next step. If the partition size is equal to the volume size, the partition can’t be extended. In my case, the Elastic Block Storage (EBS) partition xvda1
is smaller to the volume size xvda
.
Then, extend the partition you wish to increase. Take note of the number 1
. It is the same number assigned to the partition.$sudo growpart /dev/xvda 1
confirm that the partition worked$sudo lsblk
You should see your partition now extended to the volume size. Once that is done, move to the last step.
Step 2b. If your machine type is nitro
$sudo lsblk
Then extend the File System (FS) size.
$ sudo growpart /dev/nvme0n1 1
replace nvme0n1 with your partition
Verify the partition has been extended$sudo lsblk
NEXT IS TO EXTEND THE FILE SYSTEM
Step 3. IF XEN TYPE
Check the name, and mount and type of the disk file$df -hT
Result:
/dev/root ext4 39G 38G 1.3G 97% /
devtmpfs devtmpfs 2.0G 0 2.0G 0% /dev
tmpfs tmpfs 2.0G 0 2.0G 0% /dev/shm
tmpfs tmpfs 393M 1.1M 392M 1% /run
If the file type is ext4 like above, extend the file system using$sudo resize2fs /dev/root
Where dev/root
mounts to the root / file system
If the file type is xfs, extend the file system using$sudo xfs_growfs -d /
Step 3b. IF NITRO TYPE
You can also extend the Nitro type of Elastic Block Storage (EBS) File System (FS) using a little tweaked process. Get the name, size, type, and mount point for the file system that you need to extend. Use the df -hT command.$sudo df -hT
If ext4, extend the device with$sudo resize2fs /dev/nvme0n1p1
If xfs, extend with$sudo xfs_growfs -d /
Troubleshoot:
If you get a responce like: xfs_growfs: / is not a mounted XFS filesystem.
This means you did not select the correct mount point or the mount is not XFS type. Repeat the step and select the correct mount type.
Now you have extended the filesystem of your Elastic Block Storage (EBS) without causing any downtime in your AWS server or hosted application.
If this post has been helpful, kindly share to your friends and colleague. I’d also love to her from you how you manage your EBS volumes in the comment section.
Leave a Reply