Guides

Shared folders

Share files between your code and the guest over 9p, filled and read from JavaScript, or use virtio-fs through QEMU's vhost-user device.

A shared folder is a tree of files that both your code and the guest can see. The guest mounts it with 9p, and your code puts files in and reads them back through vm.shares.

Adding a share

Add the share on the command line with QEMU's 9p options and a tag, the name the guest uses to mount it:

-virtfs local,path=/tmp,mount_tag=host,security_model=none
# or, as two options
-fsdev local,id=f0,path=/tmp,security_model=none -device virtio-9p-pci,fsdev=f0,mount_tag=host

Warning The share is a tree held in memory, not a mirror of a directory on your computer. QEMU's options require a path=, but Warm64 doesn't read it. The share starts empty, and you fill it 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

mkdir -p /mnt/host
mount -t 9p -o trans=virtio host /mnt/host

The guest's kernel needs the 9p and 9pnet_virtio modules. Alpine's netboot initramfs doesn't have them; an installed system does.

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.

virtio-fs

-device vhost-user-fs-pci is QEMU's virtio-fs device. It connects over a socket -chardev to a virtiofsd that you run, which serves a host directory, as described in QEMU's vhost-user-fs documentation. It's available in Node, and virtiofsd runs on Linux. Since its files belong to virtiofsd, it doesn't appear in vm.shares.

See also