From: Ralph Ronnquist Date: Mon, 21 Mar 2022 03:28:35 +0000 (+1100) Subject: improved subhost mounting X-Git-Tag: deb_0.1~26 X-Git-Url: https://git.rrq.au/?a=commitdiff_plain;h=fef769fc5a66825081639490a6567f9df8f43193;p=rrq%2Foverlay-boot.git improved subhost mounting --- diff --git a/functions b/functions index 1d52d74..38e8725 100644 --- a/functions +++ b/functions @@ -60,21 +60,47 @@ REAPER=$(dirname $(realpath $0))/reaper/reaper # Set up an overlay fmr $name on $live, with a new tmpfs on its /run, # and "install" a "reaper" as the upcoming pid 1 setup_overlay() { - set -x - mkdir -p $4/run - mount -t tmpfs -osize=100M tmpfs $4/run - mkdir -p $4/run/lock - grep -q "$1 $2" /proc/mounts || \ - mount -t overlay -olowerdir=$3,upperdir=$4,workdir=$5 $1 $2 || \ - die "Cannot set up the overlay mount $2" - mount --bind $4/run $2/run - cp $REAPER $LIVE/.reaper -} + local ROOT="$4" + local LIVE="$2" + if grep -q "$1 $2" /proc/mounts ; then + die "$1 is already mounted" + fi -# Check if $SRV is "live" ; will -is_live() { - pgrep -f ".reaper $SRV" > /dev/null + # setup $ROOT/run + mkdir -p "$ROOT/run" + mount -t tmpfs -osize=100M tmpfs "$ROOT/run" + mkdir -p "$ROOT/run/lock" + # setup $ROOT/dev + mkdir -p "$ROOT/dev" + mount -t tmpfs -osize=100M tmpfs "$ROOT/dev" + mknod -m 622 "$ROOT/dev/console" c 5 1 + mknod -m 666 "$ROOT/dev/null" c 1 3 + mknod -m 666 "$ROOT/dev/zero" c 1 5 + mknod -m 666 "$ROOT/dev/ptmx" c 5 2 + mknod -m 666 "$ROOT/dev/tty" c 5 0 + mknod -m 444 "$ROOT/dev/random" c 1 8 + mknod -m 444 "$ROOT/dev/urandom" c 1 9 + chown root:tty "$ROOT/dev/console" + chown root:tty "$ROOT/dev/ptmx" + chown root:tty "$ROOT/dev/tty" + ln -sTf /proc/self/fd "$ROOT/dev/fd" + ln -sTf /proc/self/fd/0 "$ROOT/dev/stdin" + ln -sTf /proc/self/fd/1 "$ROOT/dev/stdout" + ln -sTf /proc/self/fd/2 "$ROOT/dev/stderr" + ln -sTf /proc/kcore "$ROOT/dev/core" + mkdir "$ROOT/dev/shm" + mkdir "$ROOT/dev/pts" + chmod 1777 "$ROOT/dev/shm" + + if mount -t overlay -olowerdir=$3,upperdir=$4,workdir=$5 $1 $2 ; then + : # all good + else + umount -R "$ROOT/dev" + umount "$ROOT/run" + die "Cannot set up the overlay mount $2" + fi + cp $REAPER $LIVE/.reaper } start_services() { @@ -82,3 +108,17 @@ start_services() { service $S start done } + +# find the upperdir option for an overlay mount line +getupper() { + sed 's/.*upperdir=\([^,]*\).*/\1/' +} + +# Check if $1 is "live" and echo the +# unshare and reaper process pids +is_live() { + local NAME=$1 + local USPID="$(pgrep -f "unshare.* $NAME ")" + [ -z "$USPID" ] && return 1 + echo $USPID $(pgrep -f ".reaper $NAME") +}