X-Git-Url: https://git.rrq.au/?a=blobdiff_plain;f=functions;h=8c1b45c048706c91a2923f451c5065040c0224f6;hb=7c240a57cac965924a90d04a24473a0387c36089;hp=0b01df810cd0504583bb79261146a83edb9b472d;hpb=a3b6bd2a94624852e5fef890fda9fde9548080f3;p=rrq%2Foverlay-boot.git diff --git a/functions b/functions index 0b01df8..8c1b45c 100644 --- a/functions +++ b/functions @@ -15,18 +15,22 @@ config() { eval echo "$1=\$$1" } -# Unless the subhost already has a private /etc/network/interfaces, -# install an "empty" one +# Install a default $1/etc/network/interfaces on the subhost root $1 setup_networking() { - [ -r $UPPER/etc/network/interfaces ] && return 0 - [ "$UPPER/etc/network" = "/etc/network" ] && exit 1 - mkdir -p $UPPER/etc/network - cat < $UPPER/etc/network/interfaces + [ -r $1/etc/network/interfaces ] && return 0 + mkdir -p $1/etc/network + cat <> $1/etc/network/interfaces # Generated for $NAME subhost auto lo iface lo inet loopback EOF - return 1 + for IF in $(ip netns exec $NAME ip link show | grep "^eth") ; do + cat <> $1/etc/network/interfaces + +auto eth$i +iface eth$i inet manual +EOF + done } # Setup the network namespace for the given $CABLES @@ -36,19 +40,12 @@ setup_veth_cables() { NETNS="$1" shift 1 i=0 - ADD=false - setup_networking || ADD=true for C in "$@" ; do IF=$NETNS$i MAC="${C#*=}" [ -z "$MAC" ] || MAC="address $MAC" ip link add $IF type veth peer name eth$i $MAC netns $NETNS ip link set $IF up - $ADD && cat <> $UPPER/etc/network/interfaces - -auto eth$i -iface eth$i inet manual -EOF BR="${C%=*}" if [ -z "$BR" ] ; then ip link set $IF @@ -118,10 +115,11 @@ setup_overlay() { mkdir "$UPPER/dev/pts" chmod 1777 "$UPPER/dev/shm" + # all good so far ; now avoid using the host's networking setup + setup_networking "$UPPER" + OLY="-olowerdir=$3,upperdir=$UPPER,workdir=$5" - if mount -t overlay "$OLY" $1 $2 ; then - : # all good - else + if ! mount -t overlay "$OLY" $1 $2 ; then umount -R "$UPPER/dev" umount "$UPPER/run" die "Cannot set up the overlay mount $2"