7 # support for Syslinux IPAPPEND parameter
8 # it sets the BOOTIF variable on the kernel parameter
12 # pxelinux sets BOOTIF to a value based on the mac address of the
13 # network card used to PXE boot, so use this value for DEVICE rather
14 # than a hard-coded device name from initramfs.conf. this facilitates
15 # network booting when machines may have multiple network cards.
16 # pxelinux sets BOOTIF to 01-$mac_address
18 # strip off the leading "01-", which isn't part of the mac
22 # convert to typical mac address format by replacing "-" with ":"
27 if [ -z "$bootif_mac" ]
31 bootif_mac="$bootif_mac:$x"
36 # look for devices with matching mac address, and set DEVICE to
37 # appropriate value if match is found.
39 for device in /sys/class/net/*
41 if [ -f "$device/address" ]
43 current_mac=$(cat "$device/address")
45 if [ "$bootif_mac" = "$current_mac" ]
47 ETHDEVICE="${device##*/},$ETHDEVICE" # use ethdevice
58 echo "Missin parameter for $0"
62 for ip in ${STATICIP} ; do
75 modprobe -q af_packet # For DHCP
80 [ -n "$ETHDEV_TIMEOUT" ] || ETHDEV_TIMEOUT=15
81 echo "Using timeout of $ETHDEV_TIMEOUT seconds for network configuration."
83 # Our modus operandi for getting a working network setup is this:
84 # * If ip=* is set, pass that to ipconfig and be done
85 # * Else, try dhcp on all devices in this order:
86 # ethdevice= bootif= <all interfaces>
88 ALLDEVICES="$(cd /sys/class/net/ && ls -1 2>/dev/null | grep -v '^lo$' )"
90 # Turn on all interfaces before doing anything, to avoid timing problems
91 # during link negotiation.
92 echo "Net: Turning on all device links..."
93 for device in ${ALLDEVICES}; do
94 ipconfig -c none -d $device -t 1 2>/dev/null >/dev/null
97 # See if we can select the device from BOOTIF
100 # if ethdevice was not specified on the kernel command line
101 # make sure we try to get a working network configuration
102 # for *every* present network device (except for loopback of course)
103 if [ -z "$ETHDEVICE" ]
105 echo "If you want to boot from a specific device use bootoption ethdevice=..."
106 ETHDEVICE="$ALLDEVICES"
109 # split args of ethdevice=eth0,eth1 into "eth0 eth1"
110 for device in $(echo $ETHDEVICE | sed 's/,/ /g')
112 devlist="$devlist $device"
115 for dev in $devlist ; do
116 param="$(get_ipconfig_para $dev)"
117 if [ -n "$NODHCP" ] && [ "$param" = "$dev" ] ; then
118 echo "Ignoring network device $dev due to nodhcp." | tee -a /boot.log
121 echo "Executing ipconfig -t $ETHDEV_TIMEOUT $param"
122 ipconfig -t "$ETHDEV_TIMEOUT" "$param" | tee -a /netboot.config
124 # if configuration of device worked we should have an assigned
125 # IP address, if so let's use the device as $DEVICE for later usage.
126 # simple and primitive approach which seems to work fine
129 if [ -e "/run/net-${device}.conf" ]; then
130 . /run/net-${device}.conf
132 if [ "${IPV4ADDR}" != "0.0.0.0" ]; then
133 export DEVICE="$dev $DEVICE"
134 # break # exit loop as we just use the irst
139 for interface in ${DEVICE}
141 # source relevant ipconfig output
142 OLDHOSTNAME=${HOSTNAME}
144 [ -e /run/net-${interface}.conf ] && . /run/net-${interface}.conf
146 [ -z ${HOSTNAME} ] && HOSTNAME=${OLDHOSTNAME}
149 if [ -n "${interface}" ]
151 HWADDR="$(cat /sys/class/net/${interface}/address)"
154 if [ ! -e "/etc/resolv.conf" ]
156 echo "Creating /etc/resolv.conf"
158 if [ -n "${DNSDOMAIN}" ]
160 echo "domain ${DNSDOMAIN}" > /etc/resolv.conf
161 echo "search ${DNSDOMAIN}" >> /etc/resolv.conf
164 for i in ${IPV4DNS0} ${IPV4DNS1} ${IPV4DNS1} ${DNSSERVERS}
166 if [ -n "$i" ] && [ "$i" != 0.0.0.0 ]
168 echo "nameserver $i" >> /etc/resolv.conf
173 # Check if we have a network device at all
174 if ! ls /sys/class/net/"$interface" > /dev/null 2>&1 && \
175 ! ls /sys/class/net/eth0 > /dev/null 2>&1 && \
176 ! ls /sys/class/net/wlan0 > /dev/null 2>&1 && \
177 ! ls /sys/class/net/ath0 > /dev/null 2>&1 && \
178 ! ls /sys/class/net/ra0 > /dev/null 2>&1
180 panic "No supported network device found, maybe a non-mainline driver is required."