[EN] On-line storage resizing in cloud instances
![[EN] On-line storage resizing in cloud instances](/_next/image?url=https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fstock%2Funsplash%2F1qL31aacAPA%2Fupload%2Fc76fd3afa4463ff31288b16339d16751.jpeg&w=3840&q=75)
Let’s say you’re using VMs in AWS, GCP, or any other cloud provider and running out of disk storage. Normally you can stop the instance, increase the storage, and then start it again to resize the disk. But that would cause a downtime. In my experience, the easiest way to increase the storage without stopping the VM is using the growpart to resize the partition and resize2fs to resize the filesystem.
Increase the block storage
In this case my Ubuntu VM is running on AWS with storage of 8GB and need to increase it to 12GB. To increase the volume size:
Go to AWS EC2 Dashboard.
Click Volumes and find your volume that you want to increase.
Right click the volume name and choose Modify Volume.
Increase the volume size in the Size (GB) field.
Resize the partition
SSH into the server and run the following commands.
# Let's inspect the block devices first
# Here I have nvme0n1 disk.
# The disk size was 8GB and increased to 12GB.
# Then I want the nvme0n1p1 (first partition) to use the remaining free space (4GB)
ubuntu@i-00cfd0679ab3871a3:~$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
...
nvme0n1 259:0 0 12G 0 disk
├─nvme0n1p1 259:1 0 7G 0 part /
├─nvme0n1p15 259:2 0 99M 0 part /boot/efi
└─nvme0n1p16 259:3 0 923M 0 part /boot
# Let's increase it using growpart
# https://access.redhat.com/solutions/5540131
ubuntu@i-00cfd0679ab3871a3:~$ sudo growpart /dev/nvme0n1 1
CHANGED: partition=1 start=2099200 old: size=14677983 end=16777182 new: size=23066591 end=25165790
# Check the partition again
# Make sure the nvme0n1p1 size is increased
ubuntu@i-00cfd0679ab3871a3:~$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
...
nvme0n1 259:0 0 12G 0 disk
├─nvme0n1p1 259:1 0 11G 0 part /
├─nvme0n1p15 259:2 0 99M 0 part /boot/efi
└─nvme0n1p16 259:3 0 923M 0 part /boot
growpart is part of utility to extend a storage in cloud environment. Usually it’s already installed in the OS image as part of cloud-guest-utils package.
Resize the filesystem
After the partition has been resized, let’s resize the filesystem so we can actually use it.
# Resize the FS
ubuntu@i-00cfd0679ab3871a3:~$ sudo resize2fs /dev/nvme0n1p1
...
Filesystem at /dev/nvme0n1p1 is mounted on /; on-line resizing required
The filesystem on /dev/nvme0n1p1 is now 2883323 (4k) blocks long.
# Verify the filesystem size again
# Now the FS size is matched with the partition size
ubuntu@i-00cfd0679ab3871a3:~$ df -Th
Filesystem Type Size Used Avail Use% Mounted on
/dev/root ext4 11G 1.7G 8.9G 17% /
![[EN] Set Up Amazon ECR Pull-Through Cache for Docker Hub](/_next/image?url=https%3A%2F%2Fcdn.hashnode.com%2Fuploads%2Fcovers%2F631dd8693e8d6f3497ad63e7%2F1ca35a5a-6303-4a86-badb-91961cf65694.jpg&w=3840&q=75)
![[EN] Track progress of MySQL Import/Export process using PV](/_next/image?url=https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fstock%2Funsplash%2Fjf1EomjlQi0%2Fupload%2Fa7ee07f61c1dc2ad71b4cf2bb4523765.jpeg&w=3840&q=75)
![[EN] Lesson learned from using the wrong AWS ElastiCache Redis endpoint](/_next/image?url=https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fstock%2Funsplash%2FemolMCqnKfg%2Fupload%2Fc7eb8197eb9ef632459ae6612b861cc6.jpeg&w=3840&q=75)
![[EN] My experience taking the KCNA certification](/_next/image?url=https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fstock%2Funsplash%2FKXwPJtAJLfU%2Fupload%2F3deba4b52e1b8e442179a495944ccb9e.jpeg&w=3840&q=75)
![[EN] How I Stopped Copy-Pasting AWS EC2 IPs and Started SSHing Smarter](/_next/image?url=https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fstock%2Funsplash%2FDXRP2PKlsFQ%2Fupload%2F8767e91ce57fa7ff90bca9149c142626.jpeg&w=3840&q=75)