Added static ip support to debian live.
authorPravin Shinde <pravin@black-perl.(none)>
Wed, 9 Sep 2009 19:53:18 +0000 (21:53 +0200)
committerPravin Shinde <pravin@black-perl.(none)>
Wed, 9 Sep 2009 19:53:18 +0000 (21:53 +0200)
The network setup is ideal now.
Only thing which is not checked is case of multiple network cards.
current code assumes that booting will be done via eth0

D/D/DL/generate_initrd.sh
D/D/DL/init [deleted file]
D/D/DL/live

index dc3414a..3006221 100755 (executable)
@@ -18,15 +18,14 @@ cd ..
 echo "coping the needed files..."
 
 
-#cp run-init mpoint/bin/
-#chmod 777 mpoint/bin/run-init
+cp run-init mpoint/bin/
+chmod 777 mpoint/bin/run-init
 
 echo "copying iscsi related files..."
 mkdir mpoint/etc/iscsi
 cp iscsi/iscsid.conf mpoint/etc/iscsi/
 cp iscsi/initiatorname.iscsi mpoint/etc/iscsi/
 cp iscsi/tools/* mpoint/sbin/
-cp fdisk mpoint/sbin/
 
 mkdir mpoint/modules
 cp modules/* mpoint/modules/
@@ -38,8 +37,6 @@ chmod 777 mpoint/bin/httpfs
 cp httpfs/server/fusermount mpoint/bin/
 chmod 777 mpoint/bin/fusermount
 
-#cp init mpoint/
-#chmod 0777 mpoint/init 
 
 cp live mpoint/scripts/
 chmod 0777 mpoint/scripts/live
diff --git a/D/D/DL/init b/D/D/DL/init
deleted file mode 100755 (executable)
index 102eda2..0000000
+++ /dev/null
@@ -1,228 +0,0 @@
-#!/bin/sh
-
-echo "Loading, please wait..."
-
-[ -d /dev ] || mkdir -m 0755 /dev
-[ -d /root ] || mkdir -m 0700 /root
-[ -d /sys ] || mkdir /sys
-[ -d /proc ] || mkdir /proc
-[ -d /tmp ] || mkdir /tmp
-mkdir -p /var/lock
-mount -t sysfs -o nodev,noexec,nosuid none /sys 
-mount -t proc -o nodev,noexec,nosuid none /proc 
-
-# Note that this only becomes /dev on the real filesystem if udev's scripts
-# are used; which they will be, but it's worth pointing out
-tmpfs_size="10M"
-if [ -e /etc/udev/udev.conf ]; then
-       . /etc/udev/udev.conf
-fi
-mount -t tmpfs -o size=$tmpfs_size,mode=0755 udev /dev
-[ -e /dev/console ] || mknod -m 0600 /dev/console c 5 1
-[ -e /dev/null ] || mknod /dev/null c 1 3
-> /dev/.initramfs-tools
-mkdir /dev/.initramfs
-
-# Export the dpkg architecture
-export DPKG_ARCH=
-. /conf/arch.conf
-
-# Set modprobe env
-export MODPROBE_OPTIONS="-qb"
-
-# Export relevant variables
-export ROOT=
-export ROOTDELAY=
-export ROOTFLAGS=
-export ROOTFSTYPE=
-export break=
-export init=/sbin/init
-export quiet=n
-export readonly=y
-export rootmnt=/root
-export debug=
-export panic=
-export blacklist=
-export resume_offset=
-
-# Bring in the main config
-. /conf/initramfs.conf
-for conf in conf/conf.d/*; do
-       [ -f ${conf} ] && . ${conf}
-done
-. /scripts/functions
-
-# Parse command line options
-for x in $(cat /proc/cmdline); do
-       case $x in
-       init=*)
-               init=${x#init=}
-               ;;
-       root=*)
-               ROOT=${x#root=}
-               case $ROOT in
-               LABEL=*)
-                       ROOT="/dev/disk/by-label/${ROOT#LABEL=}"
-                       ;;
-               UUID=*)
-                       ROOT="/dev/disk/by-uuid/${ROOT#UUID=}"
-                       ;;
-               /dev/nfs)
-                       [ -z "${BOOT}" ] && BOOT=nfs
-                       ;;
-               esac
-               ;;
-       rootflags=*)
-               ROOTFLAGS="-o ${x#rootflags=}"
-               ;;
-       rootfstype=*)
-               ROOTFSTYPE="${x#rootfstype=}"
-               ;;
-       rootdelay=*)
-               ROOTDELAY="${x#rootdelay=}"
-               case ${ROOTDELAY} in
-               *[![:digit:].]*)
-                       ROOTDELAY=
-                       ;;
-               esac
-               ;;
-       nfsroot=*)
-               NFSROOT="${x#nfsroot=}"
-               ;;
-       ip=*)
-               IPOPTS="${x#ip=}"
-               ;;
-       boot=*)
-               BOOT=${x#boot=}
-               ;;
-       resume=*)
-               RESUME="${x#resume=}"
-               ;;
-       resume_offset=*)
-               resume_offset="${x#resume_offset=}"
-               ;;
-       noresume)
-               noresume=y
-               ;;
-       panic=*)
-               panic="${x#panic=}"
-               case ${panic} in
-               *[![:digit:].]*)
-                       panic=
-                       ;;
-               esac
-               ;;
-       quiet)
-               quiet=y
-               ;;
-       ro)
-               readonly=y
-               ;;
-       rw)
-               readonly=n
-               ;;
-       debug)
-               debug=y
-               quiet=n
-               exec >/dev/.initramfs/initramfs.debug 2>&1
-               set -x
-               ;;
-       debug=*)
-               debug=y
-               quiet=n
-               set -x
-               ;;
-       break=*)
-               break=${x#break=}
-               ;;
-       break)
-               break=premount
-               ;;
-       blacklist=*)
-               blacklist=${x#blacklist=}
-               ;;
-       esac
-done
-
-if [ -z "${noresume}" ]; then
-       export resume=${RESUME}
-else
-       export noresume
-fi
-
-depmod -a
-maybe_break top
-
-# Don't do log messages here to avoid confusing usplash
-run_scripts /scripts/init-top
-
-maybe_break modules
-log_begin_msg "Loading essential drivers"
-load_modules
-log_end_msg
-
-maybe_break premount
-[ "$quiet" != "y" ] && log_begin_msg "Running /scripts/init-premount"
-run_scripts /scripts/init-premount
-[ "$quiet" != "y" ] && log_end_msg
-
-maybe_break mount
-log_begin_msg "Mounting root file system"
-. /scripts/${BOOT}
-parse_numeric ${ROOT}
-maybe_break mountroot
-mountroot
-log_end_msg
-
-maybe_break bottom
-[ "$quiet" != "y" ] && log_begin_msg "Running /scripts/init-bottom"
-run_scripts /scripts/init-bottom
-[ "$quiet" != "y" ] && log_end_msg
-
-# Move virtual filesystems over to the real filesystem
-mount -n -o move /sys ${rootmnt}/sys
-mount -n -o move /proc ${rootmnt}/proc
-
-# Check init bootarg
-if [ -n "${init}" ] && [ ! -x "${rootmnt}${init}" ]; then
-       echo "Target filesystem doesn't have ${init}."
-       init=
-fi
-
-# Search for valid init
-if [ -z "${init}" ] ; then
-       for init in /sbin/init /etc/init /bin/init /bin/sh; do
-               if [ ! -x "${rootmnt}${init}" ]; then
-                       continue
-               fi
-               break
-       done
-fi
-
-# No init on rootmount
-if [ ! -x "${rootmnt}${init}" ]; then
-       panic "No init found. Try passing init= bootarg."
-fi
-
-# don't leak too much of env - some init(8) don't clear it
-# (keep init, rootmnt)
-unset debug
-unset MODPROBE_OPTIONS
-unset DPKG_ARCH
-unset ROOTFLAGS
-unset ROOTFSTYPE
-unset ROOTDELAY
-unset ROOT
-unset blacklist
-unset break
-unset noresume
-unset panic
-unset quiet
-unset readonly
-unset resume
-unset resume_offset
-
-# Chain to real filesystem
-maybe_break init
-exec run-init ${rootmnt} ${init} "$@" <${rootmnt}/dev/console >${rootmnt}/dev/console
-panic "Could not execute run-init."
index 8c8a538..cd5f9a0 100755 (executable)
@@ -88,25 +88,36 @@ Arguments ()
                        httpfs=*)
                                HTTPFS="${ARGUMENT#httpfs=}"
                                export HTTPFS
-                echo "found argument httpfs here ${HTTPFS}"
                                ;;
 
                        iscsifs=*)
                                ISCSIFS="${ARGUMENT#iscsifs=}"
                                export ISCSIFS
-                echo "found argument iscsifs here ${ISCSIFS}"
                                ;;
 
-            rescuebreak)
-                export RESCUEBREAK="Yes" 
-                ;;
+                       iname=*)
+                               ISCSINAME="${ARGUMENT#iname=}"
+                               export ISCSINAME 
+                               ;;
 
                        target=*)
                                TARGET="${ARGUMENT#target=}"
                                export TARGET 
-                echo "found argument target here ${TARGET}"
                                ;;
 
+                       dnsip=*)
+                               DNSIP="${ARGUMENT#dnsip=}"
+                               export DNSIP 
+                               ;;
+
+                       ip=*)
+                               BOOTIP="${ARGUMENT#ip=}"
+                               export BOOTIP
+                               ;;
+
+                       rescuebreak)
+                               export RESCUEBREAK="Yes" 
+                               ;;
 
                        hostname=*)
                                HOSTNAME="${ARGUMENT#hostname=}"
@@ -717,6 +728,32 @@ add_ip_to_resolv_conf ()
        fi
 }
 
+setup_static_ip ()
+{
+       ifconfig lo 127.0.0.1 up
+       ifconfig "${DEVICE}" up
+       local myip=`echo ${BOOTIP} | cut -d: -f1`
+       local mynm=`echo ${BOOTIP} | cut -d: -f4`
+       local mygw=`echo ${BOOTIP} | cut -d: -f3`
+       echo "myip=${myip} mynm=${mynm} mygw=${mygw}"
+       ifconfig "${DEVICE}" "${myip}" netmask "${mynm}"  
+       ifconfig "${DEVICE}"
+       route add default gw "${mygw}" 
+       return 0
+}
+
+setup_static_dns ()
+{
+       if [ -z ${DNSIP} ]
+       then
+               add_ip_to_resolv_conf "4.2.2.2" 
+               add_ip_to_resolv_conf "128.255.1.3" 
+       else
+               add_ip_to_resolv_conf ${DNSIP} 
+       fi
+       return 0
+}
+
 do_netmount ()
 {
        rc=1
@@ -735,24 +772,28 @@ do_netmount ()
                udevsettle
        fi
 
-       ipconfig ${DEVICE} | tee /netboot.config
-       
-       # Adding DNS Entry
-       local ipconf_dnsip=`cat /netboot.config | grep dns0 | cut -d':' -f3 | cut -d' ' -f2`
-       if [ -z ${ipconf_dnsip}] || [ ${ipconf_dnsip} == '0.0.0.0']
-       then
-               add_ip_to_resolv_conf "4.2.2.2" 
-               add_ip_to_resolv_conf "128.255.1.3" 
+       if [ -z ${BOOTIP} ] 
+       then    
+               ipconfig ${DEVICE} | tee /netboot.config
+               # Adding DNS Entry
+               local ipconf_dnsip=`cat /netboot.config | grep dns0 | cut -d':' -f3 | cut -d' ' -f2`
+               if [ -z ${ipconf_dnsip}] || [ ${ipconf_dnsip} == '0.0.0.0']
+               then
+                       setup_static_dns
+               else
+                       add_ip_to_resolv_conf ${ipconf_dnsip}
+               fi
+               # source relevant ipconfig output
+               OLDHOSTNAME=${HOSTNAME}
+               . /tmp/net-${DEVICE}.conf
+               [ -z ${HOSTNAME} ] && HOSTNAME=${OLDHOSTNAME}
+               export HOSTNAME
+
        else
-               add_ip_to_resolv_conf ${ipconf_dnsip}
+               setup_static_ip 
+               setup_static_dns
        fi
 
-       # source relevant ipconfig output
-       OLDHOSTNAME=${HOSTNAME}
-       . /tmp/net-${DEVICE}.conf
-       [ -z ${HOSTNAME} ] && HOSTNAME=${OLDHOSTNAME}
-       export HOSTNAME
-
        # Check if we have a network device at all
        if ! ls /sys/class/net/eth0 > /dev/null 2>&1 && \
           ! ls /sys/class/net/wlan0 > /dev/null 2>&1 && \
@@ -771,21 +812,15 @@ do_netmount ()
 
        if ( [ -n "${ISCSIFS}" ] ) && do_iscsimount
        then
-        echo "do_iscsimount successful"
                rc=0
                return ${rc}
        fi
-    echo "do_iscsimount failed..."
-
-
 
        if ( [ -n "${FETCH}" ] || [ -n "${HTTPFS}" ] || [ -n "${FTPFS}" ] ) && do_httpmount
        then
-        echo "do_httpmount successful"
                rc=0
                return ${rc}
        fi
-    echo "do_httpmount failed..."
 
        if [ "${NFSROOT#*:}" = "${NFSROOT}" ] && [ "$NETBOOT" != "cifs" ]
        then
@@ -804,58 +839,10 @@ do_netmount ()
                rc=0
        fi
 
-    echo "Giving rescue shell.... type exit when finished"
-    /bin/bash
        log_end_msg
        return ${rc}
 }
 
-do_iscsimount ()
-{
-       rc=1
-       dest="${mountpoint}/${LIVE_MEDIA_PATH}"
-       mount -t ramfs ram "${mountpoint}"
-       mkdir -p "${dest}"
-            
-    insmod /modules/libcrc32c.ko
-    insmod /modules/crc32c.ko
-    modprobe iscsi_tcp
-    modprobe ib_iser
-    mkdir /var/run
-    /sbin/iscsid
-    sleep 4
-    iscsiadm -m discovery -t st -p "${ISCSIFS}"
-    sleep 4
-    targetname=`iscsiadm -m node | grep "${TARGET}" | cut -d' ' -f2`
-    iscsiadm -m node --targetname "${targetname}" --portal "${ISCSIFS}" --login
-    export iscsidevice=/dev/disk/by-label/Debian\\x20lenny\\x2020090614-09\:11 
-    wait_for_device ${iscsidevice} 160
-    mount -t iso9660 "${iscsidevice}" "${mountpoint}"
-    rc=${?}
-    sync
-    sleep 2
-#    rc=0
-    return $rc
-}
-
-# waits for $2 seconds to devie/file to appear on given path ($1)
-wait_for_device ()
-{
-       local device_path=${1}
-       local max_seconds=${2}
-       local i=0
-       while [ "$i" -lt ${max_seconds} ]
-       do
-        ls -l "${device_path}" && return 0 
-               i="$(($i + 1))"
-               echo "waiting for ${device_path} to appear $i"
-               sleep 1
-               sync
-       done
-       echo "Device did not appeared..."
-       return 1
-}
-
 do_httpmount ()
 {
        rc=1
@@ -896,16 +883,17 @@ do_httpmount ()
                                                esac
                                        else
                                                log_begin_msg "Trying to mount ${url} on ${dest}/$(basename ${url})"
-                                               modprobe fuse
-                                               wait_for_device /dev/fuse 160
                                                if [ "${webfile}" = "FTPFS" ]
                                                then
                                                        FUSE_MOUNT="curlftpfs"
                                                        url="$(dirname ${url})"
                                                else
                                                        FUSE_MOUNT="httpfs"
-                                                       httpfs ${url} ${dest}
                                                fi
+                                               modprobe fuse
+                                               # sometimes /dev/fuse takes time to appear, following line will avoid that problem
+                                               wait_for_device /dev/fuse 160
+                                               $FUSE_MOUNT "${url}" "${dest}"
                                        fi
                                        [ ${?} -eq 0 ] && rc=0
                                        [ "${extension}" = "tgz" ] && live_dest="ram"
@@ -934,6 +922,57 @@ do_httpmount ()
 #      return ${rc}
 }
 
+do_iscsimount ()
+{
+       rc=1
+       if [ ! -z ${ISCSINAME} ]
+       then
+               echo ${ISCSINAME} > /etc/iscsi/initiatorname.iscsi
+       fi
+
+       dest="${mountpoint}/${LIVE_MEDIA_PATH}"
+       mount -t ramfs ram "${mountpoint}"
+       mkdir -p "${dest}"
+       insmod /modules/libcrc32c.ko
+       insmod /modules/crc32c.ko
+       modprobe iscsi_tcp
+       modprobe ib_iser
+       mkdir /var/run
+       /sbin/iscsid
+       sleep 4
+       iscsiadm -m discovery -t st -p "${ISCSIFS}"
+       sleep 4
+       targetname=`iscsiadm -m node | grep "${TARGET}" | cut -d' ' -f2`
+       iscsiadm -m node --targetname "${targetname}" --portal "${ISCSIFS}" --login
+       export iscsidevice=/dev/disk/by-label/Debian\\x20lenny\\x2020090614-09\:11 
+       wait_for_device ${iscsidevice} 160
+       mount -t iso9660 "${iscsidevice}" "${mountpoint}"
+       rc=${?}
+       sync
+       sleep 2
+#      rc=0
+       return $rc
+}
+
+# waits for $2 seconds to devie/file to appear on given path ($1)
+wait_for_device ()
+{
+       local device_path=${1}
+       local max_seconds=${2}
+       local i=0
+       while [ "$i" -lt ${max_seconds} ]
+       do
+        ls -l "${device_path}" && return 0 
+               i="$(($i + 1))"
+               echo "waiting for ${device_path} to appear $i"
+               sleep 1
+               sync
+       done
+       echo "Device did not appeared..."
+       return 1
+}
+
+
 do_nfsmount ()
 {
        rc=1
@@ -1642,6 +1681,21 @@ integrity_check ()
        fi
 }
 
+rescue_break_shell ()
+{
+       if [ "${RESCUEBREAK}" = "Yes" ]; 
+       then
+               echo "#################################################################"
+               echo "#### giving rescue shell, you can execute any commands here #####"
+               echo "#### When done, type exit, boot process will resume :-)     #####"
+               echo "#################################################################"
+               /bin/sh
+               echo "#################################################################"
+               echo "####            Resuming Boot Process                       #####"
+               echo "#################################################################"
+       fi
+}
+
 mountroot ()
 {
         if [ -x /scripts/local-top/cryptroot ]; then
@@ -1702,14 +1756,7 @@ mountroot ()
                        done
                fi
        fi
-
-    if [ "${RESCUEBREAK}" = "Yes" ]; then
-        echo "#################################################################"
-        echo "#### giving rescue shell, you can execute any commands here #####"
-        echo "#### When done, type exit, boot process will resume :-)     #####"
-        echo "#################################################################"
-        /bin/sh
-    fi
+       rescue_break_shell
        if [ -z "${livefs_root}" ]
        then
                panic "Unable to find a medium containing a live file system"