summaryrefslogtreecommitdiffstats
path: root/remote
diff options
context:
space:
mode:
authorChristian Rößler2015-09-04 18:55:59 +0200
committerChristian Rößler2015-09-04 18:55:59 +0200
commit4e7beb644eb1ee82b377daeef84fc675b138ea7c (patch)
treeb91988a1760f8ebfc2ce0c4aa98b478c8b87d3ee /remote
parent[xorg] xserver-xorg-video-sis (not sis-usb) deleted from ubuntu.conf, as (diff)
downloadtm-scripts-4e7beb644eb1ee82b377daeef84fc675b138ea7c.tar.gz
tm-scripts-4e7beb644eb1ee82b377daeef84fc675b138ea7c.tar.xz
tm-scripts-4e7beb644eb1ee82b377daeef84fc675b138ea7c.zip
[chroot] WARNING: NEEDS BETTER TESTING! Adapted to new overlayfs mount syntax.
Diffstat (limited to 'remote')
-rw-r--r--remote/includes/chroot.inc52
1 files changed, 42 insertions, 10 deletions
diff --git a/remote/includes/chroot.inc b/remote/includes/chroot.inc
index 146d7e7e..5461898f 100644
--- a/remote/includes/chroot.inc
+++ b/remote/includes/chroot.inc
@@ -21,20 +21,27 @@ declare -rg CHROOT_BINDDIR="${CHROOT_TEMPDIR}/rootbind"
declare -rg CHROOT_LOWERDIR="/"
declare -rg CHROOT_BINDMOUNTS="/dev /proc /sys /run"
+
# Helper function to setup the directory structure
chroot_prepare_dirs() {
# first check if CHROOT_TEMPDIR exists
if [ -d "${CHROOT_TEMPDIR}" ]; then
# try to umount and rmdir CHROOT_MOUNTDIR
umount "${CHROOT_MOUNTDIR}" 2>/dev/null
- rmdir "${CHROOT_MOUNTDIR}" || perror "Could not remove '${CHROOT_MOUNTDIR}', meaning it has stuff in it. Aborting..."
+ if [ -d "${CHROOT_MOUNTDIR}" ]; then
+ rmdir "${CHROOT_MOUNTDIR}" || perror "Could not remove CHROOT_MOUNTDIR '${CHROOT_MOUNTDIR}', meaning it has stuff in it. Aborting..."
+ fi
# try to umount and rmdir CHROOT_BINDDIR
umount "${CHROOT_BINDDIR}" 2>/dev/null
- rmdir "${CHROOT_BINDDIR}" || perror "Could not remove '${CHROOT_BINDDIR}', meaning it has stuff in it. Aborting..."
+ if [ -d "${CHROOT_BINDDIR}" ]; then
+ rmdir "${CHROOT_BINDDIR}" || perror "Could not remove CHROOT_BINDDIR '${CHROOT_BINDDIR}', meaning it has stuff in it. Aborting..."
+ fi
# try to rmdir CHROOT_TEMPDIR
- rmdir "${CHROOT_TEMPDIR}" || perror "Could not remove '${CHROOT_TEMPDIR}', meaning it has stuff in it. Aborting..."
+ if [ -d "${CHROOT_TEMPDIR}" ]; then
+ rmdir "${CHROOT_TEMPDIR}" || perror "Could not remove CHROOT_TEMPDIR '${CHROOT_TEMPDIR}', meaning it has stuff in it. Aborting..."
+ fi
fi
mkdir -p "${CHROOT_TEMPDIR}" || perror "Could not create base directory for mount directories $CHROOT_TEMPDIR."
@@ -50,20 +57,36 @@ chroot_prepare_dirs() {
chroot_prepare_mounts() {
# first mount / on CHROOT_BINDDIR and remount read-only
- mount -o bind "${CHROOT_LOWERDIR}" "${CHROOT_BINDDIR}" || perror "Could not bind-mount '$CHROOT_LOWERDIR' to '$CHROOT_BINDDIR'."
- mount -o remount,ro,bind "${CHROOT_BINDDIR}" || perror "Could not remount '$CHROOT_BINDDIR' read-only."
+ mount -o bind "${CHROOT_LOWERDIR}" "${CHROOT_BINDDIR}" \
+ || perror "Could not bind-mount CHROOT_LOWERDIR '$CHROOT_LOWERDIR' to CHROOT_BINDDIR '$CHROOT_BINDDIR'."
+ mount -o remount,ro,bind "${CHROOT_BINDDIR}" || perror "Could not remount CHROOT_BINDDIR '$CHROOT_BINDDIR' read-only."
# check that it really is read-only
- [ "x$(mount | grep -E "^/ on ${CHROOT_BINDDIR}" | grep -v '\(.*ro.*\)')" != "x" ] && perror "'${CHROOT_BINDDIR}' is not read-only! Aborting..."
+ [ "x$(mount | grep -E "^/ on ${CHROOT_BINDDIR}" | grep -v '\(.*ro.*\)')" != "x" ] \
+ && perror "CHROOT_BINDDIR '${CHROOT_BINDDIR}' is not read-only! Aborting..."
# safe, go on to make the overlay
- mount -t overlayfs overlayfs -o lowerdir="${CHROOT_BINDDIR}",upperdir="${CHROOT_UPPERDIR}" "${CHROOT_MOUNTDIR}" \
- || perror "Could not mount (overlayfs) $CHROOT_LOWERDIR, $CHROOT_UPPERDIR to $CHROOT_BINDDIR."
+ pinfo "Now mounting overlayfs. Trying old mount syntax (up to Kernel 3.13) ..."
+ mount -t overlayfs overlayfs -o lowerdir="${CHROOT_BINDDIR}",upperdir="${CHROOT_UPPERDIR}" "${CHROOT_MOUNTDIR}" 2>/dev/null
+ if [ $? -ne 0 ]; then
+ pinfo "Old mount syntax failed. Trying mount syntax (Kernel 3.19+) ..."
+ # We have to use a overlayfs workdir which _must_ be on the same filesystem as CHROOT_UPPERDIR. So
+ # we traverse to the directory below CHROOT_UPPERDIR and mkdir/mktemp a workdir there. In the possible
+ # case that CHROOT_UPPERDIR is the root dir of a filesystem there's nothing we can do.
+ CHROOT_WORKDIR="$(mktemp -d $(dirname ${CHROOT_UPPERDIR})/workdirXXX)" \
+ || perror "Could not mkdir overlayfs workdir $CHROOT_WORKDIR for new overlayfs mount syntax."
+ # Now we try to mount the overlayfs in the new fashion:
+ mount -t overlayfs overlayfs -o lowerdir="$CHROOT_LOWERDIR",upperdir="${CHROOT_UPPERDIR}",workdir="${CHROOT_WORKDIR}" "${CHROOT_MOUNTDIR}" \
+ || perror "Could not mount (overlayfs) $CHROOT_LOWERDIR, $CHROOT_UPPERDIR to $CHROOT_BINDDIR."
+ pinfo "New overlayfs mount syntax has worked, commencing."
+ else
+ pinfo "Old overlayfs mount syntax has worked, commencing."
+ fi
- # mount pseudo-filesystems
+ # mount pseudo-filesystems
for DIR in $CHROOT_BINDMOUNTS; do
mount -o bind "${DIR}" "${CHROOT_MOUNTDIR}/${DIR}" \
- || perror "Could not bind mount '$DIR' into '$CHROOT_MOUNTDIR/$DIR'."
+ || perror "Could not bind mount '$DIR' into CHROOT_MOUNTDIR/DIR '$CHROOT_MOUNTDIR/$DIR'."
done
}
@@ -211,4 +234,13 @@ chroot_cleanup_mounts() {
else
pinfo "Nothing chroot-related is mounted - exiting."
fi
+
+ if [ -d "${CHROOT_WORKDIR}" ]; then
+ # Too much of a coward to rm -rf somewhere. Both directories have to be empty so we use rmdir.
+ rmdir "${CHROOT_WORKDIR}/work" && pinfo "rmdir-ed CHROOT_WORKDIR/work ${CHROOT_WORKDIR}/work needed for new overlayfs mount syntax." \
+ || pinfo "Could not rmdir CHROOT_WORKDIR/work ${CHROOT_WORKDIR}/work - clean it by hand."
+ rmdir "${CHROOT_WORKDIR}" && pinfo "rmdir-ed CHROOT_WORKDIR ${CHROOT_WORKDIR} needed for new overlayfs mount syntax." \
+ || pinfo "Could not rmdir CHROOT_WORKDIR ${CHROOT_WORKDIR} needed for new overlayfs mount syntax - clean by hand."
+ umount overlayfs
+ fi
}