Resize FreeBSD disks (and filesystems)So, it happens sometime, especially when dealing with upgrades, that I run out of space on my virtualized FreeBSD filesystems. I tend to use the Fast File System on such virtual disks, because I don’t need the power of ZFS on virtual machine and, rather, I want to save as much memory as possible.
Now, how can I resize the disk and the filesystem?
Luckily, this is explained very well on the officiale FreeBSD handbook. If you are lucky enough to have to grow a non-root disk, unmounting and proceeding with the following steps is quite straighforward, but in my case I needed to increase the root filesystem, therefore I had to boot from an installation media.
In my case I had the first disk,
ada0with three partitions:
ada0p1is the boot partition;
ada0p2is the root filesystem partition;
ada0p3is the swap space.
It was something like this:
% gpart show ada0 => 40 37748656 ada0 GPT (15G) 40 1024 1 freebsd-boot (512K) 1064 35651584 2 freebsd-ufs (14G) 35652648 2096048 3 freebsd-swap (1.0G)
If you resize the disk in your virtualization environment, you will find the free space at the end of the disk, so in order to make the root filesystem partition to grow, you have to destroy the swap partition and recreate it later.
Of course, depending on the value of your data, you should do an appropriate backup before doing this!
After having booted, and therefore having the partition not mounted, I did the following:
gpart recover ada0to make gpart not blame about a corrupted partition;
gpart delete -i 3 ada0to delete the third partition of the disk, that is the swap space;
gpart resize -i 2 -s 17Gto resize the root partition;
gpart add -t freebsd-swap -a 4K ada0to add again the swap space;
growfs /dev/ada0p2to make the filesystem grow.
gpartand I love FreeBSD!