[SOLVED] Copying files from host machine to LXC

TekTexNavy

Member
May 1, 2022
4
0
6
Hi everyone,

Thanks in advance for reading. I had about 4 TB of videos I wanted on a samba server. The samba server is an Ubuntu 22.04 LXC and is working just fine. All of the videos were on my laptop so I moved them to an external HDD, plugged it in to the server, mounted it on the pve host and copied files directly from the USB external HDD to the zfs sub-volume being used as the samba movie share.
All that worked fine, but now the files "belong" to the pve host and not the Ubuntu lxc. How do I remedy this? Preferably without having to recopy 4TB of data.

The ubuntu lxc serving as the Samba server is CT-303 and it's shared volume is /zfspool1/subvol-303-disk-0. I mounted the external hdd to /root/usb4tb on the pve host and then:
mv /root/usb4tb/*.mp4 /zfspool1/subvol-303-disk-0
Now I can 'see' the files on the container, but they don't show up on the samba share and I can't modify permissions or ownership on them. On the lxc CT-303, the files copied from the USB HDD look like filename1 and filename2. Ones copied via the network look like filename0's permissions.
ls -l /shared/Movies
...
-rw-r----- 1 systemfiles allshares 15892849840 Jun 17 17:25 filename0.mp4
-rwxr-xr-x 1 nobody nogroup 23161293021 Jun 13 00:00 filename1.mp4
-rwxr-xr-x 1 nobody nogroup 11552721961 Jun 14 20:07 filename2.mp4
...
On the host, they look like this:
ls -l /zfspool1/subvol-303/disk-0
...
-rw-r----- 1 100999 101000 17702914003 Jun 25 16:02 filename0.mp4
-rwxr-xr-x 1 root root 13123613795 Jun 13 14:46 filename1.mp4
-rwxr-xr-x 1 root root 13123613795 Jun 13 14:46 filename2.mp4
...
Where, once again, filename0.mp4 was copied via the network and the other two from the USB drive. Is there someway from the PVE host I can just like "delegate" these files to the container? I found this reddit post. Will this do the trick? It recommends I do the following:
Here is how I handle my permissions. It's mainly targeted to containers, but maybe it can help you.

  1. Enable ACLs on your dataset: zfs set acltype=posixacl pool/mydataset
  2. Make a temporary dir: mkdir -p /pool/mydataset/demo and make it writeable for everybody with chmod a+rwx. Then write a file to it from your container or vm.
  3. get the UID and GID of that user who wrote the file (containers often have a UID / GID of 100000 for root) with ls -la
  4. Set the permissions you like via ACL: here is the script I use:
# Remove all permissions

sudo setfacl -R -b /pool/mydataset/demo

sudo chown -R root.root /pool/mydataset/demo

#Set permissions of main folders

sudo setfacl -R -m u::rwX,d:u::rwX,g::rwX,d:g::rwX,o:r-X,d:eek::r-X,u:root:rwX,d:u:root:rwX,u:100000:rwX,d:u:100000:rwX /pool/mydataset/demo

Replace the 100000 with the permissions you got with the method from above.
credit to reddit user pbengert

Thanks again in advance for any help.
 
If the unprivileged container is meant to be the only one directly accessing the files from the ZFS subvolume, you can just change the uid and gid of the files on the host with chown
Code:
chown 100999:101000 /zfspool1/subvol-303/disk-0/filename1.mp4

After this the file should belong to systemfiles:allshares within the container:
-rwxr-xr-x 1 systemfiles allshares 23161293021 Jun 13 00:00 filename1.mp4

To change the owner and group of all files recursively:
Code:
chown -R 100999:101000 /zfspool1/subvol-303/disk-0/*


Another approach would be to setup a separate user or group on the host to assign the files to.
Then a mapping to that user/group would need to be configured for the container.
Check the wiki for further explanation on container uid mapping:
https://pve.proxmox.com/wiki/Unprivileged_LXC_containers#Using_local_directory_bind_mount_points
 
  • Like
Reactions: TekTexNavy

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!