FreeBSD & OPNsense: grow the root partition

October 3, 2020
opnsense freebsd ufs filesystem

I was playing with a small OPNsense VM when, during a major upgrade, the disk was suddenly full. If you ever create a OPNsense VM, here are the spec you should set :

  • 2 vCPU
  • 1GB RAM
  • 5GB disk

Boot is BIOS/MBR, in my case the disk was emulated SCSI. The network interface can use virtio.

Commands brief

Resize the disk on the hypervisor side, then reboot the VM or use camcontrol rescan all to refresh the SCSI bus (untested).

Now we’re ready for the resize dance:

# let's look at the partition layout
gpart show
# fix GPT partition table after disk extend
gpart recover da0
# now extend the partition to all available space
gpart resize -i 3 da0
# and grow the UFS filesystem
growfs /dev/gpt/rootfs

UFS is a bit confused if you specify the partition path, so be careful to use the mountpoint so it can detect the mounted partition and do an online grow.

growfs /dev/da0p3 # error
growfs /dev/gpt/rootfs # ok

More information on the FreeBSD doc: