# 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 trough Hypervisor

#### Expanding filesystem roof

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 /
```

#### Fix GPT/ Partition Table

If you run into problem where even after expanding filesystem roof it still stays at original number we might need to fix gpt/ partition table. Usually after running command below we would get following message.

1. Check Disk size vs Partition Size

```bash
sudo fdisk -l /dev/sda
```

  
GPT PMBR size mismatch (67108863 != 134217727) will be corrected by write.  
The backup GPT table is not on the end of the device

2. Fix GPT/ Partition Table

```bash
sudo gdisk /dev/sda
# Press 'v' to verify, then 'w' to write fixes
```

3. Resize the partition

```bash
sudo parted /dev/sda
(parted) resizepart 3 100%
(parted) quit
```

4. Reload partition table

```bash
sudo partprobe /dev/sda
```

5. Resize physical volume

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

6. Check VG Free Space

```bash
sudo vgdisplay
```

7. Expand Logical Volume

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

9. Resize Filesystem

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

At the end verify to make sure its actually resized

```bash
df -h /
```