Monthly Archives: July 2025

How I Successfully Shrunk an AWS EC2 Root EBS Volume (Even Though AWS Says You Can’t)

AWS doesn’t natively support shrinking an EBS volume — especially not a root volume. But with a little low-level Linux work and some patience, I successfully reduced a 200GB root volume down to just 20GB on a live EC2 instance.

Here’s the complete step-by-step process I followed, in case you ever need to do the same.

The Situation

– OS: Ubuntu on EC2
– Root volume: 200GB (over-allocated)
– Goal: Shrink to 20GB without rebuilding the system from scratch
– Challenge: AWS doesn’t allow shrinking EBS volumes directly

The Solution: Copy and Boot from a New, Smaller Volume

Attach a New Blank Volume

Create a 20GB EBS volume and attach it to the instance (default naming will usually be /dev/nvme1n1).

Identify the New Device

Run:
lsblk

Confirm the new volume appears as /dev/nvme1n1 and has no partitions.

Partition and Format the New Volume

sudo parted /dev/nvme1n1 --script mklabel gpt
sudo parted /dev/nvme1n1 --script mkpart ESP fat32 1MiB 201MiB
sudo parted /dev/nvme1n1 --script set 1 boot on
sudo parted /dev/nvme1n1 --script mkpart primary ext4 201MiB 1225MiB
sudo parted /dev/nvme1n1 --script mkpart primary ext4 1225MiB 100%


sudo mkfs.vfat -F32 /dev/nvme1n1p1
sudo mkfs.ext4 /dev/nvme1n1p2
sudo mkfs.ext4 /dev/nvme1n1p3

Mount the New Volume

sudo mkdir -p /mnt/newroot/boot/efi
sudo mount /dev/nvme1n1p3 /mnt/newroot
sudo mkdir /mnt/newroot/boot
sudo mount /dev/nvme1n1p2 /mnt/newroot/boot
sudo mount /dev/nvme1n1p1 /mnt/newroot/boot/efi

Copy the Existing System

sudo rsync -aAXH --progress \
--exclude={"/mnt/*","/proc/*","/sys/*","/dev/*","/run/*","/tmp/*","/media/*","/lost+found"} \
/ /mnt/newroot/

Chroot and Rebuild Boot Environment

sudo mount --bind /dev /mnt/newroot/dev
sudo mount --bind /sys /mnt/newroot/sys
sudo mount --bind /proc /mnt/newroot/proc
sudo mount --bind /run /mnt/newroot/run
sudo chroot /mnt/newroot


Inside chroot:
blkid /dev/nvme1n1p3
nano /etc/default/grub


Set:
GRUB_CMDLINE_LINUX="root=UUID=your-root-uuid-here"

Then run:
update-grub
update-initramfs -c -k all
grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=ubuntu --recheck --no-floppy

Exit and Unmount Everything

exit
for dir in run dev sys proc; do sudo umount /mnt/newroot/$dir; done
sudo umount /mnt/newroot/boot/efi
sudo umount /mnt/newroot/boot
sudo umount /mnt/newroot

Swap the Volumes

Stop the instance
Detach the old 200GB volume
Detach the 20GB volume
Reattach the 20GB volume as /dev/nvme0n1

Boot and Verify

After starting the instance:
lsblk
df -h /
cat /etc/fstab


Ensure / is mounted from nvme0n1p3 and fstab UUIDs match.

Clean Up and Celebrate

Delete the old volume to reduce cost
Optionally create an AMI of the new setup