2023-02-25 17:15:23 +01:00
|
|
|
#!/bin/sh
|
2023-06-28 23:42:40 +02:00
|
|
|
# Remap all files uid/gid to a new range using fuidshift
|
|
|
|
#
|
|
|
|
# This is a wrapper around `fuidshift` from `lxd-tools` Debian package for my use-case of LVM based root disks.
|
2023-02-25 17:15:23 +01:00
|
|
|
#
|
|
|
|
|
|
|
|
usage () {
|
|
|
|
echo "remap-uid-and-gid <container-name> [<target-lv>]"
|
|
|
|
printf "\nIf <target-lv> is not given it is computed from a default value with the given container name\n"
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
2023-06-28 23:42:40 +02:00
|
|
|
if [ "$(which fuidshift)" = "" ]; then
|
|
|
|
echo "fuidshift binary not found. Please install lxd-tools package."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2023-02-25 17:15:23 +01:00
|
|
|
CONTAINER_NAME="${1}"
|
2023-06-28 23:42:40 +02:00
|
|
|
if [ "${CONTAINER_NAME}" = "" ] || [ "${CONTAINER_NAME}" = "--help" ] || [ "${CONTAINER_NAME}" = "-h" ]; then
|
2023-02-25 17:15:23 +01:00
|
|
|
usage
|
|
|
|
fi
|
|
|
|
|
|
|
|
TARGET_LV="${2}"
|
|
|
|
if [ "${TARGET_LV}" = "" ]; then
|
|
|
|
GUESSED_LV="/dev/mapper/daffy--vg-lxc--${CONTAINER_NAME}"
|
|
|
|
if [ -e "${GUESSED_LV}" ]; then
|
|
|
|
TARGET_LV="${GUESSED_LV}"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
if [ "${TARGET_LV}" = "" ]; then
|
|
|
|
usage
|
|
|
|
fi
|
|
|
|
|
|
|
|
if mount | grep -qF " on /mnt"; then
|
|
|
|
echo "Mountpoint /mnt is already in use."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
mount "${TARGET_LV}" /mnt
|
|
|
|
|
2023-06-28 23:42:40 +02:00
|
|
|
# we get e.g. lxc.idmap = u 0 1000000 65535 and want u:0:1000000:65535
|
|
|
|
USER_NAMESPACE=$(get-lxc-idmap-config u $CONTAINER_NAME | sed -r -e 's/.*= (.*)/\1/' -e 's/ /:/g')
|
|
|
|
GROUP_NAMESPACE=$(get-lxc-idmap-config g $CONTAINER_NAME | sed -r -e 's/.*= (.*)/\1/' -e 's/ /:/g')
|
2023-02-25 17:15:23 +01:00
|
|
|
|
2023-06-28 23:42:40 +02:00
|
|
|
printf "fuidshift %s %s %s\n" /mnt $USER_NAMESPACE $GROUP_NAMESPACE
|
|
|
|
# fuidshift /mnt $USER_NAMESPACE $GROUP_NAMESPACE
|
2023-02-25 17:15:23 +01:00
|
|
|
|
|
|
|
cd /
|
|
|
|
umount /mnt
|