Adding upstream version 3.0~a7.
[live-boot-grml.git] / scripts / live
index f87919d..ad2d48e 100755 (executable)
@@ -68,6 +68,10 @@ Arguments ()
                                export DEFCONSOLE
                                ;;
 
+                       BOOTIF=*)
+                               BOOTIF="${x#BOOTIF=}"
+                               ;;
+
                        debug)
                                DEBUG="Yes"
                                export DEBUG
@@ -471,9 +475,6 @@ is_nice_device ()
        elif echo ${sysfs_path} | grep -q "^/block/dm-"
        then
                return 0
-       elif echo ${sysfs_path} | grep -q "^/block/mtdblock"
-       then
-               return 0
        fi
 
        return 1
@@ -580,10 +581,61 @@ do_netsetup ()
        udevadm trigger
        udevadm settle
 
+       [ -n "$ETHDEV_TIMEOUT" ] || ETHDEV_TIMEOUT=15
+       echo "Using timeout of $ETHDEV_TIMEOUT seconds for network configuration."
+
        if [ -z "${NETBOOT}" ] && [ -z "${FETCH}" ] && \
           [ -z "${HTTPFS}" ] && [ -z "${FTPFS}" ]
        then
 
+
+       # support for Syslinux IPAPPEND parameter
+       # it sets the BOOTIF variable on the kernel parameter
+
+       if [ -n "${BOOTIF}" ]
+       then
+               # pxelinux sets BOOTIF to a value based on the mac address of the
+               # network card used to PXE boot, so use this value for DEVICE rather
+               # than a hard-coded device name from initramfs.conf. this facilitates
+               # network booting when machines may have multiple network cards.
+               # pxelinux sets BOOTIF to 01-$mac_address
+
+               # strip off the leading "01-", which isn't part of the mac
+               # address
+               temp_mac=${BOOTIF#*-}
+
+               # convert to typical mac address format by replacing "-" with ":"
+               bootif_mac=""
+               IFS='-'
+               for x in $temp_mac
+               do
+                       if [ -z "$bootif_mac" ]
+                       then
+                               bootif_mac="$x"
+                       else
+                               bootif_mac="$bootif_mac:$x"
+                       fi
+               done
+               unset IFS
+
+               # look for devices with matching mac address, and set DEVICE to
+               # appropriate value if match is found.
+
+               for device in /sys/class/net/*
+               do
+                       if [ -f "$device/address" ]
+                       then
+                               current_mac=$(cat "$device/address")
+
+                               if [ "$bootif_mac" = "$current_mac" ]
+                               then
+                                       DEVICE=${device##*/}
+                                       break
+                               fi
+                       fi
+               done
+       fi
+
        # if ethdevice was not specified on the kernel command line
        # make sure we try to get a working network configuration
        # for *every* present network device (except for loopback of course)
@@ -602,9 +654,6 @@ do_netsetup ()
                devlist="$devlist $device"
        done
 
-       [ -n "$ETHDEV_TIMEOUT" ] || ETHDEV_TIMEOUT=15
-       echo "Using timeout of $ETHDEV_TIMEOUT seconds for network configuration."
-
        # this is tricky (and ugly) because ipconfig sometimes just hangs/runs into
        # an endless loop; iff execution fails give it two further tries, that's
        # why we use '$devlist $devlist $devlist' for the other for loop
@@ -628,45 +677,54 @@ do_netsetup ()
        done
 
        else
-       ipconfig ${DEVICE} | tee /netboot.config
-       fi
-
-       # source relevant ipconfig output
-       OLDHOSTNAME=${HOSTNAME}
-       . /tmp/net-${DEVICE}.conf
-       [ -z ${HOSTNAME} ] && HOSTNAME=${OLDHOSTNAME}
-       export HOSTNAME
-
-       if [ -n "${DEVICE}" ]
-       then
-               HWADDR="$(cat /sys/class/net/${DEVICE}/address)"
+               for interface in ${DEVICE}; do
+                       ipconfig -t "$ETHDEV_TIMEOUT" ${interface} | tee /netboot-${interface}.config
+                       [ -e /tmp/net-${interface}.conf ] && . /tmp/net-${interface}.conf
+                       if [ "$IPV4ADDR" != "0.0.0.0" ]
+                       then
+                               break
+                       fi
+               done
        fi
 
-       if [ ! -e "/etc/resolv.conf" ]
-       then
-               echo "Creating /etc/resolv.conf"
+       for interface in ${DEVICE}; do
+               # source relevant ipconfig output
+               OLDHOSTNAME=${HOSTNAME}
+               [ -e /tmp/net-${interface}.conf ] && . /tmp/net-${interface}.conf
+               [ -z ${HOSTNAME} ] && HOSTNAME=${OLDHOSTNAME}
+               export HOSTNAME
 
-               if [ -n "${DNSDOMAIN}" ]
+               if [ -n "${interface}" ]
                then
-                       echo "domain ${DNSDOMAIN}" > /etc/resolv.conf
-                       echo "search ${DNSDOMAIN}" > /etc/resolv.conf
+                       HWADDR="$(cat /sys/class/net/${interface}/address)"
                fi
 
-               for i in ${IPV4DNS0} ${IPV4DNS1} ${IPV4DNS1}
-               do
-                       echo "nameserver $i" >> /etc/resolv.conf
-               done
-       fi
+               if [ ! -e "/etc/resolv.conf" ]
+               then
+                       echo "Creating /etc/resolv.conf"
 
-       # Check if we have a network device at all
-       if ! ls /sys/class/net/"$DEVICE" > /dev/null 2>&1 && \
-          ! ls /sys/class/net/eth0 > /dev/null 2>&1 && \
-          ! ls /sys/class/net/wlan0 > /dev/null 2>&1 && \
-          ! ls /sys/class/net/ath0 > /dev/null 2>&1 && \
-          ! ls /sys/class/net/ra0 > /dev/null 2>&1
-       then
-               panic "No supported network device found, maybe a non-mainline driver is required."
-       fi
+                       if [ -n "${DNSDOMAIN}" ]
+                       then
+                               echo "domain ${DNSDOMAIN}" > /etc/resolv.conf
+                               echo "search ${DNSDOMAIN}" > /etc/resolv.conf
+                       fi
+
+                       for i in ${IPV4DNS0} ${IPV4DNS1} ${IPV4DNS1}
+                       do
+                               echo "nameserver $i" >> /etc/resolv.conf
+                       done
+               fi
+
+               # Check if we have a network device at all
+               if ! ls /sys/class/net/"$interface" > /dev/null 2>&1 && \
+                  ! ls /sys/class/net/eth0 > /dev/null 2>&1 && \
+                  ! ls /sys/class/net/wlan0 > /dev/null 2>&1 && \
+                  ! ls /sys/class/net/ath0 > /dev/null 2>&1 && \
+                  ! ls /sys/class/net/ra0 > /dev/null 2>&1
+               then
+                       panic "No supported network device found, maybe a non-mainline driver is required."
+               fi
+       done
 }
 
 do_netmount()
@@ -1209,16 +1267,9 @@ setup_unionfs ()
                                        log_warning_msg "Unknown file system type on ${backdev} (${image}), assuming ${fstype}."
                                fi
 
-                               if [ "${UNIONTYPE}" != "unionmount" ]
-                               then
-                                       mpoint="${croot}/${imagename}"
-                                       rofsstring="${mpoint}=${roopt}:${rofsstring}" && rofslist="${mpoint} ${rofslist}"
-                               else
-                                       mpoint="${rootmnt}"
-                               fi
-                               mkdir -p "${mpoint}"
-                               log_begin_msg "Mounting \"${image}\" on \"${mpoint}\" via \"${backdev}\""
-                               mount -t "${fstype}" -o ro,noatime "${backdev}" "${mpoint}" || panic "Can not mount ${backdev} (${image}) on ${mpoint}"
+                               mkdir -p "${croot}/${imagename}"
+                               log_begin_msg "Mounting \"${image}\" on \"${croot}${imagename}\" via \"${backdev}\""
+                               mount -t "${fstype}" -o ro,noatime "${backdev}" "${croot}/${imagename}" || panic "Can not mount ${backdev} (${image}) on ${croot}/${imagename}" && rofsstring="${croot}/${imagename}=${roopt}:${rofsstring}" && rofslist="${croot}/${imagename} ${rofslist}"
                                log_end_msg
                        fi
                done
@@ -1332,9 +1383,6 @@ setup_unionfs ()
                cow_mountopt="rw,noatime,mode=755"
        fi
 
-       if [ "${UNIONTYPE}" != "unionmount" ]
-       then
-
        if [ "${cow_fstype}" = "nfs" ]
        then
                log_begin_msg \
@@ -1345,7 +1393,6 @@ setup_unionfs ()
                mount -t ${cow_fstype} -o ${cow_mountopt} ${cowdevice} /cow || \
                        panic "Can not mount ${cowdevice} (o: ${cow_fstype}) on /cow"
        fi
-       fi
 
        rofscount=$(echo ${rofslist} |wc -w)
 
@@ -1390,10 +1437,6 @@ setup_unionfs ()
                                pidof unionfs-fuse >> /dev/.initramfs/varrun/sendsigs.omit || true
                                ;;
 
-                       unionmount)
-                               mount_full -t ${cow_fstype} -o noatime,union,${cow_mountopt} ${cowdevice} "${rootmnt}" || panic "${UNIONTYPE} ${cowdevice} on ${rootmnt} failed with option noatime,union,${cow_mountopt}"
-                               ;;
-
                        *)
                                mount -t ${UNIONTYPE} -o noatime,${noxino_opt}dirs=/cow=rw:${rofsstring} ${UNIONTYPE} "${rootmnt}" || panic "mount ${UNIONTYPE} on ${rootmnt} failed with option noatime,${noxino_opt}dirs=/cow=rw:${rofsstring}"
                                ;;
@@ -1488,7 +1531,7 @@ check_dev ()
                        echo "Warning: device for bootoption isofrom= ($FROMISO) not found.">>/live.log
                else
                        mkdir /isofrom
-                       mount -t auto "$ISO_DEVICE" /isofrom
+                       mount "$ISO_DEVICE" /isofrom
                        ISO_NAME="$(echo $FROMISO | sed "s|$ISO_DEVICE||")"
                        loopdevname=$(setup_loop "/isofrom/${ISO_NAME}" "loop" "/sys/block/loop*" "" '')
                        devname="${loopdevname}"