7 modprobe -q af_packet # For DHCP
12 [ -n "$ETHDEV_TIMEOUT" ] || ETHDEV_TIMEOUT=15
13 echo "Using timeout of $ETHDEV_TIMEOUT seconds for network configuration."
15 if [ -z "${NETBOOT}" ] && [ -z "${FETCH}" ] && \
16 [ -z "${HTTPFS}" ] && [ -z "${FTPFS}" ]
20 # support for Syslinux IPAPPEND parameter
21 # it sets the BOOTIF variable on the kernel parameter
25 # pxelinux sets BOOTIF to a value based on the mac address of the
26 # network card used to PXE boot, so use this value for DEVICE rather
27 # than a hard-coded device name from initramfs.conf. this facilitates
28 # network booting when machines may have multiple network cards.
29 # pxelinux sets BOOTIF to 01-$mac_address
31 # strip off the leading "01-", which isn't part of the mac
35 # convert to typical mac address format by replacing "-" with ":"
40 if [ -z "$bootif_mac" ]
44 bootif_mac="$bootif_mac:$x"
49 # look for devices with matching mac address, and set DEVICE to
50 # appropriate value if match is found.
52 for device in /sys/class/net/*
54 if [ -f "$device/address" ]
56 current_mac=$(cat "$device/address")
58 if [ "$bootif_mac" = "$current_mac" ]
67 # if ethdevice was not specified on the kernel command line
68 # make sure we try to get a working network configuration
69 # for *every* present network device (except for loopback of course)
70 if [ -z "$ETHDEVICE" ] ; then
71 echo "If you want to boot from a specific device use bootoption ethdevice=..."
72 for device in /sys/class/net/*; do
74 if [ "$dev" != "lo" ] ; then
75 ETHDEVICE="$ETHDEVICE $dev"
80 # split args of ethdevice=eth0,eth1 into "eth0 eth1"
81 for device in $(echo $ETHDEVICE | sed 's/,/ /g') ; do
82 devlist="$devlist $device"
85 # this is tricky (and ugly) because ipconfig sometimes just hangs/runs into
86 # an endless loop; if execution fails give it two further tries, that's
87 # why we use '$devlist $devlist $devlist' for the other for loop
88 for dev in $devlist $devlist $devlist ; do
89 echo "Executing ipconfig -t $ETHDEV_TIMEOUT $dev"
90 ipconfig -t "$ETHDEV_TIMEOUT" $dev | tee -a /netboot.config &
92 sleep "$ETHDEV_TIMEOUT" ; sleep 1
93 if [ -r /proc/"$jobid"/status ] ; then
94 echo "Killing job $jobid for device $dev as ipconfig ran into recursion..."
98 # if configuration of device worked we should have an assigned
99 # IP address, if so let's use the device as $DEVICE for later usage.
100 # simple and primitive approach which seems to work fine
101 if ifconfig $dev | grep -q 'inet.*addr:' ; then
108 for interface in ${DEVICE}; do
109 ipconfig -t "$ETHDEV_TIMEOUT" ${interface} | tee /netboot-${interface}.config
110 [ -e /tmp/net-${interface}.conf ] && . /tmp/net-${interface}.conf
111 if [ "$IPV4ADDR" != "0.0.0.0" ]
118 for interface in ${DEVICE}; do
119 # source relevant ipconfig output
120 OLDHOSTNAME=${HOSTNAME}
121 [ -e /tmp/net-${interface}.conf ] && . /tmp/net-${interface}.conf
122 [ -z ${HOSTNAME} ] && HOSTNAME=${OLDHOSTNAME}
125 if [ -n "${interface}" ]
127 HWADDR="$(cat /sys/class/net/${interface}/address)"
130 if [ ! -e "/etc/resolv.conf" ]
132 echo "Creating /etc/resolv.conf"
134 if [ -n "${DNSDOMAIN}" ]
136 echo "domain ${DNSDOMAIN}" > /etc/resolv.conf
137 echo "search ${DNSDOMAIN}" >> /etc/resolv.conf
140 for i in ${IPV4DNS0} ${IPV4DNS1} ${IPV4DNS1}
142 if [ -n "$i" ] && [ "$i" != 0.0.0.0 ]
144 echo "nameserver $i" >> /etc/resolv.conf
149 # Check if we have a network device at all
150 if ! ls /sys/class/net/"$interface" > /dev/null 2>&1 && \
151 ! ls /sys/class/net/eth0 > /dev/null 2>&1 && \
152 ! ls /sys/class/net/wlan0 > /dev/null 2>&1 && \
153 ! ls /sys/class/net/ath0 > /dev/null 2>&1 && \
154 ! ls /sys/class/net/ra0 > /dev/null 2>&1
156 panic "No supported network device found, maybe a non-mainline driver is required."