This guide explains how to extend the storage of an AWS EC2 instance's root partition and resize the filesystem to utilize the additional space.
- An AWS EC2 instance with an EBS volume.
- SSH access to the EC2 instance.
- Stop the EC2 instance for safety. This step is optional but recommended to ensure data integrity.
- In the AWS Management Console, navigate to the EC2 dashboard.
- Go to "Volumes" and locate the volume attached to your instance.
- Right-click on the volume and select "Modify Volume".
- Increase the size as needed and confirm the changes.
- Restart the EC2 instance if it was stopped.
-
Connect to the EC2 instance via SSH.
-
Run
df -h
to check the current disk space usage.df -h
Output:
Filesystem Size Used Avail Use% Mounted on /dev/root 15G 15G 18M 100% / ...
-
Use
lsblk
to list all block devices and their sizes.lsblk
Output:
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT xvda 202:0 0 50G 0 disk ├─xvda1 202:1 0 14.9G 0 part / ...
-
Use
growpart
to resize the partition.sudo growpart /dev/xvda 1
-
After resizing the partition, use
resize2fs
to resize the filesystem.sudo resize2fs /dev/xvda1
-
Run
df -h
again to verify that the filesystem is now utilizing the new partition size.df -h
Expected Output:
Filesystem Size Used Avail Use% Mounted on /dev/root 50G 15G 35G 30% / ...
This guide helps in extending the storage of an AWS EC2 instance by resizing the EBS volume and extending the filesystem. Always ensure to have backups before performing such operations.