1 From e951deaaeeb2b7badc5a6f53c6af18c1504289ee Mon Sep 17 00:00:00 2001
2 From: Riccardo Murri <riccardo.murri@gmail.com>
3 Date: Fri, 19 Jun 2015 17:50:52 +0200
4 Subject: [PATCH] Allow selecting boot eth dev by MAC address
7 components/9990-select-eth-device.sh | 101 +++++++++++++++++++++--------------
8 1 file changed, 61 insertions(+), 40 deletions(-)
10 diff --git a/components/9990-select-eth-device.sh b/components/9990-select-eth-device.sh
11 index df00666..6bc67fd 100755
12 --- a/components/9990-select-eth-device.sh
13 +++ b/components/9990-select-eth-device.sh
14 @@ -49,21 +49,32 @@ Select_eth_device ()
18 - # If user force to use specific device, write it
19 - for ARGUMENT in ${LIVE_BOOT_CMDLINE}
21 - case "${ARGUMENT}" in
23 - NETDEV="${ARGUMENT#live-netdev=}"
24 - echo "DEVICE=$NETDEV" >> /conf/param.conf
25 - echo "Found live-netdev parameter, forcing to to use network device $NETDEV."
31 - l_interfaces="$DEVICE"
33 + # If user force to use specific device, write it
34 + for ARGUMENT in ${LIVE_BOOT_CMDLINE}
36 + case "${ARGUMENT}" in
38 + NETDEV="${ARGUMENT#live-netdev=}"
39 + # net device could be specified by MAC address
40 + hex="[0-9A-Fa-f][0-9A-Fa-f]"
42 + ${hex}:${hex}:${hex}:${hex}:${hex}:${hex})
43 + # MAC address; record it and select later
44 + netdev_mac_addr="${NETDEV}"
48 + echo "DEVICE=$NETDEV" >> /conf/param.conf
49 + echo "Found live-netdev parameter, forcing to to use network device $NETDEV."
57 + l_interfaces="$DEVICE"
62 @@ -79,30 +90,40 @@ Select_eth_device ()
66 - for step in 1 2 3 4 5
68 - for interface in $l_interfaces
70 - carrier=$(cat /sys/class/net/$interface/carrier \
73 + for step in 1 2 3 4 5
75 + for interface in $l_interfaces
77 + if [ -z "$netdev_mac_addr" ]; then
78 + carrier=$(cat /sys/class/net/$interface/carrier \
82 - case "${carrier}" in
84 - echo "Connected $interface found"
85 - # inform initrd's init script :
86 - found_eth_dev="$found_eth_dev $interface"
90 - if [ -n "$found_eth_dev" ]
92 - echo "DEVICE='$found_eth_dev'" >> /conf/param.conf
100 + case "${carrier}" in
102 + echo "Connected $interface found"
103 + # inform initrd's init script :
104 + found_eth_dev="$found_eth_dev $interface"
108 + # MAC addr given, check for that
109 + mac_addr=$(ifconfig "$interface" \
111 + | { read _ _ _ _ mac_addr; echo $mac_addr; })
112 + if [ "$mac_addr" = "$netdev_mac_addr" ]; then
113 + found_eth_dev="$interface"
117 + if [ -n "$found_eth_dev" ]
119 + echo "DEVICE='$found_eth_dev'" >> /conf/param.conf