Table of Contents

About

When running a FreeBSD virtual machine, at one point or another you may end up with the dreaded "disk full" message, in which case, you may need to resize the root partition. This tutorial assumes a typical partition set-up with a bootable partition, followed by the root partition, followed by swap space.

Growing the Virtual Machine Image

First stop the virtual machine by entering:

virsh -c qemu:///system

followed by showdown domain in order to shutdown the machine. Now in order to resize the image (only if it is in qcow or raw format), navigate to /var/lib/libvirt/images and issue:

qemu-img resize domain.img +8GB

where:

The next part is to edit the domain and add a FreeBSD ISO such that we will boot from the ISO rather than the virtual machine and then resize the partitions and the filesystem.

Resizing Partitions

After you boot from the FreeBSD ISO in single-mode, you will be logged-in as root and you can issue:

gpart show

in order to list the partitions:

=>       -         -  vtbd0  GPT  (16G)
         -         -      1  freebsd-boot  (512K)
         -         -      2  freebsd-ufs  (15G)
         -         -      3  freebsd-swap  (1.0G)
         -         -      -  free-space (8.0GB)

You can see that the free space was added at the end of the partition table. Since we really do not care about the swap partition, we can delete it temporarily:

gpart delete -i 3 vtbd0

which ends-up in a total of 9GB of free space:

=>       -         -  vtbd0  GPT  (16G)
         -         -      1  freebsd-boot  (512K)
         -         -      2  freebsd-ufs  (15G)
         -         -      -  free-space (9.0GB)

So we can now resize the root partition (freebsd-ufs index 2):

gpart resize -i 2 -s 23G vtbd0

where:

Issuing another gpart show will now list:

=>       -         -  vtbd0  GPT  (16G)
         -         -      1  freebsd-boot  (512K)
         -         -      2  freebsd-ufs  (23G)
         -         -      -  free-space (1.0GB)

So, we add back the swap partition by issuing:

gpart add -t freebsd-swap -i 3 -l swap vtbd0

where:

Finally issuing another gpart show we obtain:

=>       -         -  vtbd0  GPT  (16G)
         -         -      1  freebsd-boot  (512K)
         -         -      2  freebsd-ufs  (23G)
         -         -      3  freebsd-swap (1.0GB)

Now the partitioning is over but we must grow the root filesystem to the new size by issuing:

growfs /dev/vtbd0p2

where:

Now all is done, since swap space will be automatically initialised on the next boot.