]> git.sur5r.net Git - bacula/rescue/commitdiff
More USB rescue code
authorKern Sibbald <kern@sibbald.com>
Fri, 2 Jan 2009 16:51:26 +0000 (16:51 +0000)
committerKern Sibbald <kern@sibbald.com>
Fri, 2 Jan 2009 16:51:26 +0000 (16:51 +0000)
rescue/linux/usb/README.usb [new file with mode: 0644]
rescue/linux/usb/getdiskinfo [new file with mode: 0755]
rescue/linux/usb/partitionusb [new file with mode: 0755]
rescue/linux/usb/prebuilt/QPU804.exe [new file with mode: 0644]
rescue/linux/usb/prebuilt/USBCDK810.iso [new file with mode: 0644]
rescue/linux/usb/prebuilt/casper [new file with mode: 0644]
rescue/linux/usb/prebuilt/initrd.gz [new file with mode: 0644]
rescue/linux/usb/prebuilt/syslinux.cfg [new file with mode: 0644]

diff --git a/rescue/linux/usb/README.usb b/rescue/linux/usb/README.usb
new file mode 100644 (file)
index 0000000..ac1e3aa
--- /dev/null
@@ -0,0 +1,22 @@
+
+This directory is used to build a USB key containing a Kubuntu 8.04 LiveCD
+with persistent OS files and persistent /home files.
+
+
+
+
+
+
+
+
+Kubuntu boot tricks:
+1. Booting with persistence added to the kernel options will permit
+   mounting of a USB casper-rw and home-rw partitions on the USB key.
+   casper-rw is used to store changed OS files, and home-rw is the
+   home directory.
+
+
+Bugs with Kubuntu boot process:
+1. The initrd.gz image must be opened, fixed and the repacked.
+2. The fix involves removing the ,mode=755 from the mount line for
+   the persistent OS partition (casper-rw) or /cow
diff --git a/rescue/linux/usb/getdiskinfo b/rescue/linux/usb/getdiskinfo
new file mode 100755 (executable)
index 0000000..4e90cd1
--- /dev/null
@@ -0,0 +1,463 @@
+#!/bin/sh
+#
+# Create bootstrap information files -- prelude to creating a
+#   Bacula Rescue Disk
+#
+#   Kern Sibbald, December MMII
+#      This source distributed under the GPL
+#
+export LANG=C
+di=diskinfo
+cwd=`pwd`
+host=`uname -s`
+
+case $host in
+ Linux)
+  ;;
+ FreeBSD | SunOS | IRIX)
+   echo ""
+   echo "This code is not yet adapted to this OS"     
+   exit 1
+   ;;
+ *)
+   echo ""
+   echo "Unknown operating system type: $host"     
+   exit 1
+   ;;
+esac
+if [ ! `whoami` = "root" ] ; then
+  echo ""
+  echo "You need to be root to run this, otherwise"
+  echo "sfdisk produces no output. Continuing anyway ..."
+  echo ""
+fi
+
+#
+#  First collect information
+#
+rm -rf format.* partition.* $di create-*
+echo "Begin collecting system info ..."
+mkdir -p $di
+cd $di
+mount -l >mount.bsi
+mount -l -t ext2 >mount.ext2.bsi
+mount -l -t ext3 >mount.ext3.bsi
+mount -l -t reiserfs >mount.rei.bsi
+cp /etc/fstab fstab.bsi
+cp /etc/mtab  mtab.bsi     
+df -Tl >df.bsi
+sfdisk -s >sfdisk.disks.bsi
+grep "^/dev/" sfdisk.disks.bsi | sed -n 's%\(^/dev/[A-Za-z]*\):.*$%\1%p' >disks.bsi
+for i in `cat disks.bsi`; do
+   j=`echo $i | cut -c6-`
+   sfdisk -l $i >sfdisk.$j.bsi 
+   sfdisk -d $i >sfdisk.make.$j.bsi
+done
+cat /proc/swaps > swaps.bsi
+route -n >route.bsi
+ifconfig >ifconfig.bsi
+
+# Gather LVM information
+# Only tested on LVM2
+dolvm=0
+if  which lvm > /dev/null 2>/dev/null ; then
+    echo "Gathering LVM information"
+    dolvm=1
+
+    lvm pvs --noheadings --nosuffix -o pv_name,vg_name | cat > lvm-pv.bsi
+    lvm vgs --noheadings --nosuffix -o vg_name,vg_extent_size --units=k | cat > lvm-vg.bsi
+    lvm lvs --noheadings --nosuffix -o lv_name,vg_name,lv_size --units=k | cat > lvm-lv.bsi
+fi
+
+echo "Done collecting info."
+
+#
+# Done collecting information
+#
+
+
+echo "Begin creating scripts ..."
+#
+# First create partitioning script(s)
+#
+for i in `cat disks.bsi`; do
+  j=`echo $i | cut -c6-`
+  cat >$cwd/partition.$j <<END_OF_DATA
+
+#!/bin/sh
+#
+#  Partition disk $i  -- created by getdiskinfo
+echo ""
+echo "This script will repartition disk $i."
+echo ""
+echo "IT WILL DESTROY ALL DATA ON DISK $i !!!!"
+echo ""
+echo -n "Are you sure you want to continue? yes/no: "
+read a
+if [ x\$a != xyes ] ; then
+   exit 1
+fi 
+echo "Partitioning disk $i"
+# zap partition info
+dd if=/dev/zero of=$i bs=512 count=2
+# repartition
+sfdisk $i <$di/sfdisk.make.$j.bsi | less
+echo ""
+echo "The previous partitioning was:"
+cat $di/sfdisk.$j.bsi
+#
+echo ""
+echo "The new partitioning is:"
+sfdisk -l $i
+echo ""
+echo "If the disk is correctly partitioned, you should"
+echo "now run the \"format.$j\" script."
+echo ""
+END_OF_DATA
+
+
+chmod 755 $cwd/partition.$j
+done
+echo "Done making partitioning scripts"
+
+if [ $dolvm -eq 1 ] ; then
+# 
+# LVM phase 1: create the Physical Volumess
+#
+    cat > $cwd/create-pv <<EOF
+#!/bin/sh
+#
+# Create PVs for LVM -- created by getdiskinfo
+echo ""
+echo "This script will format all partitions listed in diskinfo/lvm-pv.bsi"
+echo ""
+echo "IT WILL DESTROY ALL DATA ON THESE PARTITIONS!!!!"
+echo ""
+EOF
+    for pv in `cat lvm-pv.bsi | awk '{print $1}'`; do
+        echo "echo \"    $pv\"" >> $cwd/create-pv
+    done
+
+    cat >> $cwd/create-pv <<EOF
+echo ""
+echo -n "Are you sure you want to continue? yes/no: "
+read a
+if [ x\$a != xyes ] ; then
+   exit 1
+fi 
+EOF
+    for pv in `cat lvm-pv.bsi | awk '{print $1}'`; do
+       echo "echo \"Creating PV on $pv\"" >> $cwd/create-pv
+       echo "lvm pvcreate -ff -y -v $pv" >> $cwd/create-pv
+    done
+    echo "echo \"Done.\"" >> $cwd/create-pv
+    echo "echo \"If there were no errors, run create-vg to create the volume groups.\"" >> $cwd/create-pv
+    chmod +x $cwd/create-pv
+
+#
+# LVM phase 2: create Volume Groups
+#
+    cat > $cwd/create-vg <<EOF
+#!/bin/sh
+echo ""
+echo "This script will create all volume groups listed in diskinfo/lvm-vg.bsi"
+echo "You must have sucesfully run create-pv to create the requesite PVs first"
+echo ""
+echo -n "Are you sure you want to continue? yes/no: "
+read a
+if [ x\$a != xyes ] ; then
+   exit 1
+fi
+EOF
+    cat lvm-vg.bsi | awk '{print $1, $2}' | while read vg pesize ; do
+       echo "echo \"Creating VG $vg PE extent size $pesize kbytes"\" >> $cwd/create-vg
+       pelist=""
+       for pv in `cat lvm-pv.bsi | awk "\\\$2 == \"$vg\" { print \\\$1 }"` ; do
+           pelist="$pelist $pv"
+       done
+       echo "lvm vgcreate $vg -v -s ${pesize}k $pelist" >> $cwd/create-vg
+    done
+    echo "echo \"Done.\"" >> $cwd/create-vg
+    echo "echo \"If there were no errors, run create-lv to create the logical volumes.\"" >> $cwd/create-vg
+    chmod +x $cwd/create-vg
+
+
+#
+# LVM phase 3: create Logical Volumes 
+#
+# One quick sidenote: this script creates LVs with a size based on the
+# physical extent count, rather than the size in bytes.  This is because
+# at the time of writing this script, lvdisplay erroneously prints out
+# the size in 512 byte sector count rather than 1024 byte blocks.
+# Using the extent count should allow this script to continue to work
+# even after the bug is fixed.
+
+    cat > $cwd/create-lv <<EOF
+#!/bin/sh
+echo ""
+echo "This script will create all logical volumes listed in diskinfo/lvm-lv.bsi"
+echo "You must have sucesfully run create-vg to create the requesite VGs first"
+echo ""
+echo -n "Are you sure you want to continue? yes/no: "
+read a
+if [ x\$a != xyes ] ; then
+   exit 1
+fi
+EOF
+    cat lvm-lv.bsi | awk '{print $1, $2, $3}' | while read lv vg lvsize ; do
+       # lv=`echo $lv | sed -e 's/.*\///'`
+       echo "echo \"Creating LV $lv\"" >> $cwd/create-lv
+       echo "lvm lvcreate -L ${lvsize}k $vg -n $lv" >> $cwd/create-lv
+    done
+    chmod +x $cwd/create-lv
+fi
+
+#
+# Create formatting script(s)
+#
+echo "Begin making formatting script(s) ..."
+for i in `cat disks.bsi`; do
+  j=`echo $i | cut -c6-`
+  cat >$cwd/format.$j <<END_OF_DATA
+#!/bin/sh
+#
+#  Format all partitions on disk $i -- created by getdiskinfo
+#
+echo ""
+echo "This script will format all partitions on disk $i."
+echo ""
+echo "IT WILL DESTROY ALL DATA ON DISK $i !!!!"
+echo ""
+echo -n "Are you sure you want to continue? yes/no: "
+read a
+if [ x\$a != xyes ] ; then
+   exit 1
+fi 
+echo "Do you want to do a disk check for bad blocks?"
+echo -n "It is recommended, but takes time. yes/no: "
+read a
+if [ x\$a = xyes ] ; then
+   check="-c"
+else
+   check=
+fi
+END_OF_DATA
+
+   # Find swap partitions in output from sfdisk
+   k=`grep "^$i.*82  Linux swap" sfdisk.$j.bsi | cut -d ' ' -f 1`
+   for disk in $k; do
+      echo "echo \"Formatting $disk -- swap partition\"" >>$cwd/format.$j
+      echo "mkswap $check $disk" >>$cwd/format.$j
+      echo "echo \"\"" >>$cwd/format.$j
+   done
+   # Find ext2 partitions in mount output
+   k=`grep "^$i" mount.ext2.bsi | cut -d ' ' -f 1`
+   for disk in $k; do
+      echo "echo \"Formating $disk -- ext2 partition\"" >>$cwd/format.$j
+      label=`grep "^$disk" mount.ext2.bsi | cut -d ' ' -f 7 | cut -c2- | cut -d ] -f 1`
+      if [ x$label = x ] ; then
+         echo "mke2fs -v \$check $disk" >>$cwd/format.$j
+      else
+         echo "mke2fs -v \$check -L $label $disk" >>$cwd/format.$j
+      fi
+      echo "echo \"\"" >>$cwd/format.$j
+   done
+   # Find ext3 partitions in mount output
+   k=`grep "^$i" mount.ext3.bsi | cut -d ' ' -f 1`
+   for disk in $k; do
+      echo "echo \"Formating $disk -- ext3 partition\"" >>$cwd/format.$j
+      label=`grep "^$disk" mount.ext3.bsi | cut -d ' ' -f 7 | cut -c2- | cut -d ] -f 1`
+      if [ x$label = x ] ; then
+         echo "mke2fs -v -j \$check $disk" >>$cwd/format.$j
+      else
+         echo "mke2fs -v -j \$check -L $label $disk" >>$cwd/format.$j
+      fi
+      echo "echo \"\"" >>$cwd/format.$j
+   done
+   # Find reiserfs partitions in mount output
+   k=`grep "^$i" mount.rei.bsi | cut -d ' ' -f 1`
+   for disk in $k; do
+      echo "echo \"Formating $disk -- reiser partition\"" >>$cwd/format.$j
+      label=`grep "^$disk" mount.rei.bsi | cut -d ' ' -f 7 | cut -c2- | cut -d ] -f 1`
+      if [ x$label = x ] ; then
+         echo "mkereiserfs -V \$check $disk" >>$cwd/format.$j
+      else
+         echo "mkereiserfs -V \$check -L $label $disk" >>$cwd/format.$j
+      fi
+      echo "echo \"\"" >>$cwd/format.$j
+   done
+   chmod 755 $cwd/format.$j
+done
+
+#
+# Create LVM formatting scripts(s)
+#
+# Somebody more clever than I with bash scripting
+# could probably factor a lot of this code out.
+#
+if [ $dolvm -eq 1 ] ; then
+    echo "Begin making LVM formatting script(s) ..."
+    for i in `cat lvm-vg.bsi | awk '{print $1}'`; do
+       cat >$cwd/format.$i <<END_OF_DATA
+#!/bin/sh
+#
+#  Format all partitions on VG $i -- created by getdiskinfo
+#
+echo ""
+echo "This script will format all LVs on VG $i."
+echo ""
+echo "IT WILL DESTROY ALL DATA ON DISK $i !!!!"
+echo ""
+echo -n "Are you sure you want to continue? yes/no: "
+read a
+if [ x\$a != xyes ] ; then
+   exit 1
+fi
+echo "Do you want to do a disk check for bad blocks?"
+echo -n "It is recommended, but takes time. yes/no: "
+read a
+if [ x\$a = xyes ] ; then
+   check="-c"
+else
+   check=
+fi
+END_OF_DATA
+#   set -x
+   # Find swap partitions in output from sfdisk
+   mapper="/dev/mapper/${i}"
+   k=`grep "^$mapper" swaps.bsi | awk '{print $1}'`
+   for disk in $k; do
+      echo "echo \"Formatting $disk -- swap partition\"" >>$cwd/format.$i
+      echo "mkswap $check $disk" >>$cwd/format.$i
+      echo "echo \"\"" >>$cwd/format.$i
+   done
+   # Find ext2 partitions in mount output
+   k=`grep "^$mapper" mount.ext2.bsi | cut -d ' ' -f 1`
+   for disk in $k; do
+      echo "echo \"Formating $disk -- ext2 partition\"" >>$cwd/format.$i
+      label=`grep "^$disk on" mount.ext2.bsi | cut -d ' ' -f 7 | cut -c2- | cut -d ] -f 1`
+      if [ x$label = x ] ; then
+         echo "mke2fs -v \$check $disk" >>$cwd/format.$i
+      else
+         echo "mke2fs -v \$check -L $label $disk" >>$cwd/format.$i
+      fi
+      echo "echo \"\"" >>$cwd/format.$i
+   done
+   # Find ext3 partitions in mount output
+   k=`grep "^$mapper" mount.ext3.bsi | cut -d ' ' -f 1`
+   for disk in $k; do
+      echo "echo \"Formating $disk -- ext3 partition\"" >>$cwd/format.$i
+      label=`grep "^$disk on" mount.ext3.bsi | cut -d ' ' -f 7 | cut -c2- | cut -d ] -f 1`
+      if [ x$label = x ] ; then
+         echo "mke2fs -v -j \$check $disk" >>$cwd/format.$i
+      else
+         echo "mke2fs -v -j \$check -L $label $disk" >>$cwd/format.$i
+      fi
+      echo "echo \"\"" >>$cwd/format.$i
+   done
+   # Find reiserfs partitions in mount output
+   k=`grep "^$mapper" mount.rei.bsi | cut -d ' ' -f 1`
+   for disk in $k; do
+      echo "echo \"Formating $disk -- reiser partition\"" >>$cwd/format.$i
+      label=`grep "^$disk on" mount.rei.bsi | cut -d ' ' -f 7 | cut -c2- | cut -d ] -f 1`
+      if [ x$label = x ] ; then
+         echo "mkereiserfs -V \$check $disk" >>$cwd/format.$i
+      else
+         echo "mkereiserfs -V \$check -L $label $disk" >>$cwd/format.$i
+      fi
+      echo "echo \"\"" >>$cwd/format.$i
+   done
+   chmod 755 $cwd/format.$i
+   done
+fi
+
+cd $cwd
+
+#
+# Create network start script
+#
+ifconfig eth0 2>/dev/null >/dev/null
+if [ $? = 0 ] ; then
+  ip=`ifconfig eth0 | grep inet | head -1 | sed -n 's/\ \+inet addr:\([0-9]\+\(\.[0-9]\+\)\{3\}\).*/\1/p'`
+  cat >start_network <<END_OF_DATA
+#!/bin/sh
+#
+#  Start network -- created by getdiskinfo
+#
+ip=$ip
+dev=eth0
+ifconfig lo up
+ifconfig \$dev up \$ip
+END_OF_DATA
+else
+   echo "Warning, no eth0 found."
+   echo "#!/bin/sh" >start_network
+fi
+# Try eth1
+ifconfig eth1 2>/dev/null >/dev/null
+if [ $? = 0 ] ; then
+  ip=`ifconfig eth1 | grep inet | head -1 | sed -n 's/\ \+inet addr:\([0-9]\+\(\.[0-9]\+\)\{3\}\).*/\1/p'`
+  cat >>start_network <<END_OF_DATA
+ip1=$ip
+dev1=eth1
+ifconfig \$dev1 up \$ip1
+END_OF_DATA
+fi
+ip=`route -n | grep UG | head -1 | awk '{print $2}'`
+dev=`route -n | grep UG | head -1 | awk '{print $8}'`
+cat >>start_network <<END_OF_DATA
+route add default gw $ip dev $dev
+END_OF_DATA
+
+chmod 755 start_network
+
+cat >mount_drives <<END_OF_DATA
+#!/bin/sh
+#
+#  Mount disk drives  -- created by getdiskinfo
+#
+PATH=$PATH:/mnt/disk/sbin:/mnt/disk/bin
+END_OF_DATA
+TMP1=`mktemp gdi.1.XXXXXXXXXX`
+TMP2=`mktemp gdi.2.XXXXXXXXXX`
+if test x${TMP1} = x; then
+   TMP1="/tmp/1$$"
+   if test -f ${TMP1}; then
+      echo "Temp file security problem on: ${TMP1}"
+      exit 1
+   fi
+fi
+if test x${TMP2} = x; then
+   TMP2="/tmp/2$$"
+   if test -f ${TMP2}; then
+      echo "Temp file security problem on: ${TMP2}"
+      rm -f ${TMP1}
+      exit 1
+   fi
+fi
+sed -n 's/\(^.*\)\ on\ \(.*\)\ type.*$/\1 \/mnt\/disk\2/p' $di/mount.ext2.bsi >${TMP1}
+sed -n 's/\(^.*\)\ on\ \(.*\)\ type.*$/\1 \/mnt\/disk\2/p' $di/mount.ext3.bsi >>${TMP1}
+sed -n 's/\(^.*\)\ on\ \(.*\)\ type.*$/\1 \/mnt\/disk\2/p' $di/mount.rei.bsi >>${TMP1}
+# sort so that / is first
+sort -k 2 <${TMP1} >${TMP2}
+# output mkdir followed by its mount
+sed -n 's/\(^.*\)\ \(.*$\)/mkdir -p \2\
+mount \1 \2/p' ${TMP2} >>mount_drives
+
+# Now build unmount_drives
+cat >umount_drives <<END_OF_DATA
+#!/bin/sh
+#
+#  Unmount disk drives  -- created by getdiskinfo
+#
+END_OF_DATA
+sort -r -k 2 <${TMP1} >${TMP2}
+sed -n 's/\(^.*\)\ \(.*$\)/umount \2/p' ${TMP2} >>umount_drives
+echo "umount /mnt/cdrom 2>/dev/null >/dev/null" >>umount_drives
+echo "sync" >>umount_drives
+echo "sync" >>umount_drives
+
+rm -f ${TMP1} ${TMP2}
+
+chmod 755 mount_drives umount_drives
+echo "Done building scripts."
diff --git a/rescue/linux/usb/partitionusb b/rescue/linux/usb/partitionusb
new file mode 100755 (executable)
index 0000000..b21fd5c
--- /dev/null
@@ -0,0 +1,64 @@
+#!/bin/sh
+#
+# Partition the USB stick -- the stick is assumed to be at least 3GB in size
+#
+# First delete all existing partitions
+#
+
+if [ ! `whoami` = "root" ] ; then
+  echo ""
+  echo "You need to be root to run this shell script"
+  echo ""
+  exit 1
+fi
+if [ "x$USB_DEVICE" = "x" ] ; then
+  if [ "x$1" = "x" ] ; then
+     echo "You must supply the USB device name on the command line or in USB_DEVICE"
+     exit 1
+  else
+     dev=$1
+  fi
+else
+  dev=$USB_DEVICE
+fi
+echo "This script will distroy everything on $dev"
+echo "Answer yes to continue "
+read a
+if [ "$a" != "yes" ] ; then
+  echo "Device $dev unchanged"
+  exit 1
+fi
+
+fdisk $dev <<EOF
+d
+4
+d
+3
+d
+2
+d
+1
+n
+p
+1
+
++900M
+t
+1
+6
+a
+1
+n
+p
+2
+
++1000M
+n
+p
+3
+
+
+p
+w
+EOF
+sync
diff --git a/rescue/linux/usb/prebuilt/QPU804.exe b/rescue/linux/usb/prebuilt/QPU804.exe
new file mode 100644 (file)
index 0000000..d06e455
Binary files /dev/null and b/rescue/linux/usb/prebuilt/QPU804.exe differ
diff --git a/rescue/linux/usb/prebuilt/USBCDK810.iso b/rescue/linux/usb/prebuilt/USBCDK810.iso
new file mode 100644 (file)
index 0000000..666d632
Binary files /dev/null and b/rescue/linux/usb/prebuilt/USBCDK810.iso differ
diff --git a/rescue/linux/usb/prebuilt/casper b/rescue/linux/usb/prebuilt/casper
new file mode 100644 (file)
index 0000000..532a653
--- /dev/null
@@ -0,0 +1,657 @@
+#!/bin/sh
+
+# set -e
+
+export PATH=/root/usr/bin:/root/usr/sbin:/root/bin:/root/sbin:/usr/bin:/usr/sbin:/bin:/sbin
+
+mountpoint=/cdrom
+
+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
+
+# Pendrivelinux fix
+
+parse_cmdline ()
+{
+    PRESEEDS=
+    # looking for casper specifics options as kernel parameters
+    for x in $(cat /proc/cmdline); do
+        case $x in
+            userfullname=*)
+                export USERFULLNAME=${x#userfullname=}
+                export CASPERCONF="changed"
+                ;;
+            hostname=*)
+                export HOSTNAME=${x#hostname=}
+                export CASPERCONF="changed"
+                ;;
+            username=*)
+                export USERNAME=${x#username=}
+                export CASPERCONF="changed"
+                ;;
+            netboot*)
+                export NETBOOT=${x#netboot=} ;;
+            access=*)
+                export ACCESS=${x#access=} ;;
+            xdebconf)
+                export XDEBCONF="Yes" ;;
+            toram)
+                export TORAM="Yes" ;;
+            todisk=*)
+                export TODISK=${x#todisk=} ;;
+            showmounts)
+                export SHOWMOUNTS="Yes" ;;
+            persistent)
+                export PERSISTENT="Yes" ;;
+            nopersistent)
+                export PERSISTENT="" ;;
+            ip*)
+                STATICIP=${x#ip=}
+                if [ "${STATICIP}" == "" ]; then
+                    STATICIP="frommedia"
+                fi
+                export STATICIP ;;
+            casper-getty)
+                export CASPERGETTY=1 ;;
+            bootfrom=*|live-media=*)
+                export LIVEMEDIA=${x#*=} ;;
+            live-media-encryption=*|encryption=*)
+                export LIVEMEDIA_ENCRYPTION=${x#*=} ;;
+            live-media-timeout=*)
+                export LIVEMEDIA_TIMEOUT=${x#live-media-timeout=} ;;
+            live-media-offset=*)
+                export LIVEMEDIA_OFFSET=${x#live-media-offset=} ;;
+            locale=*|debian-installer/locale=*)
+                export LOCALE=${x#*=} ;;
+            keyb=*|kbd-chooser/method=*)
+                export KBD=${x#*=} ;;
+            klayout=*|console-setup/layoutcode=*)
+                export KLAYOUT=${x#*=} ;;
+            koptions=*)
+                export KOPTIONS=${x#koptions=} ;;
+            kvariant=*|console-setup/variantcode=*)
+                export KVARIANT=${x#*=} ;;
+            kmodel=*|console-setup/modelcode=*)
+                export KMODEL=${x#*=} ;;
+            module=*)
+                export MODULE=${x#module=} ;;
+            preseed/file=*|file=*)
+                export LOCATION="${x#*=}" ;;
+            */*=*)
+                question="${x%%=*}"
+                value="${x#*=}"
+                PRESEEDS="${PRESEEDS}\"${question}=${value}\" "
+                ;;
+            console=*)
+                export DEFCONSOLE="${x#*=}" ;;
+        esac
+    done
+
+    # sort of compatibility with netboot.h from linux docs
+    if [ -z "${NETBOOT}" ]; then
+        if [ "${ROOT}" == "/dev/nfs" ]; then
+            NETBOOT="nfs"
+            export NETBOOT
+        elif [ "${ROOT}" == "/dev/cifs" ]; then
+            NETBOOT="cifs"
+            export NETBOOT
+        fi
+    fi
+
+    if [ -z "${MODULE}" ]; then
+        MODULE=order
+    fi
+}
+
+# Pendrivelinux fix ended
+
+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
+}
+
+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])"; then
+        return 0
+    fi
+    return 1
+}
+
+is_supported_fs () {
+    # FIXME: do something better like the scan of supported filesystems
+    fstype="${1}"
+    case ${fstype} in
+        vfat|iso9660|udf|ext2|ext3|ntfs)
+            return 0
+            ;;
+    esac
+    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}"
+
+    # add by penk
+    for target in autorun.inf boot boot.catalog casper info initrd.gz logo.ico misc opt vmlinuz; do
+        cp -a ${copyfrom}/${target} ${copyto} # "cp -a" from busybox also copies hidden files
+    done
+
+    umount ${copyfrom}
+    mount -r -o move ${copyto} ${copyfrom}
+    rmdir ${copyto}
+    return 0
+}
+
+do_netmount() {
+    rc=1
+
+    modprobe "${MP_QUIET}" af_packet # For DHCP
+
+    ipconfig ${DEVICE} /tmp/net-${DEVICE}.conf | tee /netboot.config
+
+    if [ "${NFSROOT}" = "auto" ]; then
+        NFSROOT=${ROOTSERVER}:${ROOTPATH}
+    fi
+
+    [ "$quiet" != "y" ] && log_begin_msg "Trying netboot from ${NFSROOT}"
+
+    if [ "${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 for loop is an ugly HACK round an nfs bug
+    for i in 0 1 2 3 4 5 6 7 8 9 a b c d e f 10 11 12 13; do
+        nfsmount -o nolock -o ro ${NFSOPTS} "${NFSROOT}" "${mountpoint}" && rc=0 && break
+        sleep 1
+    done
+    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 "${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 squashfs
+
+    # 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
+    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
+               if [ -z "${fstype}" ]; then
+                   fstype=squashfs
+               fi
+                mkdir -p "${croot}/${imagename}"
+                mount -t "${fstype}" -o ro "${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"
+
+    # 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}")
+        else
+            [ "$quiet" != "y" ] && log_warning_msg "Unable to find the persistent medium"
+        fi
+    fi
+
+    mount ${cowdevice} -t ${cow_fstype} -o rw /cow || panic "Can not mount $cowdevice on /cow"
+
+    # add by penk
+    if grep -q aufs /proc/cmdline; then
+        modprobe aufs
+        mount -t aufs -o dirs=/cow=rw:$rofsstring unionfs "$rootmnt" || panic "Unionfs (aufs) mount failed"
+    else 
+        modprobe "${MP_QUIET}" -b unionfs
+        mount -t unionfs -o dirs=/cow=rw:$rofsstring unionfs "$rootmnt" ||  panic "Unionfs (unionfs) mount failed"
+    fi
+
+    # 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 "${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}"
+    if [ -z "${devname}" ]; then
+        devname=$(sys2dev "${sysdev}")
+    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 "${devname}" $mountpoint || continue
+        if is_casper_path $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}"; 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 -v loop | grep -v ram); 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}" = "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
+}
+
+pulsate() {
+    if [ -x /sbin/usplash_write ]; then
+        /sbin/usplash_write "PULSATE"
+    fi
+}
+
+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
+
+    # add by penk
+    parse_cmdline
+
+    set_usplash_timeout
+    [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/casper-premount"
+    pulsate
+    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 the network rootfs live file system"
+        fi
+    else
+        # Scan local devices for the image
+        for i in 0 1 2 3 4 5 6 7 8 9 a b c d e f 10 11 12 13; do
+            livefs_root=$(find_livefs $i)
+            if [ "${livefs_root}" ]; then
+                break
+            fi
+            sleep 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"
+
+    pulsate
+    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/rescue/linux/usb/prebuilt/initrd.gz b/rescue/linux/usb/prebuilt/initrd.gz
new file mode 100644 (file)
index 0000000..b6949a9
Binary files /dev/null and b/rescue/linux/usb/prebuilt/initrd.gz differ
diff --git a/rescue/linux/usb/prebuilt/syslinux.cfg b/rescue/linux/usb/prebuilt/syslinux.cfg
new file mode 100644 (file)
index 0000000..c6a9dea
--- /dev/null
@@ -0,0 +1,40 @@
+DEFAULT persistent
+GFXBOOT bootlogo
+APPEND  file=/preseed/kubuntu.seed boot=casper initrd=/casper/initrd.gz --
+LABEL persistent
+  menu label ^Start Kubuntu saving changes to USB
+  kernel /casper/vmlinuz
+  append  file=/preseed/kubuntu.seed boot=casper persistent initrd=/casper/initrd.gz --
+LABEL live
+  menu label ^Run Kubuntu without saving changes
+  kernel /casper/vmlinuz
+  append  file=/preseed/kubuntu.seed boot=casper initrd=/casper/initrd.gz --
+LABEL live-install
+  menu label ^Install Kubuntu
+  kernel /casper/vmlinuz
+  append  file=/preseed/kubuntu.seed boot=casper only-ubiquity initrd=/casper/initrd.gz --
+LABEL rescue
+  menu label ^Rescue a broken system
+  kernel /casper/vmlinuz
+  append  file=/preseed/cli.seed boot=casper persistent rescue/enable=true initrd=/casper/initrd.gz --
+LABEL memtest
+  menu label Test ^memory
+  kernel mt86plus
+  append -
+LABEL hd
+  menu label ^Boot from first hard disk
+  localboot 0x80
+  append -
+DISPLAY isolinux.txt
+TIMEOUT 300
+PROMPT 1
+F1 f1.txt
+F2 f2.txt
+F3 f3.txt
+F4 f4.txt
+F5 f5.txt
+F6 f6.txt
+F7 f7.txt
+F8 f8.txt
+F9 f9.txt
+F0 f10.txt