Basic sharing directories

Friends

I have got myself tied in knots trying to share a directory between the host and an Incus container.

I see at Type: disk - Incus documentation

Path on the host

You can share a path on your host (either a file system or a block device) to your instance by adding it as a disk device with the host path as the source:

incus config device add <instance_name> <device_name> disk source=<path_on_host> [path=<path_in_instance>]

The path is required for file systems, but not for block devices.

What is <device_name> in this instance? Is this the correct way to go? Am I off track?

I tried, given my container named c1

cd /tmp
mkdir c1_x

I want to share the directory /tmp/c1_x

incus storage create bar dir source=/tmp/poa_x
incus config device add c1 bar disk source=/tmp/c1_x path=/tmp/c1_x

But I clearly do not know what I am doing

Edit to add:

I found Use shift(fs) in Incus · toby63/shiftfs-dkms Wiki · GitHub That looks exactly like what I want, but bing a beginner with containers I cannot understand the instructions:

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

If all I need to add to my configuration is shift: true where does the rest of that go?

Looking at: How to use profiles - Incus documentation

I attempted to create a profile and edit it:

/tmp$ incus profile create c1-share-dir
Profile c1-share-dir created
/tmp$ incus profile set c1-share-dir shift=true
Error: Unknown configuration key: shift

You do not need to go through all that, it’s quite straightforward to add a host path to the container.

For a previously created container, let’s assume the container name is c1, and the path you want to share with the container is /tmp/c1.

incus config device add c1 tmpc1 disk source=/tmp/c1 path=/tmp/c1 shift=true

If you run incus config device show c1 you should see a new disk device named tmpc1.

shift=true ensures that you would be able to write to the directory in the container.

1 Like

Remembering to create /tmp/c1 on the host first

On c1 the path /tmp/c1 is created by the device add command

I just posted this

1 Like

Any particular reason you use the term folder instead of directory in your post? I will take a closer look tomorrow.

In the computer UI design, the preferred term is folder for a directory.
I think I mixed the use of directory and folder in the post. I should have stuck to directory as this is a technical audience.

jarrodu Jarrod Urban
August 22

Any particular reason you use the term folder instead of directory in your post? I will take a closer look tomorrow.

No. I use the term interchangeably. I never even noticed I do that.
Must be because I learnt to programme on Mac Plus - back in the day,
and that was the term they used.

I am close to thoroughly testing incus config device add c1 tmpc1 disk source=/somewhere/somedir path=/home/c1/var/host shift=true. I
gave it the quick test yesterday and it seemed perfect.

I am new `

This almost worked.

But there is a problem with ownership:

Before I create the container with the shared drive, at /opt/mach/var/assets;

worik@mach-test:~$ sudo ls -ld /opt/mach/var/assets 
drwx------ 2 mach mach 4096 Aug 23 16:07 /opt/mach/var/assets

Create container including make shared drive

sudo ls -ld /opt/mach/var/assets 
drwx------ 2 debian debian 4096 Aug 23 16:07 /opt/mach/var/assets

Sonow the user mach cannot use the drive

It seems you’re conflicting the user on the host with the user in the container.

Can you run the following commands both on the host and in the container and share the outputs.

id -u
ls -l /opt/mach/var/assets

Please read carefully the post at How to share a folder between a host and a container in Incus – Mi blog lah!
This post was written specifically for this thread.

You are seeing a different username on the host and in the container. This does not mean that the UID/GID are different.
When you use ls, add the parameter --numeric-uid-gid.

$ ls -l --numeric-uid-gid SHARED/
total 0
-rw-rw-r-- 1 1000 1000 0 Ιουλ 30 19:26 one
-rw-rw-r-- 1 1000 1000 0 Ιουλ 30 19:26 three
-rw-rw-r-- 1 1000 1000 0 Ιουλ 30 19:26 two
$
1 Like

Thank you for your help and hard work.

Unfortunately the powers that rule my working life have decreed “It Must Be Docker”

My objections to becoming reliant on commercial tools that can be used to squeeze us did not carry the day.

Please keep up the good work and all the best with Incus.