How to Get Around the 8GB Limit on Root Volumes in AWS?

When an AWS Elastic Cloud Compute (ECC) instance is first launched its root volume is sized by the Amazon Machine Images (AMI’s) backing snapshot. An Amazon Linux AMI creates an 8GB root volume. At launch, the root volume size can only be increased, not decreased. Some AMIs have even larger backing snapshots—creating waste. And waste comes with a cost. EBS volumes are paid GB-month regardless if the space is used.

There’s no reason to over-provision disk space in a cloud environment. Follow these steps to increase EBS volume size online.

  1. Go to AWS EC2 console, right click the EBS volume and select Modify Volume, increase the Size, and click Modify.
  2. Log on to the EC2 instance, use the growpart command to grow the partition to fill the available space.
growpart /dev/xvda 1

3. Use the ‘resize2fs command to resize the file system to fill the available partition space.

resize2fs /dev/xvda1

Unfortunately, it is still very difficult to decrease a root EBS volume size, and it can only be done offline. Here’s how to shrink an Amazon Linux EC2 root volume size from 8GB to 4GB:

  1. Stop the target EC2 instance.
  2. Snapshot the root EBS volume.
  3. Create an EBS volume from the snapshot. This will be the source EBS volume.
  4. Launch a new EC2 worker instance in the same region as the target instance.
  5. Attach the source EBS volume to the worker instance as xvdf.
  6. Create a new target EBS volume of smaller size 4GB. The size needs to be at least slightly larger than the actual filesystem used size.
  7. Attach the new target EBS volume to the worker instance as xvdg.
  8. Check file system on the source EBS volume. This is required to do the resize2fs.
e2fsck -p -f /dev/xvdf1

9. Shrink the file system to the minimal size.

resize2fs -M /dev/xvdf1

10. Get the newly shrunk file system’s total number of blocks.

NEW_FS_BLOCK_COUNT=`tune2fs -l /dev/xvdf1 | grep "Block count:" | awk '{print $3}'`
NEW_FS_BLOCK_SIZE=`tune2fs -l /dev/xvdf1| grep "Block size:" | awk '{print $3}'`
NEW_FS_SECTOR_COUNT=$((NEW_FS_BLOCK_COUNT*NEW_FS_BLOCK_SIZE/512))

11. Copy the entire newly shrunk file system disk blocks from source to the new target EBS volume.

DD_BS_1M=$((1<<20))
DD_COUNT=$((NEW_FS_SECTOR_COUNT*512/DD_BS_1M+1))
dd if=/dev/xvdf of=/dev/xvdg bs=1M count=${DD_COUNT}

12. Re-partition new target EBS volume to cover all usable space.

a. Delete partition 1.

sgdisk -d 1 /dev/xvdg

b. Get the last usable disk sector.

NEW_DISK_LAST_USABLE_SECTOR=`sgdisk -p /dev/xvdg | grep " last usable sector is " | awk '{print $10}'`

c. Recreate partition 1 to cover all usable space.

sgdisk -n 1:4096:${NEW_DISK_LAST_USABLE_SECTOR} /dev/xvdg

13. Grow file system on the new target EBS volume to fill the new partition space.

resize2fs /dev/xvdg1

14. Stop the worker instance.

15. Detach the new target EBS volume xvdg from the worker instance.

16. Detach the source EBS volume xvdf from the worker instance.

17. Attach the new target EBS volume to the target EC2 instance as xvda.

18. Start the target EC2 instance.

Even though we can reduce the root EBS volume size to a better fit size to save costs the process is complex and error-prone. Apptio helps users cut cost by reducing EBS root volume size with a click of a mouse from our SaaS web user interface.

Editor’s note: This post was originally published on the now retired FittedCloud blog (January 2018).

Download 4 steps to successfully monitor and optimize hybrid IT

A hybrid IT approach offers the best of both on-premises and public cloud by keeping costs and risk low while increasing efficiency and speed. But monitoring and optimizing hybrid environments is complicated.

 

Apptio® Cloudability provides cost and resource optimization capabilities across all leading public cloud providers (AWS, Azure and Google Cloud) so IT leaders can increase the efficiency of public cloud spending and slash waste from over-purchase and underuse.

Try Apptio Cloudability for free

Article Contents

Categories

Tags

Additional Resources