Resize your EC2 instance’s Root EBS volume on AWS

Resize your EC2 instance’s Root EBS volume on AWS with these simplified steps. Unlike expanding, shrinking isn’t as straightforward. Follow this guide for a quicker understanding:

(𝗧𝗵𝗶𝘀 𝘁𝘂𝘁𝗼𝗿𝗶𝗮𝗹 𝗶𝘀 𝗳𝗼𝗿 𝗘𝗫𝗧𝟰 𝗳𝗶𝗹𝗲-𝘀𝘆𝘀𝘁𝗲𝗺𝘀)

Let’s say we have a 500 GB root disk that we want to shrink to 100 GB.

Let’s also assume that this 500 GB was used as a root instance for an instance that was launched using the Debian 12 AMI.

I will be referring to the original 500 GB disk as the source disk and the new 100 GB disk as the destination disk.

Here are the steps I did to shrink an EBS volume:

1. Power off the original EC2 instance.

2. Snapshot the source disk for safety.

3. Create a new instance where we will be migrating the data from the source disk to the destination disk. We will be calling this instance the “workstation”.

Make sure this instance is launched using an AMI that anything except the AMI used to launch your root disk. In our case, we can use any AMI other than Debian 12.

( The reason for this is to avoid duplicate disk UUID’s when we attach the source disk ).

4. Launch a new instance with the same AMI as the source EBS volume (Debian 12 AMI in our case).

Ensure the root disk size matches the desired destination disk size (e.g., 100 GB).

After creation, shut down and detach this instance, preserving correct disk UUID, label, and boot files for seamless source and destination disk replacement.

5. Attach the source disk to the “workstation” instance.

6. Run this command on the source disk to check it’s filesystem:

– sudo e2fsck -f /dev/nvme1n1p1

(where nvme1n1p1 is the name of the disk partition, in your case it could be different, make sure using lsblk -f)

7. Change the UUID of the source disk to avoid duplicate UUID with the destination disk.

– sudo tune2fs /dev/nvme1n1p1 -U t1ce24a2-4987-4450-ae15-62eb028ff1cd

8. Attach the destination disk to the “workstation” instance.

9. Make directories to mount the source and destination disks.

– mkdir /mnt/source-disk

– mkdir /mnt/destination-disk

10. Mount the two disks

– mount /dev/nvme1n1p1 /mnt/source-disk

– mount /dev/nvme2n1p1 /mnt/destination-disk

11. Sync the two disks to that data in source disk is copied to destination disk.

– rsync -aAXv –exclude={“boot”} /mnt/source-disk/ /mnt/destination-disk

12. After the sync is complete, turn off the “workstation” instance and detach all destination volume.

13. Detach disks from original instance, attach destination disk as root disk. (/dev/sda1 in a lot of cases).

14. Start your original instance with the new shrunk disk.

Please let me know if you this guide was unclear and if you need more help.

I will proceed to find a way to automate this if there is demand for it.

Crd : Tariq Yahya IsmailTariq Yahya Ismail