summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2013-08-14 19:00:37 +0200
committerSimon Rettberg2013-08-14 19:00:37 +0200
commit7f78ad7d5e868c6d1a5779f02041c3269faa8953 (patch)
treef1df36c8fbcbd91c825884e5ae27bd884ce9f9b4
parentMerge branch 'master' of simonslx:openslx-ng/tm-scripts (diff)
downloadtm-scripts-7f78ad7d5e868c6d1a5779f02041c3269faa8953.tar.gz
tm-scripts-7f78ad7d5e868c6d1a5779f02041c3269faa8953.tar.xz
tm-scripts-7f78ad7d5e868c6d1a5779f02041c3269faa8953.zip
[roofs-stage31] fix network setup if multiple NICs are present
-rwxr-xr-xremote/rootfs/rootfs-stage31/data/bin/setup_network85
-rwxr-xr-xremote/rootfs/rootfs-stage31/data/init28
2 files changed, 63 insertions, 50 deletions
diff --git a/remote/rootfs/rootfs-stage31/data/bin/setup_network b/remote/rootfs/rootfs-stage31/data/bin/setup_network
index 8aedeaf1..93ecd75f 100755
--- a/remote/rootfs/rootfs-stage31/data/bin/setup_network
+++ b/remote/rootfs/rootfs-stage31/data/bin/setup_network
@@ -1,6 +1,6 @@
#!/bin/sh
-echo "Mac address is '$MAC'"
+echo "Main MAC address is '$MAC'"
# setup network
@@ -11,44 +11,59 @@ ip addr add 127.0.0.1/8 dev lo 2>/dev/null
echo "Setting up bridge"
BRIDGE="br0"
-SLAVE="eth0"
-BRIDGEMAC="$MAC"
# Following was supposed to prevent scripts from getting confused by multiple interfaces with same MAC - does not work though
## Flip mac address of original interface - this var is not local so init sees the changes too
#MAC="$(echo "$MAC" | awk -F ':' '{printf $1 ":" $2 ":" $5 ":" $3 ":" $6 ":" $4}')"
#ip link set addr "$MAC" "$SLAVE"
-brctl addbr "$BRIDGE" || drop_shell "Could not create bridge $BRIDGE"
-brctl stp "$BRIDGE" 0
-brctl setfd "$BRIDGE" 0.000000000001
-ip link set addr "$BRIDGEMAC" "$BRIDGE" || drop_shell "Could not set mac of $BRIDGE"
-ip link set dev "$SLAVE" up
-brctl addif "$BRIDGE" "$SLAVE" || drop_shell "Could not add $SLAVE to $BRIDGE"
-
-# analyze ip information from the kernel command line and put parts
-# of it into several variables
-if [ -n "$IPINFO" ] ; then
- getip () {
- local val="$IPINFO:"; i=$(($1 - 1));
- while [ $i -gt 0 ] ; do
- val=${val#*:} ; i=$(($i - 1));
- done;
- echo $val|sed "s/:.*//";
- }
- CLIENTIP="$(getip 1)"
- SERVERIP="$(getip 2)"
- GATEWAY="$(getip 3)"
- SUBNET_MASK="$(getip 4)"
- BROADCAST_ADDRESS="$(ipcalc -s -b "$CLIENTIP" "$SUBNET_MASK" | sed s/.*=//)"
- [ -z "$BROADCAST_ADDRESS" ] && BROADCAST_ADDRESS="255.255.255.255"
- # we might have an idea of the dns server via preboot
- DNS_SERVER="$(getip 5)"
- # set static ip address
- ip addr add "$CLIENTIP/$(ipcalc -s -p "$CLIENTIP" "$SUBNET_MASK" | sed "s/.*=//")" broadcast "$BROADCAST_ADDRESS" dev "$BRIDGE"
- ip link set dev "$BRIDGE" up
- ip route add default via "$GATEWAY" dev "$BRIDGE"
-else
- NOIPYET="yes"
-fi
+mkdir -p "${FUTURE_ROOT}/etc/udev/rules.d"
+
+#IP_OUT=$(ip a | sed -r ':a;N;$!ba;s/: ([a-z0-9]+): /####\1####/g;s/ether ([a-f0-9:]+) /####\1####/g'| grep -E -o '####[^ ]+####' | sed 's/#//g' | grep -B 1 ':')
+IP_OUT=$(ip a | grep -B 1 "/ether" | sed -r '/^--$/d;$!N;s#^[0-9]+: ([a-z0-9\.:]+): .*?/ether ([0-9a-fA-Z:]+) .*$#\1==\2#')
+
+for LINE in $IP_OUT; do
+ IFACE=$(echo "$LINE" | awk -F '==' '{printf $1}')
+ IFMAC=$(echo "$LINE" | awk -F '==' '{printf $2}' | tr '[a-z]' '[A-Z]')
+ echo "${IFACE} = ${IFMAC}"
+
+ if [ "x$IFMAC" == "x$MAC" ]; then
+ brctl addbr "$BRIDGE" || drop_shell "Could not create bridge $BRIDGE"
+ brctl stp "$BRIDGE" 0
+ brctl setfd "$BRIDGE" 0.000000000001
+ ip link set addr "$IFMAC" "$BRIDGE" || drop_shell "Could not set mac of $BRIDGE"
+ ip link set dev "$IFACE" up
+ brctl addif "$BRIDGE" "$IFACE" || drop_shell "Could not add $IFACE to $BRIDGE"
+
+ # analyze ip information from the kernel command line and put parts
+ # of it into several variables
+ if [ -n "$IPINFO" ] ; then
+ getip () {
+ local val="$IPINFO:"; i=$(($1 - 1));
+ while [ $i -gt 0 ] ; do
+ val=${val#*:} ; i=$(($i - 1));
+ done;
+ echo $val|sed "s/:.*//";
+ }
+ CLIENTIP="$(getip 1)"
+ SERVERIP="$(getip 2)"
+ GATEWAY="$(getip 3)"
+ SUBNET_MASK="$(getip 4)"
+ BROADCAST_ADDRESS="$(ipcalc -s -b "$CLIENTIP" "$SUBNET_MASK" | sed s/.*=//)"
+ [ -z "$BROADCAST_ADDRESS" ] && BROADCAST_ADDRESS="255.255.255.255"
+ # we might have an idea of the dns server via preboot
+ DNS_SERVER="$(getip 5)"
+ # set static ip address
+ ip addr add "$CLIENTIP/$(ipcalc -s -p "$CLIENTIP" "$SUBNET_MASK" | sed "s/.*=//")" broadcast "$BROADCAST_ADDRESS" dev "$BRIDGE"
+ ip link set dev "$BRIDGE" up
+ ip route add default via "$GATEWAY" dev "$BRIDGE"
+ else
+ NOIPYET="yes"
+ fi
+ fi
+ # youdev
+ echo "SUBSYSTEM==\"net\", ACTION==\"add\", DRIVERS==\"?*\", ATTR{address}==\"$IFMAC\", ATTR{dev_id}==\"0x0\", ATTR{type}==\"1\", KERNEL==\"eth*\", NAME=\"$IFACE\"" >> "${FUTURE_ROOT}/etc/udev/rules.d/70-net-boot-nic-name.rules"
+ # continue...
+ IFACE=""
+done
diff --git a/remote/rootfs/rootfs-stage31/data/init b/remote/rootfs/rootfs-stage31/data/init
index 23a1f0d5..db394c8d 100755
--- a/remote/rootfs/rootfs-stage31/data/init
+++ b/remote/rootfs/rootfs-stage31/data/init
@@ -28,6 +28,12 @@ mount -n -t tmpfs -o 'mode=755' run "/run"
[ ! -f /proc/cpuinfo ] && mount -n -t proc proc /proc
[ ! -d /sys/class ] && mount -n -t sysfs sysfs /sys
+# preparations for mounting stage3.2
+FUTURE_ROOT="/dev/shm/uniontmp"
+mkdir -p "$FUTURE_ROOT" /rorootfs
+mount -n -t tmpfs none "$FUTURE_ROOT"
+mkdir -p "$FUTURE_ROOT/opt/openslx"
+
# let kernel know that mdev is to be used for hotplug
echo "/sbin/mdev" > /proc/sys/kernel/hotplug
@@ -41,14 +47,14 @@ for DRM in /lib/modules/*/kernel/drivers/gpu/drm/*.ko /lib/modules/*/kernel/driv
done
# discover devices
-mdev -s &
+mdev -s
# read kernel command line for debugging switch
DEBUG=0
read KCL < /proc/cmdline
export KCL
for opts in ${KCL}; do
- case ${opts} in
+ case "${opts}" in
debug=*)
DEBUG=${opts#debug=} ;;
splash*)
@@ -62,7 +68,7 @@ for opts in ${KCL}; do
export NFSSERVER=${nfs%:/*}
;;
BOOTIF=*)
- export MAC="$( echo "$opts" | cut -b 11- | tr '-' ':' )" ;;
+ export MAC="$( echo "$opts" | cut -b 11- | tr '-' ':' | tr '[a-z]' '[A-Z]' )" ;;
esac
done
@@ -75,13 +81,9 @@ if [ "x$SPLASH" == "x1" -a "x$DEBUG" != "x1" ]; then
plymouthd && plymouth show-splash
fi
-# preparations for mounting stage3.2
-mkdir -p /dev/shm/uniontmp /rorootfs
-mount -n -t tmpfs none /dev/shm/uniontmp
-mkdir -p /dev/shm/uniontmp/opt/openslx
echo "Copying busybox etc. to stage32..."
-tar -cp "/bin" "/sbin" "/usr/bin" "/usr/sbin" | tar -xp -C /dev/shm/uniontmp/opt/openslx/
+tar -cp "/bin" "/sbin" "/usr/bin" "/usr/sbin" | tar -xp -C "${FUTURE_ROOT}/opt/openslx/"
[ $DEBUG -ge 4 ] && drop_shell "Requested Debug Shell (before network)."
@@ -103,9 +105,10 @@ fi
echo "Building aufs..."
#mount -t overlayfs -o lowerdir=/rorootfs,upperdir=/dev/shm/uniontmp overlayfs /mnt
-mount -n -t aufs -o br:/dev/shm/uniontmp:/rorootfs=ro none /mnt || drop_shell "Problem building aufs."
+mount -n -t aufs -o "br:${FUTURE_ROOT}:/rorootfs=ro" none /mnt || drop_shell "Problem building aufs."
mkdir -p /mnt/opt/openslx/uniontmp /mnt/tmp
-mount -n --move /dev/shm/uniontmp /mnt/opt/openslx/uniontmp || drop_shell "Problem moving uniontmp."
+mount -n --move "$FUTURE_ROOT" /mnt/opt/openslx/uniontmp || drop_shell "Problem moving uniontmp."
+FUTURE_ROOT="/mnt"
[ $DEBUG -ge 2 ] && drop_shell "Requested Debug Shell: after aufs'ing."
@@ -124,11 +127,6 @@ if [ -e /mnt/opt/openslx/config ]; then
fi
fi
-# create udev rule for nic we booted from
-cat > "/mnt/etc/udev/rules.d/70-net-boot-nic-name.rules" <<HEREEND
-SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="$MAC", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"
-HEREEND
-
# create ip config
cat >> /mnt/opt/openslx/config <<HEREEND
# IP Config written in stage31