bhyve How to expand disk in bhyve vm

I have a vm created using bhyve with this command:
Code:
NGUEST=vhp3k-06 ;  vm create  -s 16G  -t rocky_linux_uefi $NGUEST &&  vm install $NGUEST  Rocky-8.6-x86_64-minimal.iso #

The template file contains this:
Code:
[root@vhost01 ~ (master)]# cat /zroot/vm/vhp3k-06/vhp3k-06.conf
# Rocky Linux 8.6  2022-08-03
loader="uefi"
cpu=4
memory=6G

network0_type="virtio-net"
network0_switch="vm_public_net"

network1_type="virtio-net"
network1_switch="vm_private_net"

disk0_type="virtio-blk"
disk0_name="disk0.img"

### gui console
# run vm list to get vnc port
# run vncviewer to connect to console
# do not use vm console

graphics="yes"
graphics_vga="io"
graphics_res="1024x768"

xhci_mouse="yes"
uuid="18952584-13f4-11ed-a5db-7085c2da884f"
network0_mac="58:9c:fc:03:e5:72"
network1_mac="58:9c:fc:0b:08:04"

In /etc/rc.conf I have this: vm_dir="zfs:zroot/vm.

The result is this:
Code:
[root@vhost01 ~ (master)]# ll /zroot/vm/vhp3k-06
total 4847312
-rw-------  1 root  wheel  17179869184 Nov 14 11:21 disk0.img
-rw-r--r--  1 root  wheel          890 Aug  9 09:55 vhp3k-06.conf
-rw-r--r--  1 root  wheel        15497 Nov 14 11:21 vm-bhyve.log


The questions are: Given that I have approximately 6 Tb available can I expand the disk allocation from 16G to 160G? How is this accomplished?
 
As you're using a file to store the virtual disk, it's easily resized with truncate(1). The rest of the procedure very much depends on your guest system. You'll have to modify the partition table, and you have to expand the filesystem...

On a side note, as you're using zfs, I'd recommend to use a zvol instead for backing the virtual disk. Something like this:
Code:
disk0_type="virtio-blk"
disk0_name="disk0"
disk0_dev="sparse-zvol"
If you opt for a sparse zvol, it's even possible to have it automatically shrink if the guest supports TRIM.
 
Back
Top