Mount a local directory under user's home

I’m trying to mount my local /home/myuser/development directory inside an lxd container, at /home/myuser/development. It actually kind of works, but not completely.

I’m using a custom profile like this

# this is the output of lxc profile show myprofile
config:
  raw.idmap: both 1000 1000
  user.vendor-data: |
    #cloud-config
    locale: pt_PT.UTF-8
    users:
      - name: myuser
        lock_passwd: false
        shell: /bin/bash
        sudo: ['ALL=(ALL) NOPASSWD:ALL']
        ssh_import_id: 'gh:mygithubuser
description:
devices:
  dev_directory:
    path: /home/myuser/development
    source: /home/myuser/development
    type: disk
name: myprofile
used_by:

Now if I launch a new container with

lxc launch ubuntu:18.04 test -p default -p myprofile

The container starts up and my /home/myuser/development directory is indeed properly mounted. The problem is that /home/myuser is owned by root.

# lxc exec test -- /bin/bash
ls -lah /home
drwxr-xr-x  3 root root 4.0K Jan  9 11:26 .
drwxr-xr-x 22 root root 4.0K Dec  6 16:02 ..
drwxr-xr-x  3 root root 4.0K Jan  9 11:26 myuser

This also means that the ssh_import_id entry of my profile’s cloud-init section fails (since it cannot write to the user’s own home directory).

I do however have ownership of the stuff under the mounted dir:

ls -lah /home/myuser
total 12K
drwxr-xr-x  3 root    root    4.0K Jan  9 11:26 .
drwxr-xr-x  3 root    root    4.0K Jan  9 11:26 ..
drwxrwxr-x 73 myuser myuser 4.0K Jan  9 10:43 development

In order to overcome this I need to manually do a recursive chown in myuser home dir and then import my github ssh key.

Is it not possible to mount sub-dirs of of a user’s home with lxd?

1 Like