can a bhyve instance be resized? adding another virtual disk?

John Nielsen lists at jnielsen.net
Wed Oct 15 14:38:47 UTC 2014


On Oct 15, 2014, at 5:56 AM, freebsd-lists at potato.growveg.org wrote:

> Can a bhyve instance be resized? I'm talking about the disk. 
> Say your end user needs more diskspace. They have 32GB. They need 64GB.
> How do you do it? I presume one has to stop the guest, then use truncate.
> What about if the guest OS isn't freebsd, and they use say ext2 or 3? Will
> ext3 start yelling at me because I've resized it?

This isn't specific to FreeBSD or bhyve. Virtio block devices actually can support online resizing, but I don't know if bhyve allows that yet (I'm assuming it doesn't). In which case, yes, stop the guest and resize whatever its volume lives on (if a raw file then truncate would work), then start it up again. That's the easy part.

The harder part (but much easier than it used to be) is resizing everything else. If using partitions they need to be extended first (and if using GPT the backup partition table needs to be moved first of all, a la "gpart recover".) On FreeBSD this is pretty straightforward with gpart:
sysctl kern.geom.debugflags=16
gpart resize -i $number_of_last_partition $underlying_block_device

You should probably reboot at this point so the kernel forgets about the old partition table.

Then you get to resize the filesystem. If you are using ZFS or if you have FreeBSD 9.2 or newer and UFS then you can do it while it is mounted. Otherwise you may need to boot from another source to do the resize. For UFS use growfs a la "growfs /dev/$block_special_for_partition". For ZFS use "zpool online -e $zpool $zdev"

For ext[234] on Linux, use "resize2fs /dev/$block_special". (If using LVM then you need to first resize the LV with lvextend). For XFS use "xfs_growfs $mountpoint". You can also resize btrfs but I don't know the command off the top of my head.

That should be it.

> What if they just want another disk? How does one refer to a 
> newly created virtual disk from a guest? How is it mounted to the guest?

Just add a "-d /path/to/new/device" to your vmrun.sh or the corresponding -s to bhyve when you start the VM. It will show up as a new block device in the guest (e.g. /dev/vtbd1), you can partition and/or put filesystems on it as you choose and mount them normally and/or add them to /etc/fstab, etc.

JN



More information about the freebsd-virtualization mailing list