revise installation of e/n/i file
[rrq/overlay-boot.git] / functions
index 0b01df810cd0504583bb79261146a83edb9b472d..8c1b45c048706c91a2923f451c5065040c0224f6 100644 (file)
--- 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 <<EOF > $UPPER/etc/network/interfaces
+    [ -r $1/etc/network/interfaces ] && return 0
+    mkdir -p $1/etc/network
+    cat <<EOF >> $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 <<EOF >> $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 <<EOF >> $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"