Here is how to to increase the size of the disk for FreeBSD.

I am using FreeBSD 12.3 here running inside a Fedora Linux.  Here are some starting requirements

  1. One needs to have qcow2 type disk.
  2. the virtual machine must be shutdown
  3. No snapshots against the virtual machine

So, I cloned out the machine to test:

[jon2allen@fedora Downloads]$ ll freebsd*.qcow2
-rw------- 1 jon2allen jon2allen 12428836864 May 20 19:20 freebsd.bak-clone-1.qcow2
-rw------- 1 jon2allen jon2allen 20378157056 May 20 22:25 freebsd.bak-clone2.qcow2
-rw------- 1 jon2allen jon2allen 12430737408 May 20 19:14 freebsd.bak-clone.qcow2
-rw-r--r-- 1 jon2allen jon2allen 12517376000 Mar 13 22:19 freebsd.bak.qcow2
-rw-r--r-- 1 jon2allen jon2allen 12952010752 May 20 22:27 freebsd.qcow2
[jon2allen@fedora Downloads]$ 

The disk for the image is “freebsd.bak-clone-1.qcow2” and it roughly 20G.  And I want to increase it by 2G, because of all the stuff I installed.

[jon2allen@fedora Downloads]$ sudo qemu-img resize freebsd.bak-clone-1.qcow2 +2G
Image resized.
[jon2allen@fedora Downloads]$ ll freebsd*.qcow2
-rw------- 1 jon2allen jon2allen 12428837216 May 20 22:33 freebsd.bak-clone-1.qcow2
-rw------- 1 jon2allen jon2allen 20378157056 May 20 22:33 freebsd.bak-clone2.qcow2
-rw------- 1 jon2allen jon2allen 12430737408 May 20 19:14 freebsd.bak-clone.qcow2
-rw-r--r-- 1 jon2allen jon2allen 12517376000 Mar 13 22:19 freebsd.bak.qcow2
-rw-r--r-- 1 jon2allen jon2allen 12952010752 May 20 22:33 freebsd.qcow2
[jon2allen@fedora Downloads]$ 

You can see it is now 2 GB bigger, but of course the partition and fs are not using it yet.

So now boot up the freebsd image

Use this growfs to do the magic

 

service growfs onestart

It will invoke /etc/rc.d/growfs once. That script basically calls all the same commands that are in the FreeBSD Handbook. This script is meant to be called on first boot, so that you can distribute a very small virtual hard disk, and then when it boots the first time on a large virtual hard disk, the VM expands to use the whole disk provided. If you later expand your virtual disk (or if you dd your filesystem onto a larger physical disk) you can invoke the script manually once to do all the right things.

ref stackexchange doc on this

 

It says to do a commit… but I try it and it says operation not permitted.   However, it has worked. I shutdown and reload just for good measure

 

Leave a Reply