Add bind-mount for /etc/adjtime to make subhost use host clock without ado
[rrq/overlay-boot.git] / overlay-share
1 #!/bin/bash
2 #
3 # Share a directory tree with an overlay-boot subhost
4 #
5 # $1 = directory $2 = subhost
6
7 set -e
8
9 . $(dirname $(realpath $0))/functions
10
11 if [ ! -d "$1" ] ; then
12    echo "** Not a directory: $1" >&2
13    exit 1
14 fi
15
16 SHARE="$1"
17 NAME="$2"
18
19 [ -z "$NAME" ] && echo "Select subhost: $(list_running)" && exit 0
20
21 read USPID RSPID <<EOF
22 $(is_live $NAME)
23 EOF
24 [ -z "$USPID" ] && echo "$NAME is not running" >&2 && exit 1
25 if [ -z "$RSPID" ] ; then
26     cat <<EOF >&2
27 ***  $NAME is started (pid $USPID) but doesn't seem to be running
28 *** /.reaper and might need manual fixing.
29 EOF
30     exit 1
31 fi
32
33 sudo nsenter -t "$RSPID" -n -m -p /bin/bash <<EOF
34 set -e
35 LIVE=\$(awk '\$1=="$NAME" && \$3=="overlay" {print \$2;}' < /proc/mounts)
36 [ -d "\$LIVE" ] && mount --bind $SHARE "\$LIVE$SHARE"
37 EOF
38 echo "Sharing $SHARE with subhost $NAME"
39 exit 0