org_mounts="$(cat /proc/mounts)"# save the original mounts table
target="/overlay"
sudo mkdir -p /lower
sudo mount --bind / /lower
mounts+=("/lower")
sudo mount -t overlay overlay -o lowerdir=/lower,upperdir=/upper,workdir=/work "$target"# mount the overlayfs
mounts+=("/")
whileread line # bind-mount any mounts under the old rootfs into the new one (overlayfs isn't recursive like e.g. `mount --rbind`)
do
echo DOING $line
if["$line" !="/"]# except the rootfs base, to avoid infinite mountpoint loops
then
target="/overlay$line"
sudo mount --bind "$line""$target"|| true
mounts+=("$line")
fi
done < <(echo"$org_mounts"| cut -d" " -f2)
# remove the MS_SHARED flag from the original rootfs mount, which isn't supported by pivot_root(8) and would cause it to fail (see: https://lxc-users.linuxcontainers.narkive.com/pNQKxcnN/pivot-root-failures-when-is-mounted-as-shared)
sudo mount --make-rprivate /
# prepare for the pivot_root(8) and execute, swapping places of the original rootfs and the new one on overlayfs (with its lowerdir still being the original one)
# (what this achieves is committing the state of the original rootfs and making it read-only, while creating a new, virtual read-write rootfs with all changes written into a separate directory, the upperdir)
cd /overlay
sudo mkdir -p old
sudo pivot_root . old # once this finishes, the system is moved to the new rootfs and all newly open file descriptors will point to it
#sudo systemctl daemon-reexec
cd
mount
ls /home/runner
sudo touch /root_commited
exec"$ORG_PWD/$0""$@"
}
}
restore_roota(){
prepare_mounts(){
# create and mount the required volumes where they're expected
# in order to be able to build a diff rootfs tarball, we need to commit its initial state by moving it on-the-fly to overlayfs;
# in order to be able to build a diff rootfs tarball, we need to commit its initial state by moving it on-the-fly to overlayfs;
# below, we prepare the system and the new rootfs itself
# below, we prepare the system and the new rootfs itself
if ! [ -e /root_committed ]
if ! [ -e /root_committed ]
then
then
commit_root
commit_root
fi
fi
# -------- at this point, the original rootfs was committed and all the changes to it done below will be saved to the newly created rootfs diff tarball --------
# -------- at this point, the original rootfs was committed and all the changes to it done below will be saved to the newly created rootfs diff tarball --------
# install and set up the native dependencies needed
# install and set up the native dependencies needed