Sharing a host-machine directory with lxc-vm

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

1 Like

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.