# Expanding VM Filesystem Size

If the VM hits the size limit, but there is more space allocated, or you allocated the space. These steps will help with expanding the size of the volume.

##### Checking the Size

1. Check Disk Usage to see which disk is affected

```bash
df -h
```

2. Check volume group for free space

```bash
sudo vgdisplay
```

If there is no space, you will need to allocate more through Hypervisor. Note: even after allocating more space in the Hypervisor, `vgdisplay` may still show 0 free PE — this means the partition and PV inside the guest haven't been grown yet to see the new disk size. Continue to the next section.

##### Extending the Partition and Physical Volume

Growing the virtual disk on the Hypervisor does not automatically grow the partition table inside the guest. The dependency chain is: disk → partition → PV → VG → LV → filesystem. Each layer must be resized in order before `lvextend` has any free space to work with.

1. Confirm partition layout and which partition holds the LVM PV (typically the last partition, e.g. sda3)

```bash
lsblk
```

2. Grow the partition to consume the new disk space

```bash
sudo growpart /dev/sda 3
```

If `growpart` is not installed: `sudo apt install cloud-guest-utils`

3. Resize the physical volume to match the new partition size

```bash
sudo pvresize /dev/sda3
```

4. Confirm the VG now shows free PE matching the new space

```bash
sudo vgdisplay
```

##### Expanding filesystem

1. Extend logical volume

```bash
sudo lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv
```

This will add remaining space to the root system

2. Resize filesystem

```bash
sudo resize2fs /dev/ubuntu-vg/ubuntu-lv
```

3. Verify disk size and usage

```bash
df -h /
```