How to Resize Partitions on FreeBSD
In this guide I will demonstrate how to resize the root partition of a FreeBSD system
using gpart(8) from a live system. This procedure is particular useful when you need
to increase the disk size without having to reinstall the whole operating system.
Although this process is safe and well tested, I strongly recommend performing it first
on a testing environment and creating multiple backup copies of the production system
before proceeding.
Since the resize procedure differs when using ZFS, that scenario will be addressed on the final section of this guide.
Resize UFS partitions
Let's start by figuring out which disk we want to resize. We can use gpart show
to retrieve the list of available drives. In my setup, since I only have one disk,
I get the following output:
Because partitions can only be expanded into contiguous free space, resizing the second partition (i.e., the root partition) requires first deleting the third one. After removing it, we will then proceed by expanding the second partition and then recreating the swap:
We now can resize the root partition and recreate the swap area:
We can now check whether the operation was successful or not by issuing the following command:
Since the partition correctly indicates the expected size (43GiB), we can complete this procedure by resizing the file system:
Finally, let's activate back the swap partition:
Resize ZFS partitions
As mentioned before, the final section of this guide will cover the resizing of ZFS partitions. While the procedure is largely similar to the steps outlined before, certain aspects specific to ZFS pools warrant a separate treatment.
Just like before, let's get started by listing the available disks:
We want to resize the last partition; that is, the root one. In this case, the disk
is a virtual one created using QEMU. Therefore, I will use qemu-img(1) to extend it:
After that, power on the machine and run gpart show to acknowledge that
the disk has been successfully expanded:
As you can see, the disk has been flagged with a "corrupt" status. This is normal when modifying the size of GPT-partitioned disk, as the backup of the partition scheme is no longer located at the end of the disk, causing the system to be unable to locate it.
In order to fix this issue, we can run the following command:
Let's now extend the last partition:
Since no error were reported, the partition is successfully resized. The last thing we need to do is to check whether the ZFS pool has been informed about this change:
As you can notice, the size has not been automatically updated; therefore, we need to this manually using the following command:
Let's check again: