Recently, I had to add some space to my test FreeBSD box. I’ve used this tutorial from the BSD handbook to do it.
First, we have to identify the name of the disk. In my case it was da0. I have two FreeBSD VMs at home, one running under VMWare Workstation and the other under Hyper-V. In both cases, the disk name was da0. Use dmesg to check the name of your disk.
gpart show da0
As you can see from the screenshot above, my partition that I want to extend is 7.6GB and the available space for extension is 991K. Technically, I can’t extend my partition because the swap partition (410M) is in between.
But, we can easily destroy and recreate this partition. Just make sure you are not doing this on a heavily used server.
First, let’s see how to destroy the partition. Use swapinfo to see where the swap partition is mounted.
gpart delete -i 3 da0
gpart recover da0
Then delete the swap again with gpart delete -i 3 da0.
If you show the disk one more time, you’ll see that the swap is gone and that the disk partition (7.6G) is now adjacent with the free partition (12G).
The 12G partition didn’t show up before because we got that “corrupt” error before. Now, we have to “grow” the original partition.
gpart resize -i 2 -a 4k -s 19G da0
-i 2 means the ID number 2, -s is the total size (19G = 12GB that I’ve added + about 7GB that I had originally).
We also have to plan for the swap partition. Always start with the smaller size than the total sum and then you can grow it if needed.
gpart add -t freebsd-swap -a 4k da0 swapon /dev/da0p3 gpart show da0