LXD usecases of shiftfs (volume-/disk-share)

What is shiftfs?
See @stgraber’s post.

Usecases:

  1. General Advantages:
  • faster startup of containers
  • easier and less risky setup of uid/gid-shifting
  1. sharing disk-devices:
    If you want to share e.g. a folder between host & container or between containers.

  2. sharing volumes:
    If you want to share volumes between isolated containers.

How to get shiftfs:

  • For Ubuntu Users: It is already included in the Ubuntu Kernel.
  • For other Distros: It is not included in the mainline kernel yet, but you can add it via dkms.
    I created a github repo for this: https://github.com/toby63/shiftfs-dkms/

Instructions:
1. General use:
See @stgraber’s post on how to enable shiftfs in LXD.

2. Sharing disk-devices:

If you want to share a disk device (for example a folder) between host/container or between containers, so that both parties can have full access (rwx) to it, shiftfs will make that much easier.

You only need to add this key to your device-configuration in the container/profile-config:
shift: true

For example:

folder1:
path: /home/user1/folder1
source: /home/hostuser1/folder1
shift: true
type: disk

Note:
This will match the hosts uid/gid (of the folder owner) with the container uid/gid.
So if the hosts uid is 1000, the user in the container also needs to have the uid 1000 to be able to access it.
See forum post by stgraber.

3. Sharing volumes:

If you want to share a volume between isolated containers, shiftfs will make that possible.

You add this key to your volume-configuration:
security.shifted=true

Then you attach the volume to both containers:
lxc storage volume attach POOL-NAME VOLUME-NAME container1 DEVICENAME /PATH

lxc storage volume attach POOL-NAME VOLUME-NAME container2 DEVICENAME /PATH

Sources:

Tags:
share folder
share volume
:rw

2 Likes

Thanks, have moved this to the tutorials category.

1 Like