# resize truncated bhyve .img file



## zader (Feb 3, 2020)

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


----------



## Phishfry (Feb 3, 2020)

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..








						VM File sizing
					

I am new to VM's so I wonder what is the best strategy for VM file sizing. For example I am building a Poudiere VM and I truncated my VM for 80GB. What if I need more later? Can I DD my VM image into another larger image and grow the filesystem on the VM side? So I can probably grow a VM but...




					forums.freebsd.org


----------



## aragats (Feb 3, 2020)

The image file itself can be expanded with `truncate`:
	
	



```
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:
	
	



```
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:
	
	



```
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().


----------



## zader (Feb 3, 2020)

sick, ty sir!


----------

