4 # the name of the floppy based network configuration
5 # files (checked first). the name planet.cnf is kept
6 # for backward compatibility with old nodes, and only
7 # the floppy disk is searched for files with this name.
8 # new files are named plnode.txt and can be located on
9 # a floppy or usb device or on the cdrom
10 OLD_NODE_CONF_NAME=planet.cnf
11 NEW_NODE_CONF_NAME=plnode.txt
13 # one location of cd-based network configuration file
14 # (checked if floppy conf file missing and usb
15 # configuration file is missing)
16 CD_NET_CONF_BOOT=/usr/boot/$NEW_NODE_CONF_NAME
18 # the other location of cd-based network configuration file
19 CD_NET_CONF_ROOT=/usr/$NEW_NODE_CONF_NAME
21 # if all other network configuration file sources
22 # don't exist, fall back to this one (always on the cd)
23 FALLBACK_NET_CONF=/usr/boot/default-node.txt
25 # a temporary place to hold the old configuration file
26 # off of the floppy disk if we find it (so we don't have
27 # to remount the floppy later)
28 TMP_OLD_FLOPPY_CONF_FILE=/tmp/oldfloppy_planet.cnf
30 # once a configuration file is found, save it in /tmp
31 # (may be used later by boot scripts)
32 USED_NET_CONF=/tmp/planet.cnf
34 # default device to use for contacting PLC if not specified
35 # in the configuration file
38 # where to store the temporary dhclient conf file
39 DHCLIENT_CONF_FILE=/tmp/dhclient.conf
41 # which fs types we support finding node configuration files on
42 # (will be based as a -t parameter to mount)
43 NODE_CONF_DEVICE_FS_TYPES="msdos,ext2"
45 # a temporary place to mount devices that might contain configuration
47 CONF_DEVICE_MOUNT_POINT=/mnt/confdevice
48 /bin/mkdir -p $CONF_DEVICE_MOUNT_POINT
50 # for some backwards compatibility, save the ifconfig <device>
51 # output to this file after everything is online
52 IFCONFIG_OUTPUT=/tmp/ifconfig
54 # set to 1 if the default network configuration was loaded off the cd
55 # (no other configuration file found)
62 echo $(date "+%H:%M:%S") " pl_netinit: network initialization failed,"
63 echo $(date "+%H:%M:%S") " pl_netinit: shutting down machine in two hours"
69 # Function for checking the IP address to see if its sensible.
73 "" | *[!0-9.]* | *[!0-9]) return 1 ;;
78 [ ${1:-666} -le 255 ] && [ ${2:-666} -le 255 ] &&
79 [ ${3:-666} -le 255 ] && [ ${4:-666} -le 255 ]
82 # find and parse a node network configuration file. return 0 if not found,
83 # return 1 if found and parsed. if this is the case, DEFAULT_NET_CONF will
84 # be set to 1. For any found configuration file, $USED_NET_CONF will
85 # contain the validated contents
88 /bin/rm -f $TMP_OLD_FLOPPY_CONF_FILE 2>&1 > /dev/null
90 echo $(date "+%H:%M:%S") " pl_netinit: looking for node configuration file on floppy"
92 /bin/mount -o ro -t $NODE_CONF_DEVICE_FS_TYPES /dev/fd0 \
93 $CONF_DEVICE_MOUNT_POINT 2>&1 > /dev/null
94 if [[ $? -eq 0 ]]; then
96 # 1. check for new named file first on the floppy disk
97 if [ -r "$CONF_DEVICE_MOUNT_POINT/$NEW_NODE_CONF_NAME" ]; then
98 conf_file="$CONF_DEVICE_MOUNT_POINT/$NEW_NODE_CONF_NAME"
99 echo $(date "+%H:%M:%S") " pl_netinit: found node configuration file $conf_file"
100 /etc/init.d/pl_validateconf < $conf_file > $USED_NET_CONF
101 /bin/umount $CONF_DEVICE_MOUNT_POINT
104 # since we have the floppy mounted already, see if an old file
105 # exists there so we don't have to remount the floppy when we need
106 # to check for an old file on it (later in the order). if it does
107 # just copy it off to a special location
108 elif [ -r "$CONF_DEVICE_MOUNT_POINT/$OLD_NODE_CONF_NAME" ]; then
109 conf_file="$CONF_DEVICE_MOUNT_POINT/$OLD_NODE_CONF_NAME"
110 /bin/cp -f $conf_file $TMP_OLD_FLOPPY_CONF_FILE
111 echo $(date "+%H:%M:%S") " pl_netinit: found old named configuration file, checking later."
113 echo $(date "+%H:%M:%S") " pl_netinit: floppy mounted, but no configuration file."
116 /bin/umount $CONF_DEVICE_MOUNT_POINT
118 echo $(date "+%H:%M:%S") " pl_netinit: no floppy could be mounted, continuing search."
121 # 2. check for a new named file on removable flash devices (those
122 # that start with sd*, because usb_storage emulates scsi devices).
123 # to prevent checking normal scsi disks, also make sure
124 # /sys/block/<dev>/removable is set to 1
126 echo $(date "+%H:%M:%S") " pl_netinit: looking for node configuration file on flash based devices"
128 # make the sd* hd* expansion fail to an empty string if there are no sd
132 for device in /sys/block/[hsv]d*; do
133 removable=$(cat $device/removable)
134 if [[ $removable -ne 1 ]]; then
138 partitions=$(/bin/awk "\$4 ~ /$(basename $device)[0-9]*/ { print \$4 }" /proc/partitions)
139 for partition in $partitions ; do
140 check_dev=/dev/$partition
142 echo $(date "+%H:%M:%S") " pl_netinit: looking for node configuration file on device $check_dev"
143 /bin/mount -o ro -t $NODE_CONF_DEVICE_FS_TYPES $check_dev \
144 $CONF_DEVICE_MOUNT_POINT 2>&1 > /dev/null
145 if [[ $? -eq 0 ]]; then
146 if [ -r "$CONF_DEVICE_MOUNT_POINT/$NEW_NODE_CONF_NAME" ]; then
147 conf_file="$CONF_DEVICE_MOUNT_POINT/$NEW_NODE_CONF_NAME"
148 echo $(date "+%H:%M:%S") " pl_netinit: found node configuration file $conf_file"
149 /etc/init.d/pl_validateconf < $conf_file > $USED_NET_CONF
150 echo $(date "+%H:%M:%S") " pl_netinit: found configuration"
151 /bin/umount $CONF_DEVICE_MOUNT_POINT
155 echo $(date "+%H:%M:%S") " pl_netinit: not found"
157 /bin/umount $CONF_DEVICE_MOUNT_POINT
162 # normal filename expansion setting
165 # 3. see if there is an old file on the floppy disk. if there was,
166 # the file $TMP_OLD_FLOPPY_CONF_FILE will be readable.
167 if [ -r "$TMP_OLD_FLOPPY_CONF_FILE" ]; then
168 conf_file=$TMP_OLD_FLOPPY_CONF_FILE
169 echo $(date "+%H:%M:%S") " pl_netinit: found node configuration file $conf_file"
170 /etc/init.d/pl_validateconf < $conf_file > $USED_NET_CONF
175 # 4. check for plnode.txt on the cd at /usr/boot
176 echo $(date "+%H:%M:%S") " pl_netinit: looking for network configuration on cd in /usr/boot"
177 if [ -r "$CD_NET_CONF_BOOT" ]; then
179 echo $(date "+%H:%M:%S") " pl_netinit: found cd configuration file $CD_NET_BOOT_CONF"
180 /etc/init.d/pl_validateconf < $CD_NET_CONF_BOOT > $USED_NET_CONF
185 # 5. check for plnode.txt on the cd at /usr
186 echo $(date "+%H:%M:%S") " pl_netinit: looking for network configuration on cd in /usr"
187 if [ -r "$CD_NET_CONF_ROOT" ]; then
189 echo $(date "+%H:%M:%S") " pl_netinit: found cd configuration file $CD_NET_CONF_ROOT"
190 /etc/init.d/pl_validateconf < $CD_NET_CONF_ROOT > $USED_NET_CONF
195 # 6. no node configuration file could be found, fall back to
196 # builtin default. this can't be used to install a machine, but
197 # will at least let it download and run the boot manager, which
198 # can inform the users appropriately.
199 echo $(date "+%H:%M:%S") " pl_netinit: using default network configuration"
200 if [ -r "$FALLBACK_NET_CONF" ]; then
201 echo $(date "+%H:%M:%S") " pl_netinit: found cd default configuration file $FALLBACK_NET_CONF"
202 /etc/init.d/pl_validateconf < $FALLBACK_NET_CONF > $USED_NET_CONF
211 echo $(date "+%H:%M:%S") " pl_netinit: bringing loopback network device up"
212 /sbin/ifconfig lo 127.0.0.1 up
215 if [ $? -eq 0 ]; then
216 # no network configuration file found. this should not happen as the
217 # default cd image has a backup one. halt.
218 echo $(date "+%H:%M:%S") " pl_netinit: unable to find even a default network configuration"
219 echo $(date "+%H:%M:%S") " pl_netinit: file, this cd may be corrupt."
223 # load the configuration file. if it was a default one (not user specified),
224 # then remove the saved copy from /tmp, but continue on. since a network
225 # configuration file is required and boot scripts only know about this location
226 # they will fail (as they should) - but the network will be up if dhcp is
229 echo $(date "+%H:%M:%S") " pl_netinit: loading network configuration"
232 if [[ $DEFAULT_NET_CONF -eq 1 ]]; then
233 /bin/rm -f $USED_NET_CONF
236 # initialize IPMI device
237 if [[ -n "$IPMI_ADDRESS" ]] ; then
238 echo -n "pl_netinit: initializing IPMI: "
239 cmd="ipnmac -i $IPMI_ADDRESS"
240 if [[ -n "$IPMI_MAC" ]] ; then
241 cmd="$cmd -m $IPMI_MAC"
247 # now, we need to find which device to use (ie, eth0 or eth1). start out
248 # by defaulting to eth0, then see if the network configuration file specified
249 # either a mac address (in which case we will need to find the device), or
253 if [[ -n "$NET_DEVICE" ]]; then
254 # the user specified a mac address we should use. find the network
256 NET_DEVICE=$(tr A-Z a-z <<<$NET_DEVICE)
260 dev_address=$(cat $device/address | tr A-Z a-z)
261 if [ "$device" == "$NET_DEVICE" -o "$dev_address" == "$NET_DEVICE" ]; then
263 echo $(date "+%H:%M:%S") " pl_netinit: found device $ETH_DEVICE with mac address $dev_address"
270 # if we didn't find a device yet, check which is the primary
271 if [[ -z "$ETH_DEVICE" ]]; then
272 pushd /etc/sysconfig/network-scripts > /dev/null
273 for conf in ifcfg-*; do
274 egrep -q '^PRIMARY=["'"'"']?[yY1t]' $conf || continue
275 ETH_DEVICE=${conf#ifcfg-}
281 # still nothing? fail the boot.
282 if [[ -z "$ETH_DEVICE" ]]; then
283 echo $(date "+%H:%M:%S") " pl_netinit: unable to find a usable device, check to make sure"
284 echo $(date "+%H:%M:%S") " pl_netinit: the NET_DEVICE field in the configuration file"
285 echo $(date "+%H:%M:%S") " pl_netinit: corresponds with a network adapter on this system"
290 # actually check to make sure ifconfig <device> succeeds
291 /sbin/ifconfig $ETH_DEVICE up 2>&1 > /dev/null
292 if [[ $? -ne 0 ]]; then
293 echo $(date "+%H:%M:%S") " pl_netinit: device $ETH_DEVICE does not exist, most likely"
294 echo $(date "+%H:%M:%S") " pl_netinit: this CD does not have hardware support for your"
295 echo $(date "+%H:%M:%S") " pl_netinit: network adapter. please send the following lines"
296 echo $(date "+%H:%M:%S") " pl_netinit: to your PlanetLab support for further assistance"
298 /sbin/lspci -n | /bin/grep "Class 0200"
304 echo $(date "+%H:%M:%S") " pl_netinit: attempting to start networking"
305 /sbin/service network start
307 # for backwards compatibility
308 /sbin/ifconfig $ETH_DEVICE > $IFCONFIG_OUTPUT
310 echo $(date "+%H:%M:%S") " pl_netinit: network online"