Add bind-mount for /etc/adjtime to make subhost use host clock without ado
[rrq/overlay-boot.git] / overlay-boot
1 #!/bin/sh
2 #
3 # This boot scripts runs a service subhost as defined by the
4 # configuration file named on the command line.
5 # See "man overlay-boot" for details.
6
7 set -x
8 PROGRAMDIR="$(dirname $(realpath $0))"
9 . $PROGRAMDIR/functions
10
11 subhost_name $1
12
13 if [ -z "$UNSHARED" ] ; then
14     if [ ! -r /run/netns/$NAME ] ; then
15         ip netns add $NAME
16         ip netns exec $NAME ip link set lo up || exit 1
17     fi
18     exec env UNSHARED=yes unshare -m $0 $@ > $LOG 2>&1 &
19     echo "Logging to $LOG" >&2
20     exit 0
21 fi
22
23 subhost_config
24 setup_veth_cables $NAME $CABLES
25 setup_overlay "$NAME" "$LIVE" "$LOWER" "$UPPER" "$WORK"
26 setup_cgroup2_accounting "$NAME" "$$"
27
28 exithandler() {
29     ip netns del $NAME
30     [ "$UPPER" != "$LIVE" ] && umount -R "$LIVE"
31 }
32 trap "exithandler" 0
33
34 # This process has an unshared mount namespace, so we unmount almost
35 # everything before chroot. Exceptions are: $LIVE and anything mounted
36 # below that, "/run/netns/$NAME" and its parent paths (incidentally
37 # including "/" as well) and "/proc".
38 sort -rk2,2 < /proc/mounts | while read D P A2 ; do
39     beginswith "$P" "$LIVE" && continue
40     beginswith "$P" "$(realpath $LIVE)" && continue
41     beginswith "/run/netns/$NAME" "$P" && continue
42     [ "$P" = /proc ] && continue
43     umount "$P"
44 done
45
46 echo "Starting $NAME"
47 env CONFIG="$CONFIG" $INIT | \
48     unshare -fp --mount-proc -i -u \
49             ip netns exec $NAME chroot $LIVE /bin/sh
50 echo "Exited $NAME"