The FreeBSD filesystem is somewhat unique and requires a few precautions. Unlike a classic filesystem, the BSD filesystem is split into partitions, then into sub-partitions. FreeBSD uses the GPT partition model and a GEOM framework to manage these partitions. Each GPT partition contains a bsdlabel with the actual partitions. The resulting model looks like this:
In a virtualized environment you may need to extend a disk for various reasons. First, grow the system disk through your virtualization platform of choice. Then boot on a FreeBSD install CD and switch to shell mode.
The first step is to grow your GPT slices. If you have only one slice this is straightforward (otherwise you’ll need a second disk to place the slices that follow the one you want to grow). First let’s check the disks and GPT slices present:
# gpart show
=> 63 31457217 da0 GPT (50G)
63 31455207 1 freebsd [active] (15G)
31455270 73402330 - free - (35G)
=> 0 31455207 da0s1 BSD (15G)
0 30055207 1 freebsd-ufs (14G)
30055207 1400000 2 freebsd-swap (683M)
The swap partition will get in the way. Remove it:
# gpart delete -i 2 da0s1
Now resize the GPT partition to use the whole disk:
# gpart resize -i 1 da0
# gpart show
=> 63 104857537 da0 MBR (50G)
63 104857515 1 freebsd [active] (50G)
104857578 22 - free - (11k)
Growing the filesystem is more delicate. First grow the slice to the size specified in the MBR:
# growfs da0s1
# gpart show
=> 63 104857537 da0 MBR (50G)
63 104857515 1 freebsd [active] (50G)
104857578 22 - free - (11k)
=> 0 104857515 da0s1 BSD (15G)
0 30055207 1 freebsd-ufs (14G)
30055207 74802308 - free - (35G)
Then finish by growing the UFS filesystem:
# gpart resize -i 1 da0s1
# gpart show
=> 63 104857537 da0 MBR (50G)
63 104857515 1 freebsd [active] (50G)
104857578 22 - free - (11k)
=> 0 104857515 da0s1 BSD (50G)
0 104857515 1 freebsd-ufs (50G)