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:

  • domain.img is the image to resize
  • +8GB adds another 8GB

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:

  • -i 2 means to resize the partition with index 2 which is our freebsd-ufs root partition,
  • -s 23G means to resize the root partition up to 23GB (15GB and another 8GB since we want 1GB left over for swap space)

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:

  • -t freebsd-swap specifies the filesystem type as freebsd-swap,
  • -i 3 is the new index,
  • -l swap sets the label of the partition to swap

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:

  • vtbd0p2 - p2 indicates the partition with index ''2'.

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


freebsd/resizing_partitions.txt ยท Last modified: 2022/04/19 08:28 by 127.0.0.1

Wizardry and Steamworks

© 2025 Wizardry and Steamworks

Access website using Tor Access website using i2p Wizardry and Steamworks PGP Key


For the contact, copyright, license, warranty and privacy terms for the usage of this website please see the contact, license, privacy, copyright.