I installed Linux Mint Debian Edition (LMDE) 6 on one of my older laptops, replaced version 6.1 of the Linux kernel with 6.5, and repeated my test of mounting a directory from the host into a container using incus config device add
both with and without option shift=true
. With this configuration, running incus config device add
with shift=true
was successful.
In my opinion, if you use a lot of containers that mount host directories into containers, option shift=true
in command incus config device add
is a very compelling reason to migrate from Proxmox to Debian Linux and Incus. In Proxmox, I find it very tedious to calculate and set the host to container ID mappings. Proxmox containers would benefit greatly from an option similar to option shift=true
in Incus.
Command “incus config device add” without option “shift=true”
Test script:
#!/usr/bin/env bash
# Trace the script execution.
set -o xtrace
# Display kernel version.
uname -a
# Display Incus containers.
incus list
# Display host user and group names and IDs.
id
# Display the contents of the source host directory that we will mount inside the container.
ls -la /mnt/incus/share
# Display the contents of the mounted path inside the container before mounting.
incus exec careful-seahorse -- ls -al /share
# Display the user and group names and IDs of user 1000 and group 1000 inside the container.
incus exec careful-seahorse --group 1000 --user 1000 -- id
# Mount the host directory /mnt/incus/share to /share inside the container without option shift=true.
incus config device add careful-seahorse share disk source=/mnt/incus/share path=/share
# Display the contents of the mounted path inside the container.
incus exec careful-seahorse -- ls -al /share
# Display the contents of the mounted path inside the container replacing user and group names with their numeric IDs.
incus exec careful-seahorse -- ls -aln /share
# Attempt to create file /share/test3.txt inside the container as user 1000 and group 1000.
incus exec careful-seahorse --group 1000 --user 1000 -- touch /share/test3.txt
# Display the contents of the mounted path inside the container.
incus exec careful-seahorse -- ls -al /share
# Display the contents of the source host directory that is mounted inside the container.
ls -la /mnt/incus/share
# Remove file created during test.
rm /mnt/incus/share/test3.txt
# Remove the mounted host directory "share" from the container.
incus config device remove careful-seahorse share
Output:
derek@yoga-3-pro:~/Documents$ ./incus_test_mount_host_directory_without_shift_true
+ uname -a
Linux yoga-3-pro 6.5.0-0.deb12.4-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.5.10-1~bpo12+1 (2023-11-23) x86_64 GNU/Linux
+ incus list
+------------------+---------+----------------------+-----------------------------------------------+-----------+-----------+
| NAME | STATE | IPV4 | IPV6 | TYPE | SNAPSHOTS |
+------------------+---------+----------------------+-----------------------------------------------+-----------+-----------+
| careful-seahorse | RUNNING | 10.158.47.161 (eth0) | fd42:6f5d:75b3:70fc:216:3eff:fe74:222e (eth0) | CONTAINER | 0 |
+------------------+---------+----------------------+-----------------------------------------------+-----------+-----------+
+ id
uid=1000(derek) gid=1000(derek) groups=1000(derek),4(adm),20(dialout),21(fax),24(cdrom),25(floppy),26(tape),27(sudo),29(audio),30(dip),44(video),46(plugdev),100(users),106(netdev),110(lpadmin),115(bluetooth),123(scanner),992(incus-admin)
+ ls -la /mnt/incus/share
total 16
drwxr-xr-x 2 derek derek 4096 Feb 12 13:04 .
drwxr-xr-x 3 root root 4096 Feb 9 13:50 ..
-rw-r--r-- 1 derek derek 7 Feb 9 14:06 test1.txt
-rw-rw-r-- 1 derek derek 7 Feb 9 14:05 test2.txt
+ incus exec careful-seahorse -- ls -al /share
ls: cannot access '/share': No such file or directory
+ incus exec careful-seahorse --group 1000 --user 1000 -- id
uid=1000(ubuntu) gid=1000(ubuntu) groups=1000(ubuntu)
+ incus config device add careful-seahorse share disk source=/mnt/incus/share path=/share
Device share added to careful-seahorse
+ incus exec careful-seahorse -- ls -al /share
total 12
drwxr-xr-x 2 nobody nogroup 4096 Feb 12 18:04 .
drwxr-xr-x 1 root root 164 Feb 12 18:12 ..
-rw-r--r-- 1 nobody nogroup 7 Feb 9 19:06 test1.txt
-rw-rw-r-- 1 nobody nogroup 7 Feb 9 19:05 test2.txt
+ incus exec careful-seahorse -- ls -aln /share
total 12
drwxr-xr-x 2 65534 65534 4096 Feb 12 18:04 .
drwxr-xr-x 1 0 0 164 Feb 12 18:12 ..
-rw-r--r-- 1 65534 65534 7 Feb 9 19:06 test1.txt
-rw-rw-r-- 1 65534 65534 7 Feb 9 19:05 test2.txt
+ incus exec careful-seahorse --group 1000 --user 1000 -- touch /share/test3.txt
touch: cannot touch '/share/test3.txt': Permission denied
+ incus exec careful-seahorse -- ls -al /share
total 12
drwxr-xr-x 2 nobody nogroup 4096 Feb 12 18:04 .
drwxr-xr-x 1 root root 164 Feb 12 18:12 ..
-rw-r--r-- 1 nobody nogroup 7 Feb 9 19:06 test1.txt
-rw-rw-r-- 1 nobody nogroup 7 Feb 9 19:05 test2.txt
+ ls -la /mnt/incus/share
total 16
drwxr-xr-x 2 derek derek 4096 Feb 12 13:04 .
drwxr-xr-x 3 root root 4096 Feb 9 13:50 ..
-rw-r--r-- 1 derek derek 7 Feb 9 14:06 test1.txt
-rw-rw-r-- 1 derek derek 7 Feb 9 14:05 test2.txt
+ rm /mnt/incus/share/test3.txt
rm: cannot remove '/mnt/incus/share/test3.txt': No such file or directory
+ incus config device remove careful-seahorse share
Device share removed from careful-seahorse
Notice that on the host, user derek (ID 1000) and group derek (ID 1000) own the files in /mnt/incus/share
, but inside the container, user nobody (ID 65534) and group nogroup (ID 65534) own the files in /share
.
Command “incus config device add” with option “shift=true”
Test script:
#!/usr/bin/env bash
# Trace the script execution.
set -o xtrace
# Display kernel version.
uname -a
# Display Incus containers.
incus list
# Display host user and group names and IDs.
id
# Display the contents of the source host directory that we will mount inside the container.
ls -la /mnt/incus/share
# Display the contents of the mounted path inside the container before mounting.
incus exec careful-seahorse -- ls -al /share
# Display the user and group names and IDs of user 1000 and group 1000 inside the container.
incus exec careful-seahorse --group 1000 --user 1000 -- id
# Mount the host directory /mnt/incus/share to /share inside the container with option shift=true.
incus config device add careful-seahorse share disk source=/mnt/incus/share path=/share shift=true
# Display the contents of the mounted path inside the container.
incus exec careful-seahorse -- ls -al /share
# Attempt to create file /share/test3.txt inside the container as user 1000 and group 1000.
incus exec careful-seahorse --group 1000 --user 1000 -- touch /share/test3.txt
# Display the contents of the mounted path inside the container.
incus exec careful-seahorse -- ls -al /share
# Display the contents of the mounted path inside the container replacing user and group names with their numeric IDs.
incus exec careful-seahorse -- ls -aln /share
# Display the contents of the source host directory.
ls -la /mnt/incus/share
# Remove file created during test.
rm /mnt/incus/share/test3.txt
# Remove the mounted host directory "share" from the container.
incus config device remove careful-seahorse share
Output:
derek@yoga-3-pro:~/Documents$ ./incus_test_mount_host_directory_with_shift_true
+ uname -a
Linux yoga-3-pro 6.5.0-0.deb12.4-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.5.10-1~bpo12+1 (2023-11-23) x86_64 GNU/Linux
+ incus list
+------------------+---------+----------------------+-----------------------------------------------+-----------+-----------+
| NAME | STATE | IPV4 | IPV6 | TYPE | SNAPSHOTS |
+------------------+---------+----------------------+-----------------------------------------------+-----------+-----------+
| careful-seahorse | RUNNING | 10.158.47.161 (eth0) | fd42:6f5d:75b3:70fc:216:3eff:fe74:222e (eth0) | CONTAINER | 0 |
+------------------+---------+----------------------+-----------------------------------------------+-----------+-----------+
+ id
uid=1000(derek) gid=1000(derek) groups=1000(derek),4(adm),20(dialout),21(fax),24(cdrom),25(floppy),26(tape),27(sudo),29(audio),30(dip),44(video),46(plugdev),100(users),106(netdev),110(lpadmin),115(bluetooth),123(scanner),992(incus-admin)
+ ls -la /mnt/incus/share
total 16
drwxr-xr-x 2 derek derek 4096 Feb 12 12:46 .
drwxr-xr-x 3 root root 4096 Feb 9 13:50 ..
-rw-r--r-- 1 derek derek 7 Feb 9 14:06 test1.txt
-rw-rw-r-- 1 derek derek 7 Feb 9 14:05 test2.txt
+ incus exec careful-seahorse -- ls -al /share
ls: cannot access '/share': No such file or directory
+ incus exec careful-seahorse --group 1000 --user 1000 -- id
uid=1000(ubuntu) gid=1000(ubuntu) groups=1000(ubuntu)
+ incus config device add careful-seahorse share disk source=/mnt/incus/share path=/share shift=true
Device share added to careful-seahorse
+ incus exec careful-seahorse -- ls -al /share
total 12
drwxr-xr-x 2 ubuntu ubuntu 4096 Feb 12 17:46 .
drwxr-xr-x 1 root root 164 Feb 12 18:04 ..
-rw-r--r-- 1 ubuntu ubuntu 7 Feb 9 19:06 test1.txt
-rw-rw-r-- 1 ubuntu ubuntu 7 Feb 9 19:05 test2.txt
+ incus exec careful-seahorse --group 1000 --user 1000 -- touch /share/test3.txt
+ incus exec careful-seahorse -- ls -al /share
total 12
drwxr-xr-x 2 ubuntu ubuntu 4096 Feb 12 18:04 .
drwxr-xr-x 1 root root 164 Feb 12 18:04 ..
-rw-r--r-- 1 ubuntu ubuntu 7 Feb 9 19:06 test1.txt
-rw-rw-r-- 1 ubuntu ubuntu 7 Feb 9 19:05 test2.txt
-rw-r--r-- 1 ubuntu ubuntu 0 Feb 12 18:04 test3.txt
+ incus exec careful-seahorse -- ls -aln /share
total 12
drwxr-xr-x 2 1000 1000 4096 Feb 12 18:04 .
drwxr-xr-x 1 0 0 164 Feb 12 18:04 ..
-rw-r--r-- 1 1000 1000 7 Feb 9 19:06 test1.txt
-rw-rw-r-- 1 1000 1000 7 Feb 9 19:05 test2.txt
-rw-r--r-- 1 1000 1000 0 Feb 12 18:04 test3.txt
+ ls -la /mnt/incus/share
total 16
drwxr-xr-x 2 derek derek 4096 Feb 12 13:04 .
drwxr-xr-x 3 root root 4096 Feb 9 13:50 ..
-rw-r--r-- 1 derek derek 7 Feb 9 14:06 test1.txt
-rw-rw-r-- 1 derek derek 7 Feb 9 14:05 test2.txt
-rw-r--r-- 1 derek derek 0 Feb 12 13:04 test3.txt
+ rm /mnt/incus/share/test3.txt
+ incus config device remove careful-seahorse share
Device share removed from careful-seahorse
Notice that on the host, user derek (ID 1000) and group derek (ID 1000) own the files in /mnt/incus/share
and inside the container, user ubuntu (ID 1000) and group ubuntu (ID 1000) own the files in /share
. Inside and outside the container, the owners of the files have the same user and group IDs.