Here is what happens when I try to mount directories using lxc file mount with lxd snap package

I want to access files in a container from the host using the ‘lxc file mount’ command. I’m using the lxd 5.0 snap package.

There are a few problems:

  1. I cannot access the user’s home directory at all because the lxd snap provides no plug for home:
 $ snap connections lxd
Interface       Plug                Slot             Notes
lxd             -                   lxd:lxd          -
lxd-support     lxd:lxd-support     :lxd-support     -
network         lxd:network         :network         -
network-bind    lxd:network-bind    :network-bind    -
system-observe  lxd:system-observe  :system-observe  -
  1. If I try to do this with a path in the snap, it doesn’t work either:
 23298.pts-0.vm-121 user@vm-121 2023-12-28 14:33:47 ~/certs $ lxc file mount container/etc/repo /certs/source
Error: stat /var/lib/snapd/hostfs/certs/source: no such file or directory
 23298.pts-0.vm-121 user@vm-121 2023-12-28 14:35:17 ~/certs $ sudo lxc file mount container/etc/repo /certs/source
[sudo] password for user:
Error: stat /var/lib/snapd/hostfs/certs/source: no such file or directory
 23298.pts-0.vm-121 user@vm-121 2023-12-28 14:35:40 ~/certs $ ls -liah /var/lib/snapd/hostfs/certs/
total 16K
393221 drwxr-xr-x 4 user user 4.0K Dec 28 14:16 .
 23434 drwxr-xr-x 3 root    root    4.0K Dec 28 14:15 ..
393386 drwxrwxr-x 2 user user 4.0K Dec 28 14:16 source
393587 drwxrwxr-x 2 user user 4.0K Dec 28 14:16 target
 23298.pts-0.vm-121 user@vm-121 2023-12-28 14:36:01 ~/certs $ ls -liah /var/lib/snapd/hostfs/certs/source
total 8.0K
393386 drwxrwxr-x 2 user user 4.0K Dec 28 14:16 .
393221 drwxr-xr-x 4 user user 4.0K Dec 28 14:16 ..

This is probably because I am misunderstanding how snap namespaces work. Can you help me get this to work?

When I try this on 5.0/stable I get a different error:

pwd
/home/user

lxc file mount c1/root/foo bah
sshfs mounting "c1/root/foo" on "/var/lib/snapd/hostfs/home/user/bah"
Press ctrl+c to finish

"lxc file mount" with SSHFS can only be used as root in the LXD snap.
For use as a regular user, please use the --connect option instead.

Note that the --connect option mentioned here is actually --listen and is fixed in a future release.

Installing sshfs and then running the command with sudo worked:

sudo lxc file mount c1/root/foo bah 
sshfs mounting "c1/root/foo" on "/var/lib/snapd/hostfs/home/user/bah"
Press ctrl+c to finish

If you start the local path with / it will be interpreted as an absolute path.