made changes to incorporate ubuntu, need testing now
authorPravin Shinde <pravin@black-perl.(none)>
Thu, 25 Jun 2009 21:50:40 +0000 (23:50 +0200)
committerPravin Shinde <pravin@black-perl.(none)>
Thu, 25 Jun 2009 21:50:40 +0000 (23:50 +0200)
pxeknife/ubuntu/ubuntu-9.04-desktop-i386/casper [new file with mode: 0644]
pxeknife/ubuntu/ubuntu-9.04-desktop-i386/generate_initrd.sh [new file with mode: 0755]
pxeknife/ubuntu/ubuntu-9.04-desktop-i386/init [new file with mode: 0755]
pxeknife/ubuntu/ubuntu.conf [new file with mode: 0755]

diff --git a/pxeknife/ubuntu/ubuntu-9.04-desktop-i386/casper b/pxeknife/ubuntu/ubuntu-9.04-desktop-i386/casper
new file mode 100644 (file)
index 0000000..4a99f8d
--- /dev/null
@@ -0,0 +1,647 @@
+#!/bin/sh
+
+# set -e
+
+export PATH=/usr/bin:/usr/sbin:/bin:/sbin
+
+mountpoint=/cdrom
+
+root_persistence="casper-rw"
+home_persistence="home-rw"
+root_snapshot_label="casper-sn"
+home_snapshot_label="home-sn"
+
+USERNAME=casper
+USERFULLNAME="Live session user"
+HOST=live
+BUILD_SYSTEM=Custom
+
+mkdir -p $mountpoint
+
+[ -f /etc/casper.conf ] && . /etc/casper.conf
+export USERNAME USERFULLNAME HOST BUILD_SYSTEM
+
+. /scripts/casper-helpers
+
+if [ ! -f /casper.vars ]; then
+    touch /casper.vars
+fi
+
+parse_cmdline() {
+    for x in $(cat /proc/cmdline); do
+        case $x in
+            showmounts|show-cow)
+                export SHOWMOUNTS='Yes' ;;
+            persistent)
+                export PERSISTENT="Yes" ;;
+            nopersistent)
+                export PERSISTENT="" ;;
+            union=*)
+                export UNIONFS="${x#union=}";;
+            ip*)
+                STATICIP=${x#ip=}
+                if [ "${STATICIP}" = "" ]; then
+                    STATICIP="frommedia"
+                fi
+                export STATICIP ;;
+            ignore_uuid)
+                IGNORE_UUID="Yes" ;;
+        esac
+    done
+    if [ "${UNIONFS}" = "" ]; then
+        export UNIONFS="aufs"
+    fi
+}
+
+is_casper_path() {
+    path=$1
+    if [ -d "$path/casper" ]; then
+        if [ "$(echo $path/casper/*.squashfs)" != "$path/casper/*.squashfs" ] ||
+            [ "$(echo $path/casper/*.ext2)" != "$path/casper/*.ext2" ] ||
+            [ "$(echo $path/casper/*.dir)" != "$path/casper/*.dir" ]; then
+            return 0
+        fi
+    fi
+    return 1
+}
+
+matches_uuid() {
+    if [ "$IGNORE_UUID" ] || [ ! -e /conf/uuid.conf ]; then
+        return 0
+    fi
+    path="$1"
+    uuid="$(cat /conf/uuid.conf)"
+    for try_uuid_file in "$path/.disk/casper-uuid"*; do
+        [ -e "$try_uuid_file" ] || continue
+        try_uuid="$(cat "$try_uuid_file")"
+        if [ "$uuid" = "$try_uuid" ]; then
+            return 0
+        fi
+    done
+    return 1
+}
+
+get_backing_device() {
+    case "$1" in
+        *.squashfs|*.ext2)
+            echo $(setup_loop "$1" "loop" "/sys/block/loop*")
+            ;;
+        *.dir)
+            echo "directory"
+            ;;
+        *)
+            panic "Unrecognized casper filesystem: $1"
+            ;;
+    esac
+}
+
+match_files_in_dir() {
+    # Does any files match pattern $1 ?
+
+    local pattern="$1"
+    if [ "$(echo $pattern)" != "$pattern" ]; then
+        return 0
+    fi
+    return 1
+}
+
+mount_images_in_directory() {
+    directory="$1"
+    rootmnt="$2"
+    if match_files_in_dir "$directory/casper/*.squashfs" ||
+        match_files_in_dir "$directory/casper/*.ext2" ||
+        match_files_in_dir "$directory/casper/*.dir"; then
+        setup_unionfs "$directory/casper" "$rootmnt"
+    else
+        :
+    fi
+}
+
+is_nice_device() {
+    sysfs_path="${1#/sys}"
+    if /lib/udev/path_id "${sysfs_path}" | grep -E -q "ID_PATH=(usb|pci-[^-]*-(ide|scsi|usb)|platform-mmc)"; then
+        return 0
+    fi
+    return 1
+}
+
+copy_live_to() {
+    copyfrom="${1}"
+    copytodev="${2}"
+    copyto="${copyfrom}_swap"
+
+    size=$(fs_size "" ${copyfrom} "used")
+
+    if [ "${copytodev}" = "ram" ]; then
+        # copying to ram:
+        freespace=$( expr $(awk '/MemFree/{print $2}' /proc/meminfo) + $( cat /proc/meminfo | grep Cached | head -n 1 | awk '/Cached/{print $2}' - ) )
+        mount_options="-o size=${size}k"
+        free_string="memory"
+        fstype="tmpfs"
+        dev="/dev/shm"
+    else
+        # it should be a writable block device
+        if [ -b "${copytodev}" ]; then
+            dev="${copytodev}"
+            free_string="space"
+            fstype=$(get_fstype "${dev}")
+            freespace=$(fs_size "${dev}")
+        else
+            [ "$quiet" != "y" ] && log_warning_msg "${copytodev} is not a block device."
+            return 1
+        fi
+    fi
+    if [ "${freespace}" -lt "${size}" ] ; then
+        [ "$quiet" != "y" ] && log_warning_msg "Not enough free ${free_string} (${freespace}k > ${size}k) to copy live media in ${copytodev}."
+        return 1
+    fi
+
+    # begin copying..
+    mkdir "${copyto}"
+    echo "mount -t ${fstype} ${mount_options} ${dev} ${copyto}"
+    mount -t "${fstype}" ${mount_options} "${dev}" "${copyto}"
+    cp -a ${copyfrom}/* ${copyto} # "cp -a" from busybox also copies hidden files
+    umount ${copyfrom}
+    mount -r -o move ${copyto} ${copyfrom}
+    rmdir ${copyto}
+    return 0
+}
+
+do_netmount() {
+    rc=1
+
+    modprobe "${MP_QUIET}" af_packet # For DHCP
+
+    /sbin/udevadm trigger
+    /sbin/udevadm settle
+
+    ipconfig ${DEVICE} /tmp/net-${DEVICE}.conf | tee /netboot.config
+
+    if [ "${NFSROOT}" = "auto" ]; then
+        NFSROOT=${ROOTSERVER}:${ROOTPATH}
+    fi
+    log_begin_msg "inside netboot, will use ${NETBOOT} and httproot as ${HTTPFS}"
+
+    [ "$quiet" != "y" ] && log_begin_msg "Trying netboot from ${NFSROOT}"
+
+    if [ "${NETBOOT}" == "http" ] && do_httpfsmount ; then
+        rc=0
+    elif [ "${NETBOOT}" != "nfs" ] && do_cifsmount ; then
+        rc=0
+    elif do_nfsmount ; then
+        NETBOOT="nfs"
+        export NETBOOT
+        rc=0
+    fi
+
+    [ "$quiet" != "y" ] && log_end_msg
+    return ${rc}
+}
+
+do_nfsmount() {
+    rc=1
+    modprobe "${MP_QUIET}" nfs
+    if [ -z "${NFSOPTS}" ]; then
+        NFSOPTS=""
+    fi
+
+    [ "$quiet" != "y" ] && log_begin_msg "Trying nfsmount -o nolock -o ro ${NFSOPTS} ${NFSROOT} ${mountpoint}"
+    # FIXME: This while loop is an ugly HACK round an nfs bug
+    i=0
+    while [ "$i" -lt 60 ]; do
+        nfsmount -o nolock -o ro ${NFSOPTS} "${NFSROOT}" "${mountpoint}" && rc=0 && break
+        sleep 1
+        i="$(($i + 1))"
+    done
+    return ${rc}
+}
+
+do_httpfsmount() {
+    # objectives: 
+    # Enable networking.
+    # Setup networking.
+    # Find the location from which we need to get the ISO.
+    # Mount the ISO.
+    rc=1
+
+    echo "HTTP Boot: inserting network modules"
+#    insmod /modules/crc32c.ko >/dev/null 2>&1  
+    insmod /lib/modules/2.6.28-11-generic/kernel/drivers/net/8390.ko  
+    insmod /lib/modules/2.6.28-11-generic/kernel/drivers/net/mii.ko   
+    insmod /lib/modules/2.6.28-11-generic/kernel/drivers/net/ne2k-pci.ko 
+    insmod /lib/modules/2.6.28-11-generic/kernel/drivers/net/pcnet32.ko  
+    insmod /lib/modules/2.6.28-11-generic/kernel/drivers/net/r8169.ko  
+    insmod /lib/modules/2.6.28-11-generic/kernel/drivers/net/e100.ko   
+    insmod /lib/modules/2.6.28-11-generic/kernel/drivers/net/e1000/e1000.ko 
+    insmod /lib/modules/2.6.28-11-generic/kernel/drivers/net/sis900.ko 
+    insmod /lib/modules/2.6.28-11-generic/kernel/drivers/net/via-rhine.ko 
+    insmod /lib/modules/2.6.28-11-generic/kernel/drivers/net/8139too.ko   
+#    insmod /modules/af_packet.ko  
+#    insmod /modules/loop.ko >/dev/null 2>&1 
+
+       ifconfig lo 127.0.0.1 up
+       ifconfig eth0 up
+       udhcpc -s /bin/udhcpc.sh  >/dev/null 2>&1 
+       echo "passed on path is ${HTTPFS}"
+       ISO_PATH="http://192.168.0.2/ubuntu-9.04-desktop-i386.iso"
+       echo "The location of ubuntu iso  is $ISO_PATH"
+       echo "mounting CDROM"
+       mkdir /iso
+       httpfs $ISO_PATH /iso
+       FILEPATH=`ls /iso/*.iso`
+       busybox mount -t iso9660 $FILEPATH "${mountpoint}" -o loop -o ro
+       
+       
+       # test if knoppix is there
+       if test -f /cdrom/casper
+       then
+               echo -n "successfully mounted the Image"
+               rc=0
+       fi
+       return ${rc}
+
+}
+
+
+do_cifsmount() {
+    rc=1
+    if [ -x "/sbin/mount.cifs" ]; then
+        if [ -z "${NFSOPTS}" ]; then
+            CIFSOPTS="-ouser=root,password="
+        else
+            CIFSOPTS="${NFSOPTS}"
+        fi
+
+        [ "$quiet" != "y" ] && log_begin_msg "Trying mount.cifs ${NFSROOT} ${mountpoint} ${CIFSOPTS}"
+        modprobe "${MP_QUIET}" cifs
+
+        if mount.cifs "${NFSROOT}" "${mountpoint}" "${CIFSOPTS}" ; then
+            rc=0
+        fi
+    fi
+    return ${rc}
+}
+
+do_snap_copy ()
+{
+    fromdev="${1}"
+    todir="${2}"
+    snap_type="${3}"
+
+    size=$(fs_size "${fromdev}" "" "used")
+
+    if [ -b "${fromdev}" ]; then
+        # look for free mem
+        if [ -n "${HOMEMOUNTED}" -a "${snap_type}" = "HOME" ]; then
+            todev=$(cat /proc/mounts | grep -s " $(base_path ${todir}) " | awk '{print $1}' )
+            freespace=$(df -k  | grep -s ${todev} | awk '{print $4}')
+        else
+            freespace=$( expr $(awk '/MemFree/{print $2}' /proc/meminfo) + $( cat /proc/meminfo | grep Cached | head -n 1 | awk '/Cached/{print $2}' - ))
+        fi
+
+        tomount="/mnt/tmpsnap"
+        if [ ! -d "${tomount}" ] ; then
+            mkdir -p "${tomount}"
+        fi
+
+        fstype=$(get_fstype "${fromdev}")
+        if [ -n "${fstype}" ]; then
+            # Copying stuff...
+            mount -t "${fstype}" -o ro,noatime "${fromdev}" "${tomount}"
+            cp -a "${tomount}"/* ${todir}
+            umount "${tomount}"
+        else
+            log_warning_msg "Unrecognized fstype: ${fstype} on ${fromdev}:${snap_type}"
+        fi
+
+        rmdir "${tomount}"
+        if echo ${fromdev} | grep -qs loop; then
+           losetup -d "${fromdev}"
+        fi
+        return 0
+    else
+        return 1
+        [ "$quiet" != "y" ] && log_warning_msg "Unable to find the snapshot ${snap_type} medium"
+    fi
+}
+
+try_snap ()
+{
+    # Look for $snap_label.* in block devices and copy the contents to $snap_mount
+    #   and remember the device and filename for resync on exit in casper.init
+
+    snap_label="${1}"
+    snap_mount="${2}"
+    snap_type="${3}"
+
+    snapdata=$(find_files "${snap_label}.squashfs ${snap_label}.cpio.gz ${snap_label}.ext2")
+    if [ ! -z "${snapdata}" ]; then
+        snapdev="$(echo ${snapdata} | cut -f1 -d ' ')"
+        snapback="$(echo ${snapdata} | cut -f2 -d ' ')"
+        snapfile="$(echo ${snapdata} | cut -f3 -d ' ')"
+        if echo "${snapfile}" | grep -qs '\(squashfs\|ext2\)'; then
+            # squashfs or ext2 snapshot
+            dev=$(get_backing_device "${snapback}/${snapfile}")
+            if ! do_snap_copy "${dev}" "${snap_mount}" "${snap_type}"; then
+                 log_warning_msg "Impossible to include the ${snapfile} Snapshot"
+                 return 1
+            fi
+        else
+            # cpio.gz snapshot
+            if ! (cd "${snap_mount}" && zcat "${snapback}/${snapfile}" | cpio -i -u -d 2>/dev/null) ; then
+                log_warning_msg "Impossible to include the ${snapfile} Snapshot"
+                return 1
+            fi
+        fi
+        umount "${snapback}"
+    else
+        dev=$(find_cow_device "${snap_label}")
+        if [ -b ${dev} ]; then
+            if echo "${dev}" | grep -qs loop; then
+                # strange things happens, user confused?
+                snaploop=$( losetup ${dev} | awk '{print $3}' | tr -d '()' )
+                snapfile=$(basename ${snaploop})
+                snapdev=$(cat /proc/mounts | awk '{print $2,$1}' | grep -es "^$( dirname ${snaploop} )" | cut -f2 -d ' ')
+            else
+                snapdev="${dev}"
+            fi
+            if ! do_snap_copy "${dev}" "${snap_mount}" "${snap_type}" ; then
+                log_warning_msg "Impossible to include the ${snap_label} Snapshot"
+                return 1
+            else
+                if [ -n "${snapfile}" ]; then
+                     # it was a loop device, user confused
+                     umount ${snapdev}
+                fi
+            fi
+        else
+            log_warning_msg "Impossible to include the ${snap_label} Snapshot"
+            return 1
+        fi
+    fi
+    echo "export ${snap_type}SNAP="${snap_mount}":${snapdev}:${snapfile}" >> /etc/casper.conf # for resync on reboot/halt
+    return 0
+}
+
+setup_unionfs() {
+    image_directory="$1"
+    rootmnt="$2"
+
+    modprobe "${MP_QUIET}" -b ${UNIONFS}
+
+    # run-init can't deal with images in a subdir, but we're going to
+    # move all of these away before it runs anyway.  No, we're not,
+    # put them in / since move-mounting them into / breaks mono and
+    # some other apps.
+
+    croot="/"
+
+    # Let's just mount the read-only file systems first
+    rofsstring=""
+    rofslist=""
+    if [ "${NETBOOT}" = "nfs" ] ; then
+        roopt="nfsro" # go aroung a bug in nfs-unionfs locking
+    elif [ "${UNIONFS}" = "aufs" ]; then
+        roopt="rr"
+    else
+        roopt="ro"
+    fi
+
+    mkdir -p "${croot}"
+    for image_type in "ext2" "squashfs" "dir" ; do
+        for image in "${image_directory}"/*."${image_type}"; do
+            imagename=$(basename "${image}")
+            if [ -d "${image}" ]; then
+                # it is a plain directory: do nothing
+                rofsstring="${image}=${roopt}:${rofsstring}"
+                rofslist="${image} ${rofslist}"
+            elif [ -f "${image}" ]; then
+                backdev=$(get_backing_device "$image")
+                fstype=$(get_fstype "${backdev}")
+                if [ "${fstype}" = "unknown" ]; then
+                    panic "Unknown file system type on ${backdev} (${image})"
+                fi
+                mkdir -p "${croot}/${imagename}"
+                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}"
+            fi
+        done
+    done
+    rofsstring=${rofsstring%:}
+
+    mkdir -p /cow
+    cowdevice="tmpfs"
+    cow_fstype="tmpfs"
+    cow_mountopt="rw,noatime,mode=755"
+
+    # Looking for "${root_persistence}" device or file
+    if [ -n "${PERSISTENT}" ]; then
+        cowprobe=$(find_cow_device "${root_persistence}")
+        if [ -b "${cowprobe}" ]; then
+            cowdevice=${cowprobe}
+            cow_fstype=$(get_fstype "${cowprobe}")
+           cow_mountopt="rw,noatime"
+        else
+            [ "$quiet" != "y" ] && log_warning_msg "Unable to find the persistent medium"
+        fi
+    fi
+
+    mount -t ${cow_fstype} -o ${cow_mountopt} ${cowdevice} /cow || panic "Can not mount $cowdevice on /cow"
+
+    mount -t ${UNIONFS} -o noatime,dirs=/cow=rw:$rofsstring ${UNIONFS} "$rootmnt" || panic "${UNIONFS} mount failed"
+
+    # Adding other custom mounts
+    if [ -n "${PERSISTENT}" ]; then
+        # directly mount /home
+        # FIXME: add a custom mounts configurable system
+        homecow=$(find_cow_device "${home_persistence}" )
+        if [ -b "${homecow}" ]; then
+            mount -t $(get_fstype "${homecow}") -o rw,noatime "${homecow}" "${rootmnt}/home"
+            export HOMEMOUNTED=1 # used to proper calculate free space in do_snap_copy()
+        else
+            [ "$quiet" != "y" ] && log_warning_msg "Unable to find the persistent home medium"
+        fi
+        # Look for other snapshots to copy in
+        try_snap "${root_snapshot_label}" "${rootmnt}" "ROOT"
+        try_snap "${home_snapshot_label}" "${rootmnt}/home" "HOME"
+    fi
+
+    if [ -n "${SHOWMOUNTS}" ]; then
+        for d in ${rofslist}; do
+            mkdir -p "${rootmnt}/casper/${d##*/}"
+            case d in
+                *.dir) # do nothing # mount -o bind "${d}" "${rootmnt}/casper/${d##*/}"
+                    ;;
+                *) mount -o move "${d}" "${rootmnt}/casper/${d##*/}"
+                    ;;
+            esac
+        done
+        # shows cow fs on /cow for use by casper-snapshot
+        mkdir -p "${rootmnt}/cow"
+        mount -o bind /cow "${rootmnt}/cow"
+    fi
+
+    # move the first mount; no head in busybox-initramfs
+    for d in $(mount -t squashfs | cut -d\  -f 3); do
+        mkdir -p "${rootmnt}/rofs"
+        mount -o move "${d}" "${rootmnt}/rofs"
+        break
+    done
+}
+
+check_dev ()
+{
+    sysdev="${1}"
+    devname="${2}"
+    skip_uuid_check="${3}"
+    if [ -z "${devname}" ]; then
+        devname=$(sys2dev "${sysdev}")
+    fi
+
+    if [ -d "${devname}" ]; then
+        mount -o bind "${devname}" $mountpoint || continue
+        if is_casper_path $mountpoint; then
+            echo $mountpoint
+            return 0
+        else
+            umount $mountpoint
+        fi
+    fi
+
+    if [ -n "${LIVEMEDIA_OFFSET}" ]; then
+        loopdevname=$(setup_loop "${devname}" "loop" "/sys/block/loop*" "${LIVEMEDIA_OFFSET}")
+        devname="${loopdevname}" 
+    fi
+
+    fstype=$(get_fstype "${devname}")
+    if is_supported_fs ${fstype}; then
+        mount -t ${fstype} -o ro,noatime "${devname}" $mountpoint || continue
+        if is_casper_path $mountpoint && \
+           ([ "$skip_uuid_check" ] || matches_uuid $mountpoint); then
+            echo $mountpoint
+            return 0
+        else
+            umount $mountpoint
+        fi
+    fi
+
+    if [ -n "${LIVEMEDIA_OFFSET}" ]; then
+        losetup -d "${loopdevname}"
+    fi
+    return 1
+}
+
+find_livefs() {
+    timeout="${1}"
+    # first look at the one specified in the command line
+    if [ ! -z "${LIVEMEDIA}" ]; then
+        if check_dev "null" "${LIVEMEDIA}" "skip_uuid_check"; then
+            return 0
+        fi
+    fi
+    # don't start autodetection before timeout has expired
+    if [ -n "${LIVEMEDIA_TIMEOUT}" ]; then
+        if [ "${timeout}" -lt "${LIVEMEDIA_TIMEOUT}" ]; then
+            return 1
+        fi
+    fi
+    # or do the scan of block devices
+    for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -vE "/(loop|ram|fd)"); do
+        devname=$(sys2dev "${sysblock}")
+        fstype=$(get_fstype "${devname}")
+        if /lib/udev/cdrom_id ${devname} > /dev/null; then
+            if check_dev "null" "${devname}" ; then
+                return 0
+            fi
+        elif is_nice_device "${sysblock}" ; then
+            for dev in $(subdevices "${sysblock}"); do
+                if check_dev "${dev}" ; then
+                    return 0
+                fi
+            done
+        elif [ "${fstype}" = "squashfs" -o \
+                "${fstype}" = "ext4" -o \
+                "${fstype}" = "ext3" -o \
+                "${fstype}" = "ext2" ]; then
+            # This is an ugly hack situation, the block device has
+            # an image directly on it.  It's hopefully
+            # casper, so take it and run with it.
+            ln -s "${devname}" "${devname}.${fstype}"
+            echo "${devname}.${fstype}"
+            return 0
+        fi
+    done
+    return 1
+}
+
+set_usplash_timeout() {
+    if [ -x /sbin/usplash_write ]; then
+        /sbin/usplash_write "TIMEOUT 120"
+    fi
+}
+
+mountroot() {
+    exec 6>&1
+    exec 7>&2
+    exec > casper.log
+    exec 2>&1
+
+    parse_cmdline
+
+    set_usplash_timeout
+    [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/casper-premount"
+    run_scripts /scripts/casper-premount
+    [ "$quiet" != "y" ] && log_end_msg
+
+    # Needed here too because some things (*cough* udev *cough*)
+    # changes the timeout
+
+    set_usplash_timeout
+
+    if [ ! -z "${NETBOOT}" ]; then
+        if do_netmount ; then
+            livefs_root="${mountpoint}"
+        else
+            panic "Unable to find a live file system on the network"
+        fi
+    else
+        # Scan local devices for the image
+        i=0
+        while [ "$i" -lt 60 ]; do
+            livefs_root=$(find_livefs $i)
+            if [ "${livefs_root}" ]; then
+                break
+            fi
+            sleep 1
+            i="$(($i + 1))"
+        done
+    fi
+
+    if [ -z "${livefs_root}" ]; then
+        panic "Unable to find a medium containing a live file system"
+    fi
+
+    if [ "${TORAM}" ]; then
+        live_dest="ram"
+    elif [ "${TODISK}" ]; then
+        live_dest="${TODISK}"
+    fi
+    if [ "${live_dest}" ]; then
+        log_begin_msg "Copying live_media to ${live_dest}"
+        copy_live_to "${livefs_root}" "${live_dest}"
+        log_end_msg
+    fi
+
+    mount_images_in_directory "${livefs_root}" "${rootmnt}"
+
+    log_end_msg
+
+    maybe_break casper-bottom
+    [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/casper-bottom"
+
+    run_scripts /scripts/casper-bottom
+    [ "$quiet" != "y" ] && log_end_msg
+
+    exec 1>&6 6>&-
+    exec 2>&7 7>&-
+    cp casper.log "${rootmnt}/var/log/"
+}
diff --git a/pxeknife/ubuntu/ubuntu-9.04-desktop-i386/generate_initrd.sh b/pxeknife/ubuntu/ubuntu-9.04-desktop-i386/generate_initrd.sh
new file mode 100755 (executable)
index 0000000..f53baee
--- /dev/null
@@ -0,0 +1,56 @@
+#!/bin/bash
+
+#cleanup the old mess
+echo "Removing the old files"
+rm -rf initrd.gz initrd mpoint
+
+# create a copy of image to modify
+cp initrd.gz_orig initrd.gz
+gunzip initrd.gz
+mkdir mpoint
+
+echo "extracting filesystem filesystem"
+mkdir mpoint
+cd mpoint 
+cpio -ivu --no-absolute-filename  < ../initrd
+cd ..
+
+echo "coping the needed files..."
+
+cp httpfs/static/udhcpc mpoint/bin/
+chmod 777 mpoint/bin/udhcpc
+
+cp httpfs/static/udhcpc.sh mpoint/bin/
+chmod 777 mpoint/bin/udhcpc.sh
+
+
+cp httpfs/server/httpfs mpoint/bin/
+chmod 777 mpoint/bin/httpfs
+
+cp httpfs/server/fusermount mpoint/bin/
+chmod 777 mpoint/bin/fusermount
+
+cp init mpoint/
+chmod 0777 mpoint/init 
+
+cp casper mpoint/scripts/
+chmod 0777 mpoint/scripts/casper
+
+
+cp mount_http_iso.sh mpoint/
+chmod 0777 mpoint/mount_http_iso.sh 
+
+#mknod mpoint/dev/fuse c 10 229
+
+
+cd mpoint
+echo "creating initrd from new system filesystem"
+
+echo "Compressing the filesystem"
+find . | cpio -oH newc | gzip -9 > ../initrd.gz
+cd ..
+
+rm -rf mpoint initrd
+
+
+echo "Done, you can use initrd.gz"
diff --git a/pxeknife/ubuntu/ubuntu-9.04-desktop-i386/init b/pxeknife/ubuntu/ubuntu-9.04-desktop-i386/init
new file mode 100755 (executable)
index 0000000..28a7c86
--- /dev/null
@@ -0,0 +1,263 @@
+#!/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
+mount -t tmpfs -o 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="${ROOT#LABEL=}"
+
+                       # support / in LABEL= paths (escape to \x2f)
+                       case "${ROOT}" in
+                       *[/]*)
+                       if [ -x "$(command -v sed)" ]; then
+                               ROOT="$(echo ${ROOT} | sed 's,/,\\x2f,g')"
+                       else
+                               if [ "${ROOT}" != "${ROOT#/}" ]; then
+                                       ROOT="\x2f${ROOT#/}"
+                               fi
+                               if [ "${ROOT}" != "${ROOT%/}" ]; then
+                                       ROOT="${ROOT%/}\x2f"
+                               fi
+                               IFS='/'
+                               newroot=
+                               for s in $ROOT; do
+                                       if [ -z "${newroot}" ]; then
+                                               newroot="${s}"
+                                       else
+                                               newroot="${newroot}\\x2f${s}"
+                                       fi
+                               done
+                               unset IFS
+                               ROOT="${newroot}"
+                       fi
+                       esac
+                       ROOT="/dev/disk/by-label/${ROOT}"
+                       ;;
+               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
+               ;;
+       resumedelay=*)
+               RESUMEDELAY="${x#resumedelay=}"
+               ;;
+       loop=*)
+               LOOP="${x#loop=}"
+               ;;
+       loopflags=*)
+               LOOPFLAGS="-o ${x#loopflags=}"
+               ;;
+       loopfstype=*)
+               LOOPFSTYPE="${x#loopfstype=}"
+               ;;
+       cryptopts=*)
+               cryptopts="${x#cryptopts=}"
+               ;;
+       nfsroot=*)
+               NFSROOT="${x#nfsroot=}"
+               ;;
+       httpfs=*)
+               HTTPFS="${x#httpfs=}"
+               ;;
+       netboot=*)
+               NETBOOT="${x#netboot=}"
+               ;;
+       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
+
+# export BOOT variable value for compcache,
+# so we know if we run from casper
+export BOOT
+
+# 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}
+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
+
+# Confuses /etc/init.d/rc
+if [ -n ${debug} ]; then
+       unset debug
+fi
+
+# Chain to real filesystem
+maybe_break init
+exec run-init ${rootmnt} ${init} "$@" <${rootmnt}/dev/console >${rootmnt}/dev/console 2>&1
+panic "Could not execute run-init."
diff --git a/pxeknife/ubuntu/ubuntu.conf b/pxeknife/ubuntu/ubuntu.conf
new file mode 100755 (executable)
index 0000000..76b0d89
--- /dev/null
@@ -0,0 +1,39 @@
+MENU TITLE --== Ubuntu ==--
+LABEL rootmenu
+       MENU LABEL <---- PXE Knife
+       kernel menu.c32
+       append pxeknife/pxeknife.conf
+
+
+label ubuntu904desktopi386-laptop
+       MENU LABEL Ubuntu 9.04 Desktop i386 - laptop
+       kernel pxeknife/ubuntu/ubuntu-9.04-desktop-i386/vmlinuz
+       append  file=/cdrom/preseed/ubuntu.seed netboot=http boot=casper httpfs=http://192.168.0.2/ubuntu-9.04-desktop-i386.iso  initrd=pxeknife/ubuntu/ubuntu-9.04-desktop-i386/initrd.gz
+
+
+label knoppix502-rom
+       MENU LABEL Knoppix 5.0.1 - from rom (for US)
+       kernel pxeknife/knoppix/5.0.1/linux httpfs=http://140.211.167.171/share/pravin/KNOPPIX_V5.1.1CD-2007-01-04-EN.iso
+       append nodhcp lang=us ramdisk_size=100000 init=/etc/init apm=power-off nomce vga=791 initrd=pxeknife/knoppix/5.0.1/minirt.gz quiet BOOT_IMAGE=knoppix
+
+label knoppix502-alien
+       MENU LABEL Knoppix 5.0.1 - from alien  (for Europe)
+       kernel pxeknife/knoppix/5.0.1/linux httpfs=http://145.116.233.189/KNOPPIX_V5.1.1CD-2007-01-04-EN.iso
+       append nodhcp lang=us ramdisk_size=100000 init=/etc/init apm=power-off nomce vga=791 initrd=pxeknife/knoppix/5.0.1/minirt.gz quiet BOOT_IMAGE=knoppix
+
+
+label knoppix-txt502-rom
+       MENU LABEL Knoppix 5.0.1 - DVD - Text-rom(for US)
+       kernel pxeknife/knoppix/5.0.1/linux httpfs=http://140.211.167.171/share/pravin/KNOPPIX_V5.1.1CD-2007-01-04-EN.iso
+       APPEND nodhcp lang=us ramdisk_size=100000 init=/etc/init apm=power-off nomce vga=normal initrd=pxeknife/knoppix/5.0.1/miniroot.gz BOOT_IMAGE=knoppix
+
+label knoppix-txt502-alien
+       MENU LABEL Knoppix 5.0.1 - DVD - Text-alien(for EU)
+       kernel pxeknife/knoppix/5.0.1/linux httpfs=http://145.116.233.189/KNOPPIX_V5.1.1CD-2007-01-04-EN.iso
+       APPEND nodhcp lang=us ramdisk_size=100000 init=/etc/init apm=power-off nomce vga=normal initrd=pxeknife/knoppix/5.0.1/miniroot.gz BOOT_IMAGE=knoppix
+
+label knoppix-txt502-localhost
+       MENU LABEL Knoppix 5.0.1 - DVD - Text-rom(localhost--Dont try this)
+       kernel pxeknife/knoppix/5.0.1/linux httpfs=http://192.168.0.2/share/pravin/KNOPPIX_V5.1.1CD-2007-01-04-EN.iso
+       APPEND nodhcp lang=us ramdisk_size=100000 init=/etc/init apm=power-off nomce vga=normal initrd=pxeknife/knoppix/5.0.1/miniroot.gz BOOT_IMAGE=knoppix
+