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" ]
57 modprobe -q af_packet # For DHCP
62 [ -n "$ETHDEV_TIMEOUT" ] || ETHDEV_TIMEOUT=15
63 echo "Using timeout of $ETHDEV_TIMEOUT seconds for network configuration."
65 if [ -z "${NETBOOT}" ] && [ -z "${FETCH}" ] && [ -z "${HTTPFS}" ] && [ -z "${FTPFS}" ]
67 # See if we can select the device from BOOTIF
70 # if ethdevice was not specified on the kernel command line
71 # make sure we try to get a working network configuration
72 # for *every* present network device (except for loopback of course)
73 if [ -z "$ETHDEVICE" ]
75 echo "If you want to boot from a specific device use bootoption ethdevice=..."
76 for device in /sys/class/net/*
81 ETHDEVICE="$ETHDEVICE $dev"
86 # split args of ethdevice=eth0,eth1 into "eth0 eth1"
87 for device in $(echo $ETHDEVICE | sed 's/,/ /g')
89 devlist="$devlist $device"
94 echo "Executing ipconfig -t $ETHDEV_TIMEOUT $dev"
95 ipconfig -t "$ETHDEV_TIMEOUT" $dev | tee -a /netboot.config
97 # if configuration of device worked we should have an assigned
98 # IP address, if so let's use the device as $DEVICE for later usage.
99 # simple and primitive approach which seems to work fine
100 if ifconfig $dev | grep -q -E 'inet.*addr:|inet [0-9][0-9]*.[0-9][0-9]*.[0-9][0-9]*.[0-9][0-9]*'
107 for interface in ${DEVICE}; do
108 ipconfig -t "$ETHDEV_TIMEOUT" ${interface} | tee /netboot-${interface}.config
110 [ -e /run/net-${interface}.conf ] && . /run/net-${interface}.conf
112 if [ "$IPV4ADDR" != "0.0.0.0" ]
119 for interface in ${DEVICE}
121 # source relevant ipconfig output
122 OLDHOSTNAME=${HOSTNAME}
124 [ -e /run/net-${interface}.conf ] && . /run/net-${interface}.conf
126 [ -z ${HOSTNAME} ] && HOSTNAME=${OLDHOSTNAME}
129 if [ -n "${interface}" ]
131 HWADDR="$(cat /sys/class/net/${interface}/address)"
134 if [ ! -e "/etc/resolv.conf" ]
136 echo "Creating /etc/resolv.conf"
138 if [ -n "${DNSDOMAIN}" ]
140 echo "domain ${DNSDOMAIN}" > /etc/resolv.conf
141 echo "search ${DNSDOMAIN}" >> /etc/resolv.conf
144 for i in ${IPV4DNS0} ${IPV4DNS1} ${IPV4DNS1} ${DNSSERVERS}
146 if [ -n "$i" ] && [ "$i" != 0.0.0.0 ]
148 echo "nameserver $i" >> /etc/resolv.conf
153 # Check if we have a network device at all
154 if ! ls /sys/class/net/"$interface" > /dev/null 2>&1 && \
155 ! ls /sys/class/net/eth0 > /dev/null 2>&1 && \
156 ! ls /sys/class/net/wlan0 > /dev/null 2>&1 && \
157 ! ls /sys/class/net/ath0 > /dev/null 2>&1 && \
158 ! ls /sys/class/net/ra0 > /dev/null 2>&1
160 panic "No supported network device found, maybe a non-mainline driver is required."