resize truncated bhyve .img file

Just wondering if anyone knows a safe way to expand a vm .img file created with truncate and used for a vm.. the image file its self is a tiny ubuntu 18.04 that needs more space.

thanks
 
I have done this with a FreeBSD VM but I dunno what to tell you for Ubuntu filesystem growth.
Truncate a new larger VM file and dd the old image to the new file. Then with FreeBSD you would run growfs from inside the VM to fill it out..
 
The image file itself can be expanded with truncate:
Code:
truncate -s<newsize> ubuntu.img
Then the safest way to expand the filesiystem is doing it from within Ubuntu itself.
Fire up Ubuntu, with fdisk or gdisk remove the partition and create a larger one starting from the same sector. Then reboot Ubuntu and run:
Code:
resize2fs <device_node>
where <device_node> is the one corresponding to the target partition, e.g. /dev/sda1.

Of course, all the above can be done in FreeBSD:
Code:
mdconfig ubuntu.img
gpart show md0
gpart resize -iN md0   # N - the partition index
resize2fs /dev/md0sN   # could be md0pN in case of GPT scheme
mdconfig -d -u0
You will need to install sysutils/e2fsprogs. You may also need to delete/re-add a swap partition if it's "on the way" of the expansion.

[EDIT] in case of GPT you should run gpart recover md0 before resizing the partition with gpart().
 
Back
Top