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)
59 function net_init_failed() {
61 echo $(date "+%H:%M:%S") " pl_netinit: network initialization failed,"
62 echo $(date "+%H:%M:%S") " pl_netinit: shutting down machine in two hours"
68 # Function for checking the IP address to see if its sensible.
71 "" | *[!0-9.]* | *[!0-9]) return 1 ;;
76 [ ${1:-666} -le 255 ] && [ ${2:-666} -le 255 ] &&
77 [ ${3:-666} -le 255 ] && [ ${4:-666} -le 255 ]
80 # find and parse a node network configuration file. return 0 if not found,
81 # return 1 if found and parsed. if this is the case, DEFAULT_NET_CONF will
82 # be set to 1. For any found configuration file, $USED_NET_CONF will
83 # contain the validated contents
84 function find_node_config() {
85 /bin/rm -f $TMP_OLD_FLOPPY_CONF_FILE 2>&1 > /dev/null
87 echo $(date "+%H:%M:%S") " pl_netinit: looking for node configuration file on floppy"
89 /bin/mount -o ro -t $NODE_CONF_DEVICE_FS_TYPES /dev/fd0 \
90 $CONF_DEVICE_MOUNT_POINT 2>&1 > /dev/null
91 if [[ $? -eq 0 ]]; then
93 # 1. check for new named file first on the floppy disk
94 if [ -r "$CONF_DEVICE_MOUNT_POINT/$NEW_NODE_CONF_NAME" ]; then
95 conf_file="$CONF_DEVICE_MOUNT_POINT/$NEW_NODE_CONF_NAME"
96 echo $(date "+%H:%M:%S") " pl_netinit: found node configuration file $conf_file"
97 /etc/init.d/pl_validateconf < $conf_file > $USED_NET_CONF
98 /bin/umount $CONF_DEVICE_MOUNT_POINT
101 # since we have the floppy mounted already, see if an old file
102 # exists there so we don't have to remount the floppy when we need
103 # to check for an old file on it (later in the order). if it does
104 # just copy it off to a special location
105 elif [ -r "$CONF_DEVICE_MOUNT_POINT/$OLD_NODE_CONF_NAME" ]; then
106 conf_file="$CONF_DEVICE_MOUNT_POINT/$OLD_NODE_CONF_NAME"
107 /bin/cp -f $conf_file $TMP_OLD_FLOPPY_CONF_FILE
108 echo $(date "+%H:%M:%S") " pl_netinit: found old named configuration file, checking later."
110 echo $(date "+%H:%M:%S") " pl_netinit: floppy mounted, but no configuration file."
113 /bin/umount $CONF_DEVICE_MOUNT_POINT
115 echo $(date "+%H:%M:%S") " pl_netinit: no floppy could be mounted, continuing search."
118 # 2. check for a new named file on removable flash devices (those
119 # that start with sd*, because usb_storage emulates scsi devices).
120 # to prevent checking normal scsi disks, also make sure
121 # /sys/block/<dev>/removable is set to 1
123 echo $(date "+%H:%M:%S") " pl_netinit: looking for node configuration file on flash based devices"
125 # make the sd* hd* expansion fail to an empty string if there are no sd
129 for device in /sys/block/[hsv]d*; do
130 removable=$(cat $device/removable)
131 if [[ $removable -ne 1 ]]; then
135 partitions=$(/bin/awk "\$4 ~ /$(basename $device)[0-9]*/ { print \$4 }" /proc/partitions)
136 for partition in $partitions ; do
137 check_dev=/dev/$partition
139 echo $(date "+%H:%M:%S") " pl_netinit: looking for node configuration file on device $check_dev"
140 /bin/mount -o ro -t $NODE_CONF_DEVICE_FS_TYPES $check_dev \
141 $CONF_DEVICE_MOUNT_POINT 2>&1 > /dev/null
142 if [[ $? -eq 0 ]]; then
143 if [ -r "$CONF_DEVICE_MOUNT_POINT/$NEW_NODE_CONF_NAME" ]; then
144 conf_file="$CONF_DEVICE_MOUNT_POINT/$NEW_NODE_CONF_NAME"
145 echo $(date "+%H:%M:%S") " pl_netinit: found node configuration file $conf_file"
146 /etc/init.d/pl_validateconf < $conf_file > $USED_NET_CONF
147 echo $(date "+%H:%M:%S") " pl_netinit: found configuration"
148 /bin/umount $CONF_DEVICE_MOUNT_POINT
152 echo $(date "+%H:%M:%S") " pl_netinit: not found"
154 /bin/umount $CONF_DEVICE_MOUNT_POINT
159 # normal filename expansion setting
162 # 3. see if there is an old file on the floppy disk. if there was,
163 # the file $TMP_OLD_FLOPPY_CONF_FILE will be readable.
164 if [ -r "$TMP_OLD_FLOPPY_CONF_FILE" ]; then
165 conf_file=$TMP_OLD_FLOPPY_CONF_FILE
166 echo $(date "+%H:%M:%S") " pl_netinit: found node configuration file $conf_file"
167 /etc/init.d/pl_validateconf < $conf_file > $USED_NET_CONF
172 # 4. check for plnode.txt on the cd at /usr/boot
173 echo $(date "+%H:%M:%S") " pl_netinit: looking for network configuration on cd in /usr/boot"
174 if [ -r "$CD_NET_CONF_BOOT" ]; then
176 echo $(date "+%H:%M:%S") " pl_netinit: found cd configuration file $CD_NET_BOOT_CONF"
177 /etc/init.d/pl_validateconf < $CD_NET_CONF_BOOT > $USED_NET_CONF
182 # 5. check for plnode.txt on the cd at /usr
183 echo $(date "+%H:%M:%S") " pl_netinit: looking for network configuration on cd in /usr"
184 if [ -r "$CD_NET_CONF_ROOT" ]; then
186 echo $(date "+%H:%M:%S") " pl_netinit: found cd configuration file $CD_NET_CONF_ROOT"
187 /etc/init.d/pl_validateconf < $CD_NET_CONF_ROOT > $USED_NET_CONF
192 # 6. no node configuration file could be found, fall back to
193 # builtin default. this can't be used to install a machine, but
194 # will at least let it download and run the boot manager, which
195 # can inform the users appropriately.
196 echo $(date "+%H:%M:%S") " pl_netinit: using default network configuration"
197 if [ -r "$FALLBACK_NET_CONF" ]; then
198 echo $(date "+%H:%M:%S") " pl_netinit: found cd default configuration file $FALLBACK_NET_CONF"
199 /etc/init.d/pl_validateconf < $FALLBACK_NET_CONF > $USED_NET_CONF
208 echo $(date "+%H:%M:%S") " pl_netinit: bringing loopback network device up"
209 /sbin/ifconfig lo 127.0.0.1 up
212 if [ $? -eq 0 ]; then
213 # no network configuration file found. this should not happen as the
214 # default cd image has a backup one. halt.
215 echo $(date "+%H:%M:%S") " pl_netinit: unable to find even a default network configuration"
216 echo $(date "+%H:%M:%S") " pl_netinit: file, this cd may be corrupt."
220 # load the configuration file. if it was a default one (not user specified),
221 # then remove the saved copy from /tmp, but continue on. since a network
222 # configuration file is required and boot scripts only know about this location
223 # they will fail (as they should) - but the network will be up if dhcp is
226 echo $(date "+%H:%M:%S") " pl_netinit: loading network configuration"
229 if [[ $DEFAULT_NET_CONF -eq 1 ]]; then
230 /bin/rm -f $USED_NET_CONF
233 # initialize IPMI device
234 if [[ -n "$IPMI_ADDRESS" ]] ; then
235 echo -n "pl_netinit: initializing IPMI: "
236 cmd="ipnmac -i $IPMI_ADDRESS"
237 if [[ -n "$IPMI_MAC" ]] ; then
238 cmd="$cmd -m $IPMI_MAC"
244 # now, we need to find which device to use (ie, eth0 or eth1). start out
245 # by defaulting to eth0, then see if the network configuration file specified
246 # either a mac address (in which case we will need to find the device), or
250 if [[ -n "$NET_DEVICE" ]]; then
251 # the user specified a mac address we should use. find the network
253 NET_DEVICE=$(tr A-Z a-z <<<$NET_DEVICE)
257 dev_address=$(cat $device/address | tr A-Z a-z)
258 if [ "$device" == "$NET_DEVICE" -o "$dev_address" == "$NET_DEVICE" ]; then
260 echo $(date "+%H:%M:%S") " pl_netinit: found device $ETH_DEVICE with mac address $dev_address"
267 # if we didn't find a device yet, check which is the primary
268 if [[ -z "$ETH_DEVICE" ]]; then
269 pushd /etc/sysconfig/network-scripts > /dev/null
270 for conf in ifcfg-*; do
271 egrep -q '^PRIMARY=["'"'"']?[yY1t]' $conf || continue
272 ETH_DEVICE=${conf#ifcfg-}
278 # still nothing? fail the boot.
279 if [[ -z "$ETH_DEVICE" ]]; then
280 echo $(date "+%H:%M:%S") " pl_netinit: unable to find a usable device, check to make sure"
281 echo $(date "+%H:%M:%S") " pl_netinit: the NET_DEVICE field in the configuration file"
282 echo $(date "+%H:%M:%S") " pl_netinit: corresponds with a network adapter on this system"
287 # actually check to make sure ifconfig <device> succeeds
288 /sbin/ifconfig $ETH_DEVICE up 2>&1 > /dev/null
289 if [[ $? -ne 0 ]]; then
290 echo $(date "+%H:%M:%S") " pl_netinit: device $ETH_DEVICE does not exist, most likely"
291 echo $(date "+%H:%M:%S") " pl_netinit: this CD does not have hardware support for your"
292 echo $(date "+%H:%M:%S") " pl_netinit: network adapter. please send the following lines"
293 echo $(date "+%H:%M:%S") " pl_netinit: to your PlanetLab support for further assistance"
295 /sbin/lspci -n | /bin/grep "Class 0200"
301 echo $(date "+%H:%M:%S") " pl_netinit: attempting to start networking"
302 /sbin/service network start
304 # for backwards compatibility
305 /sbin/ifconfig $ETH_DEVICE > $IFCONFIG_OUTPUT
307 echo $(date "+%H:%M:%S") " pl_netinit: network online"