[pve-devel] [PATCH container 2/2] mountpoint_insert_staged: inherit attributes if directory already exists

Filip Schauer f.schauer at proxmox.com
Tue Dec 16 19:08:52 CET 2025


Make mount points inherit the uid, gid, and access mode if the directory
already exists in the container file system. This makes setting up mount
points more convenient when attributes different from uid=0, gid=0,
mode=755 are required.

As an example, this ensures that directories like /app/data and
/app/cache in the docker.io/weblate/weblate OCI image retain the correct
permissions when adding mount points over them.

While not explicitly specified by the OCI spec, this matches the
behaviour of implementations such as Docker and Podman.

Signed-off-by: Filip Schauer <f.schauer at proxmox.com>
---
 src/PVE/LXC.pm | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/src/PVE/LXC.pm b/src/PVE/LXC.pm
index e5ff3a1..bf4899f 100644
--- a/src/PVE/LXC.pm
+++ b/src/PVE/LXC.pm
@@ -2130,6 +2130,13 @@ sub mountpoint_insert_staged {
 
     my $dest_fd = walk_tree_nofollow_fd('/', $rootdir_fd, $mp_dir, 1, $root_uid, $root_gid);
 
+    # Preserve attributes of destination directory
+    my ($mode, $uid, $gid) = (stat($dest_fd))[2, 4, 5];
+    PVE::Tools::fchownat(fileno($mount_fd), '', $uid, $gid, PVE::Tools::AT_EMPTY_PATH)
+        or die "failed to propagate uid and gid to mountpoint: $!\n";
+    PVE::Tools::fchmodat(fileno($mount_fd), '.', $mode, 0)
+        or die "failed to propagate access mode to mountpoint: $!\n";
+
     PVE::Tools::move_mount(
         fileno($mount_fd),
         '',
-- 
2.47.3





More information about the pve-devel mailing list