Shared folders
Files shared between your code and the guest over virtio-fs or 9p, filled and read from JavaScript.
A shared folder is a tree of files your code and the guest both see. The guest mounts it with virtio-fs or 9p; your code puts files in and reads them back through vm.shares.
Adding a share
Name the share on the command line with a tag, the name the guest mounts it by:
# virtio-fs
-device vhost-user-fs-pci,tag=host
# 9p
-virtfs local,mount_tag=host,security_model=noneUse virtio-fs where the guest's kernel has it; 9p is there for kernels that don't.
Warning The share is a tree held in memory, not a mirror of a directory on your computer. A path= on -virtfs or -fsdev is ignored with a warning: the share starts empty and is filled from JavaScript.
Filling it from JavaScript
const share = vm.shares.get("host");
share.put("input/data.csv", new TextEncoder().encode("a,b\n1,2\n"));
share.mkdir("output");Mounting it in the guest
# virtio-fs
mount -t virtiofs host /mnt
# 9p
mount -t 9p -o trans=virtio host /mntAlpine's netboot initramfs loads the driver first: modprobe virtiofs.
Reading the guest's files
const bytes = vm.shares.get("host").get("output/result.txt");
if (bytes) console.log(new TextDecoder().decode(bytes));
console.log(vm.shares.get("host").list("/output"));get() returns null for a file that isn't there, and list() marks directories with a trailing /.
Snapshots
A share's tree is part of the machine's state: savevm and migrate save it, and restoring brings it back.