Hi All,
I am trying to understand how can I share the directory on the host-machine with the lxd-vm running on the same host-machine. Any help with the sample configuration would be of great help.
Hi All,
I am trying to understand how can I share the directory on the host-machine with the lxd-vm running on the same host-machine. Any help with the sample configuration would be of great help.
Hi there,
You can use a disk
device added to the VM instance to achieve this.
See https://documentation.ubuntu.com/lxd/en/latest/reference/devices_disk/#configuration-examples
E.g.
lxc config device add <instance_name> <device_name> disk source=<path_on_host> [path=<path_in_instance>]
Thanks @tomp
One addon question here, what would be the device_name here.
For e.g. I want to share /home/test/shared folder with lxc vm instance runme then what would be the device_name?
Anything you like, it’s just a friendly name for referencing the device in the configuration (for editing or removing it).
Thanks @tomp
One more addon question
Can I make it Read-only or Read-write enabled for this path inside lxc vm ?
@codingfreak, yes, you just need to add readonly: false
to the disk device, see https://documentation.ubuntu.com/lxd/en/latest/reference/devices_disk/#device-options for details
Does below command add the mount as read-write?
lxc config device add apt-mirror mirror readonly=false disk source=/home/ubuntu/files path=/var
Yes that is correct.
Thanks a lot @tomp! In my case my guest system is a Windows 11 VM. Would sharing the directory work the same way in that case or are there any pitfalls due to the different file system formats (ntfs vs. ext4)? I want to access music and game folders from the Windows VM located on my Ubuntu host and wonder if the solution you describe is the way to go for this scenario.
LXD shares the host directory via 9p or virtiofs, so the guest would need to be able to mount those types of filesystems.
I’m not sure if Windows has support for either of those by default.
You may have some success with Virtiofs: Shared file system · virtio-win/kvm-guest-drivers-windows Wiki · GitHub
Please let us know how you get on.
Thanks!
Thanks a lot the virtiofs solved this. Just to give some more information in case others might want to do the same:
You can solve this as follows:
lxc config device add win11 foo disk source=/home/johndoe/foo path=foo
on the host.Installing these guest-tools will creates a new service on your guest system, which you should add to start-up type Automatic
and start.
This service will translate the path of the device you added in the first step to something windows understands resulting in the drive you shared with your guest system/Windows VM appearing in the guest system explorer.
Excellent, glad you got it solved. Nice!