# [EN] On-line storage resizing in cloud instances

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:

1. Go to AWS EC2 Dashboard.
    
2. Click **Volumes** and find your volume that you want to increase.
    
3. Right click the volume name and choose **Modify Volume**.
    
4. Increase the volume size in the **Size (GB)** field.
    

# Resize the partition

SSH into the server and run the following commands.

<div data-node-type="callout">
<div data-node-type="callout-emoji">💡</div>
<div data-node-type="callout-text">Check the commands before copying and running anything.</div>
</div>

```bash
# 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.

```bash
# 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% /
```
