-
-
Notifications
You must be signed in to change notification settings - Fork 11
share_folder
One easy way to share a host folder with a guest on bhyve is using virtio-9p devices.
- FreeBSD host running bhyvemgr
- FreeBSD guest
My host is a FreeBSD 15-amd64. From bhyvemgr, add a new virtio-9p (Shared folders) device from Devices Settings. Sharename will be used to identify virtio-9p device which will mount in the guest. I'm putting host-folder like name. Path is the folder location in the host that will be share with the guest. In this case, I'm sharing /home/acm/sample-folder directory.
In this guide, I'm using a FreeBSD 16.x CURRENT like a guest. It supports virtio-p9fs module.
When the guest boot is done, you can look into dmesg output if virtio-9p device is detected.
virtio_pci1: <VirtIO PCI (legacy) Entropy adapter> port 0x2240-0x225f mem 0xc2002000-0xc2003fff irq 17 at device 20.0 on pci0
virtio_pci2: <VirtIO PCI (legacy) 9P Transport adapter> port 0x2000-0x21ff mem 0xc2000000-0xc2001fff irq 19 at device 22.0 on pci0
The virtio-p9fs module is not loaded by default on boot time. You can add an entry to /boot/loder.conf to change it.
# echo virtio_p9fs_load=\"YES\" >> /boot/loader.conf
For testing purpose, load the driver manually
# kldload virtio_p9fs
virtio_p9fs0: <VirtIO 9P Transport> on virtio_pci2
virtio_p9fs0: Mount tag: host-folder
Now, mount virtio-9p filesystem into the guest
# mount -t p9fs host-folder /mnt
# ls /mnt
testfile testfile1 testfile2
Also, you can put an entry to /etc/fstab file
# echo "host-folder /mnt p9fs rw 0 0" >> /etc/fstab
virtio-9p driver support is included in FreeBSD 14-STABLE, 15-STABLE, 15-RELEASE and 16-CURRENT branches.