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" ]
58 modprobe -q af_packet # For DHCP
63 [ -n "$ETHDEV_TIMEOUT" ] || ETHDEV_TIMEOUT=15
64 echo "Using timeout of $ETHDEV_TIMEOUT seconds for network configuration."
66 if [ -z "${NETBOOT}" ] && [ -z "${FETCH}" ] && [ -z "${HTTPFS}" ] && [ -z "${FTPFS}" ]
68 # See if we can select the device from BOOTIF
71 # if ethdevice was not specified on the kernel command line
72 # make sure we try to get a working network configuration
73 # for *every* present network device (except for loopback of course)
74 if [ -z "$ETHDEVICE" ]
76 echo "If you want to boot from a specific device use bootoption ethdevice=..."
77 for device in /sys/class/net/*
82 ETHDEVICE="$ETHDEVICE $dev"
87 # split args of ethdevice=eth0,eth1 into "eth0 eth1"
88 for device in $(echo $ETHDEVICE | sed 's/,/ /g')
90 devlist="$devlist $device"
93 # this is tricky (and ugly) because ipconfig sometimes just hangs/runs into
94 # an endless loop; if execution fails give it two further tries, that's
95 # why we use '$devlist $devlist $devlist' for the other for loop
96 for dev in $devlist $devlist $devlist
98 echo "Executing ipconfig -t $ETHDEV_TIMEOUT $dev"
99 ipconfig -t "$ETHDEV_TIMEOUT" $dev | tee -a /netboot.config &
101 sleep "$ETHDEV_TIMEOUT" ; sleep 1
102 if [ -r /proc/"$jobid"/status ]
104 echo "Killing job $jobid for device $dev as ipconfig ran into recursion..."
108 # if configuration of device worked we should have an assigned
109 # IP address, if so let's use the device as $DEVICE for later usage.
110 # simple and primitive approach which seems to work fine
111 if ifconfig $dev | grep -q 'inet.*addr:'
118 for interface in ${DEVICE}; do
119 ipconfig -t "$ETHDEV_TIMEOUT" ${interface} | tee /netboot-${interface}.config
121 [ -e /run/net-${interface}.conf ] && . /run/net-${interface}.conf
123 if [ "$IPV4ADDR" != "0.0.0.0" ]
130 for interface in ${DEVICE}
132 # source relevant ipconfig output
133 OLDHOSTNAME=${HOSTNAME}
135 [ -e /run/net-${interface}.conf ] && . /run/net-${interface}.conf
137 [ -z ${HOSTNAME} ] && HOSTNAME=${OLDHOSTNAME}
140 if [ -n "${interface}" ]
142 HWADDR="$(cat /sys/class/net/${interface}/address)"
145 if [ ! -e "/etc/resolv.conf" ]
147 echo "Creating /etc/resolv.conf"
149 if [ -n "${DNSDOMAIN}" ]
151 echo "domain ${DNSDOMAIN}" > /etc/resolv.conf
152 echo "search ${DNSDOMAIN}" >> /etc/resolv.conf
155 for i in ${IPV4DNS0} ${IPV4DNS1} ${IPV4DNS1}
157 if [ -n "$i" ] && [ "$i" != 0.0.0.0 ]
159 echo "nameserver $i" >> /etc/resolv.conf
164 # Check if we have a network device at all
165 if ! ls /sys/class/net/"$interface" > /dev/null 2>&1 && \
166 ! ls /sys/class/net/eth0 > /dev/null 2>&1 && \
167 ! ls /sys/class/net/wlan0 > /dev/null 2>&1 && \
168 ! ls /sys/class/net/ath0 > /dev/null 2>&1 && \
169 ! ls /sys/class/net/ra0 > /dev/null 2>&1
171 panic "No supported network device found, maybe a non-mainline driver is required."