Written by BiRU Wednesday, 28 February 2024 17:04
I use FreeBSD whenever I can as a server machine because I find it very reliable, with a very good amount of non invasive features and whit a very extensive documentation and toll chain.
It happens that sometime you end up your disk space, and usually you have two choices:
ada0
, second partition therefore ada0p2
. The first step is to provide more space on the root disk, and I will not discuss here how I did because it depends on the actual virtual machine manager you are using.
Therefore, do stop the machine (you are not expecting to apply this on a live system, do you?) and enlarge the filesystem thru your virtual media manager.
First of all, boot the machine in single user mode and get to a shell.
Use gpart show
with the disk name to get the list of partitions and find out the one you need to resize:
In the above example we need to resize ada0p2
.
Please note that between the free space and the ada0p2
there is the swap partition, so we need to erase that first.
As already stated, between the free space available on disk and the partition I need to resize there is the swap partition ada0p3
, so I need to erase that first.
In my case don’t need to swapoff
the swap space, so I can go for the partition destruction.
However, before I’m able to act on the partition table there is the need to recover it. In fact, GPT scheme stores the partition data (backup) to the end of the disk, and since the end has grown, gpart
is not able to find such copy of the data and assumes the partition is corrupted. It does suffice to issue a gpart recover ada0
to make gpart
happy again. After that, it is possible to gpart delete -i 3 ada0
to erase the partition.
Now it is possible to resize the partition and add again a swap partition. The first step is to instrument the kernel to do so, and this requires to shut down extra dangerous partition protection by setting a kernel flag value.
Then you can resize the partition to less than the overall space, in order to let room for the swap partition, and then add the latter to the disk.
Therefore:
# sysctl kern.geom.debugflags=16
# gpart resize -i 2 -s 15G -a 4k ada0
# gpart add -t freebsd-swap -a 4k ada0
The resize
command is the crucial part, and expands the partition up to 15 GB
(change with your value) with a data alignment to 4kB
.
It is amost done, but there is the need to grow the root filesystem. This can be easily done, on UFS, by means of growfs(1)
:
Note how growfs(1)
displays the resizing from aorund seven gigabytes to fifteen, giving me a chance to check I’m doing the correct resizing.
The easiest part (if your machine starts over again!**.
Just issue a reboot and check the new filesystem once you can login again.
GEOM is too much superior of any other filesystem I’ve ever used, and the above steps emphasize how simple it can be to resize even the root partition!
I remember doing the same resizing on a Linux machine with a volume manager, and it was a lot much more complicated and obscure, at least to me.