Resize a FreeBSD UFS Boot Drive

FreeBSD

Resizing the boot drive on a FreeBSD server can seem a little daunting since that if the drive that FreeBSD is running on. This post will show that it is not that hard, if your FreeBSD server is a guest running on a hypervisor (I use VMware for this).

NOTE: This is don’t with FreeBSD 12.2 UFS under VMware.

Shut down the FreeBSD guest and increase the side of the virtual disk.

Start the FreeBSD server backup. Login as root and tell FreeBSD to check the drives again just incase. NOTE: The boot drive in this case is da0

# camcontrol reprobe da0

Resize the partition table.

# gpart recover da0

You can only resize the last partition on the disk. If your swap is the last partition (the default was for FreeBSD install) then you have to remove it before you can resize the file system. In this example the swap is the last partition /dev/da0p3 (the third partition) so will will first turn our swap off and then remove it.

# swapoff /dev/da0p3
# gpart show da0
# gpart delete -i 3 da0
# gpart show da0

FreeBSD by default will not let you make changes to the partition table of a disk that is mounted so we need to tell the kernel to allow this. Note that the kernel does not keep this setting across reboots so even though we are telling the kernel to allow it, it will be back to the standard setting after a reboot.

# sysctl kern.geom.debugflags=16

Resize the UFS partition now, make sure to leave room to put the swap back. Once the partition is resized we can recreate the swap partition and enable it again.

# gpart resize -i 2 -s 48G da0
# gpart add -t freebsd-swap da0
# swapon /dev/da0p3

Now that the partition is resized. Let’s grow the file system.

# growfs /dev/da0p2

Leave a Comment

Your email address will not be published. Required fields are marked *