Growing a VM partition

Alerts inform me that my root partition on user-apps is running low on space. Expanding disk space is usually a task I’d leave to another, but it’s on me to learn now.

I’ve already taken the easy steps pruning old Docker images that are no longer in use, migrating large infrequently accessed data over to FreeNAS and just mounting it, confirming there are no other obvious gains via ncdu -x /.

Expanding the virtual disk

The first step seems obvious: go into Proxmox and resize the virtual disk.

Proxmox resize

But df -h | grep sda doesn’t show any change in disk size, so clearly I’m missing something. A quick google shows that resizing in Proxmox only resizes the virtual disk, but does nothing to modify the virtual machine’s partitions. That actually makes sense as Proxmox can’t and likely shouldn’t guess how you want to make use of the newly allocated space.

Resizing the partition

I feel like fdisk and I have a tenuous relationship. I know how to use it, but I find it unnervingly easy to shoot myself in the foot while I do. Looking at my partition layout, I have a swap partition after my root partition, so I have to do the following dance:

  1. swapoff -a
  2. fdisk
    • Remove both partitions
    • Create new partitions of the appropriate sizes, maintaining the ext4 signature of the root partition
    • Mark the root partition as bootable
    • Adjust the swap partition to type 82 (Linux swap)
    • Write the partition table to disk
  3. mkswap /dev/sda2
  4. Modify /etc/fstab to note the new swap UUID
  5. Remount the partitions

And thankfully I haven’t destroyed my partitions in the process (though note we have both full VM snapshots and file-level Borg backups in the event of).

Resizing the file system

Lastly, resize2fs will adjust the ext4 file system to match the partition size. df -h | grep sda confirms our job is done.

I’m sure the above is fairly banal to those that have done it a thousand times, but there’s a sense of independence that comes from learning how to take these steps yourself.