Passthrough directory to VM

How do you passthrough a directory the a VM?

lxc config device add webserver test disk source=/mnt/pool/storage/test path=/mnt/test
Error: Invalid devices: Device validation failed "test": Invalid device option "path"

lxc config device add webserver test disk source=/mnt/pool/storage/test
Device test added to webserver

lxc start webserver
Error: Failed to run: qemu-system-x86_64 -S -name webserver -uuid 983e0289-2bce-4187-9f35- 
79f7459b1bb5 -daemonize -cpu host -nographic -serial chardev:console -nodefaults -no-reboot -no- 
user-config -readconfig /var/snap/lxd/common/lxd/logs/webserver/qemu.conf -pidfile 
/var/snap/lxd/common/lxd/logs/webserver/qemu.pid -D / 
/var/snap/lxd/common/lxd/logs/webserver/qemu.log -chroot /var/snap/lxd/common/lxd/virtual- 
machines/webserver -runas lxd: : exit status 1
Try `lxc info --show-log webserver` for more info

lxc info --show-log webserver
Name: webserver
Location: none
Remote: unix://
Architecture: x86_64
Created: 2020/01/25 23:15 UTC
Status: Stopped
Type: virtual-machine
Profiles: default, vm
Snapshots:
  snapshot-0 (taken at 2020/01/26 02:00 UTC) (expires at 2020/02/02 02:00 UTC) (stateless)

Log:

qemu-system-x86_64:/var/snap/lxd/common/lxd/logs/webserver/qemu.conf:165: A regular file was 
expected by the 'file' driver, but something else was given

Not supported, with a VM you can only pass a partition or disk image in as a disk, you can’t bind-mount a directory as can be done with containers, at least not yet.

@tomp looks like we need to fix our logic to refuse non-files at least.

I understand, thank you very much! Would love to see this feature added in the future if possible at all.

Yeah, we’ve been planning on adding it. It will require the agent to be running in the VM and will effectively be dynamically passing new 9p mounts.

1 Like

https://github.com/lxc/lxd/pull/6780 will improve the reported error

2 Likes