albertyw/albertyw.com

View on GitHub
app/notes/20221020-0501.md

Summary

Maintainability
Test Coverage
Resizing a Ubuntu Disk in a UTM VM

resizing-ubuntu-utm

1666242114

[UTM](https://mac.getutm.app/) is an awesome virtualization system based on
QEMU built for M1 (ARM) Macs.
[v4.0.8 of UTM](https://github.com/utmapp/UTM/releases/tag/v4.0.8), the first
v4 stable release, came out today with support for resizing QEMU disk images
but while the [UTM docs show how to resize the UTM machine](https://docs.getutm.app/settings-qemu/drive/resize-and-compress/#resize),
there's several more steps to get the virtualized file system to recognize
the additional disk space.

For an Ubuntu guest OS running a default GPT and LVM partition:

1.  On a shut down VM, in the UTM UI's configuration, select the disk you wish to expand, resize the disk, and save the VM configuration.
2.  Launch the VM and get a terminal
3.  Run `sudo fdisk -l` and confirm that there is a `GPT PMBR Size Mismatch will be corrected by w(rite)` warning
4.  Run `sudo parted -l` and gparted should ask to automatically fix the size mismatch.  Fix the size mismatch.
5.  If the resizing doesn't work, manually run `parted /dev/vda resize 3 100%`.
6.  Run `pvresize /dev/vda3`.
7.  Run `sudo lvm` to get an lvm console
8.  Run `lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv` to expand the lvm logical volume
9.  Exit the lvm console
10.  Run `sudo resize2fs /dev/ubuntu-vg/ubuntu-lv` to expand the ext4 file system to the logical volume
11.  Run `df -h` to confirm that the `/dev/mapper/ubuntu--vg-ubuntu--lv` has been expanded.

References:

- [Superuser: GPT PMBR Size Mismatch will be corrected by w(rite)](https://superuser.com/q/1352065/1687653)
- [AskUbuntu: Ubuntu Server 18.04 LVM out of space with improper default partitioning](https://askubuntu.com/q/1106795/1577326)