Cleanest way to mount folder from host to container rw

Hi all,

how can we mount a folder from the host to the container rw mode? in a way i dont have to change user id’s and stuff like that?

I had the same problem.

The solution is shiftfs:

  1. Check wether your kernel includes shiftfs (to my knowledge only ubuntu’s kernel does).
    You can check that with:

modinfo shiftfs

1.a) If your kernel does not include it, you can use dkms to install shiftfs:

I created a github repo with scripts to install shiftfs via dkms:

  1. Activate it within lxd:
    Excerpt from comment by stgraber:
  • sudo snap set lxd shiftfs.enable=true
  • sudo systemctl reload snap.lxd.daemon

Check whether it is activated:

  • lxc info

And should see:

    shiftfs: "true"
  1. To use it with your container, you just need to add “shift: true” to your disk device.
    For example:
    folder1:
    path: /home/user1/folder1
    source: /home/hostuser1/folder1
    shift: true
    type: disk

And it should work.

Edit: Added my github repo.

Also interesting:

But maybe that is only for virtual machines (?).

@stgraber

Is this possible? What @toby63 answers? That should be great

Yeah, that’s for VM.

For containers the disk devices work fine but you indeed either need shiftfs or need to add some ACLs to allow write access.

How to add acls? Is this different then changing ids?

Yeah, it makes it possible for a container and the host to both have access.

You’d usually keep the ownership on the host as it is, then use setfacl to allow access by particular user or groups from inside the container.

Do i need to do this in the container or on the host. Because in the container root can not create files or setfacl

allredeay got it i think.

I need to do it with ids otherwise it is not working (by usernames). Is the disk mounted auto after reboot?

For everyone who is interested in using shiftfs, here is my github repo for shiftfs via dkms:

1 Like