I am using Free Tier on Amazon Web Services. It is a great offer. It comes with 30GB of space among other things. However, by default, a Linux VM comes with only 8GB of space. I have been working on my WordPress installations and I found out that the 8GB space is running out. Fret not, we can increase the space online. No downtime is required. This is how to do it.
First of all: Backup!
Modifying partition and filesystem is no simple task. A simple typo could ruin your Linux installation or data. On AWS we can easily backup our VM using its snapshot feature. However, it is only free for up to 1GB of snapshot. So, in this case, I will use a good old traditional backup method. That is tar gunzip and rsync to my local PC 🙂 I backup my WordPress files, databases, and supporting configurations (apache, automysqlbackup, etc).
Rsync command from my PC to AWS:
rsync -azvv -e “ssh -i /home/username/key-ssh1.pem” firstname.lastname@example.org:backup/ .
Check current filesystem usage. As you can see /dev/root which is mounted on / has about 8GB space.
Check current block device usage. This command is similar to fdisk. We can see xvda1 partition size is about 8GB.
Now we make a request to AWS to increase our VM Volume.
Go to menu:
1. Elastic Block Store > Volumes
2. Tick mark the volume we want to increase
3. Action > Modify Volume
4. Change the size to 16. Click Modify.
AWS said the modification may take a few minutes, but in my case, since the size is very small, the modification was almost instant.
Check current block device usage again with lsblk command. As you can see xvda is now 16GB, but partition xvda1 is still about 8GB.
Check also the filesystem size. As you can see it is still about 8GB (of course).
Now we have to “grow” the block device to utilize all available blocks with command: growpart /dev/xvda 1
Check block device size. xvda1 is now showing about 16GB.
Even though the partition has increased but the filesystem is still about 8GB. We have to resize the filesystem too.
Since the filesystem is EXT4, we use command: resize2fs
Check the filesystem usage, and finally, it is 16GB 🙂
And we do all of this without any downtime. I hope this experience sharing is useful for all AWS and Linux Sysadmin.
- Backup first
- Check current filesystem size and block device size
- Request Volume Increase to AWS:
- Elastic Block Store
- Select Volume, Modify Volume
- Wait if necessary till finished.
- Growpart block device.
- Resize filesystem.