I’ve setup a Debian GNU/Linux for LXC and its subuids. I created an unprivileged user account. I created and use an LXC container for that account with “dir” backend; and this deployed directories and files owned by correspondent subUIDs and subGIDs.
Now I’ve archived whole container structure (with tar) and I want to restore it into another computer, with same environment setup.
How do I deal with different subUIDs and subGIDs ranges in target, while the ported files are owned by unmatching ranges?
How can I move UIDs and GIDs in a filetree?
Supposing I have an Ext4 filesystem with a tree owned by UIDs range 100000-165535 , and I want to move it to UIDs range 200000-265535
How can I apply +100000 to every subdirectory and file in that tree?
You can first create the regular user under which the container is running in the source system in the target system. Replace the subuids/subgids of this user in the target system with ones in the source system. Add any entries required for this user in lxc-usernet file corresponding to source system in the target system. Create any bridge interface as required corresponding to the source system in the target system.
Shutdown the container in the source system and create a tar file of the full container directory (not rootfs alone).
Copy the tar file to target system and extract the container directory to where it should be as per lxc config of the target system. You should now be able to start the container.
Okay, I understand that I can tar and extract filesystem from inside source and target containers, both with guest’s plain UID/GID as seen 0-65535.