USERNAME="casper"
USERFULLNAME="Live session user"
HOSTNAME="live"
-BUILD_SYSTEM="Debian"
+BUILD_SYSTEM="Custom"
mkdir -p $mountpoint
. /scripts/casper-helpers
+if [ ! -f /casper.vars ]; then
+ touch /casper.vars
+fi
+
parse_cmdline ()
{
+ PRESEEDS=
# looking for casper specifics options as kernel parameters
for x in $(cat /proc/cmdline); do
case $x in
;;
netboot*)
export NETBOOT=${x#netboot=} ;;
+ access=*)
+ export ACCESS=${x#access=} ;;
+ xdebconf)
+ export XDEBCONF="Yes" ;;
toram)
- export TORAM=1 ;;
- todisk=)
+ export TORAM="Yes" ;;
+ todisk=*)
export TODISK=${x#todisk=} ;;
showmounts)
- export SHOWMOUNTS=1 ;;
+ export SHOWMOUNTS="Yes" ;;
persistent)
- export PERSISTENT=1 ;;
+ export PERSISTENT="Yes" ;;
+ nopersistent)
+ export PERSISTENT="" ;;
ip*)
STATICIP=${x#ip=}
if [ "${STATICIP}" == "" ]; then
export STATICIP ;;
casper-getty)
export CASPERGETTY=1 ;;
+ bootfrom=*|live-media=*)
+ export LIVEMEDIA=${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=$(sed -e 's%.*console=%console=%' /proc/cmdline) ;;
- bootfrom=*)
- export LIVEMEDIA=${x#bootfrom=} ;;
- live-media=*)
- export LIVEMEDIA=${x#live-media=} ;;
- debian-installer/locale=*)
- export LOCALE=${x#debian-installer/locale=} ;;
- locale=*)
- export LOCALE=${x#locale=} ;;
- kbd-chooser/method=*)
- export KBD=${x#kbd-chooser/method=} ;;
- keyb=*)
- export KBD=${x#keyb=} ;;
- console-setup/layoutcode=*)
- export CSLAYOUT=${x#console-setup/layoutcode=} ;;
- console-setup/variantcode=*)
- export CSVARIANT=${x#console-setup/variantcode=} ;;
- console-setup/modelcode=*)
- export CSMODEL=${x#console-setup/modelcode=} ;;
+ export DEFCONSOLE="${x#*=}" ;;
esac
done
export NETBOOT
fi
fi
+
+ if [ -z "${MODULE}" ]; then
+ MODULE=order
+ fi
}
is_casper_path() {
fi
}
-get_fstype() {
- local FSTYPE
- local FSSIZE
- eval $(fstype < $1)
- if [ "$FSTYPE" != "unknown" ]; then
- echo $FSTYPE
- return 0
- fi
- /lib/udev/vol_id -t $1 2>/dev/null
-}
-
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 1
}
-is_supported_fs ()
-{
+is_supported_fs () {
# FIXME: do something better like the scan of supported filesystems
fstype="${1}"
case ${fstype} in
copytodev="${2}"
copyto="${copyfrom}_swap"
- size=$(used_fs_size "null" "${copyfrom}")
+ size=$(fs_size "" ${copyfrom} "used")
if [ "${copytodev}" = "ram" ]; then
# copying to ram:
else
# it should be a writable block device
if [ -b "${copytodev}" ]; then
- free_string="space"
- freespace="$(df -k ${copytodev} | grep -s ${copytodev} | awk '{print $4}')"
- fstype="$(get_fstype ${devname})"
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_begin_msg "Not enough free ${free_string} to copy live media in ${copytodev}."
- [ "$quiet" != "y" ] && log_end_msg
+ 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..
- [ "$quiet" != "y" ] && log_begin_msg "Copying live media to ${copytodev}..."
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}
- [ "$quiet" != "y" ] && log_end_msg
return 0
}
modprobe "${MP_QUIET}" af_packet # For DHCP
- ipconfig ${DEVICE} /tmp/net-${DEVICE}.conf
+ ipconfig ${DEVICE} /tmp/net-${DEVICE}.conf | tee /netboot.config
if [ "${NFSROOT}" = "auto" ]; then
NFSROOT=${ROOTSERVER}:${ROOTPATH}
todir="${2}"
snap_type="${3}"
- #size=$(used_fs_size "${fromdev}")
+ size=$(fs_size "${fromdev}" "" "used")
if [ -b "${fromdev}" ]; then
# look for free mem
# Let's just mount the read-only file systems first
rofsstring=""
rofslist=""
- if [ "${NETBOOT}" == "nfs" ] ; then
+ if [ "${NETBOOT}" = "nfs" ] ; then
roopt="nfsro" # go aroung a bug in nfs-unionfs locking
else
roopt="ro"
fi
+ # Read image names from ${MODULE}.lst if it exists
+ if [ -e "${image_directory}/${MODULE}.lst" ]; then
+ for image in $(cat "${image_directory}/${MODULE}.lst"); do
+ image_string="${image_string} ${image_directory}/${image}";
+ done
+ else
+ # If ${MODULE}.lst does not exist, create a list of images
+ for image_type in "ext2" "squashfs" "dir"; do
+ for image in "${image_directory}"/*."${image_type}"; do
+ if [ -e "${image}" ]; then
+ image_string="${image_string} ${image}";
+ fi
+ done
+ done
+ # Now sort the list
+ image_string=$(echo ${image_string} | sed -e 's/ /\n/g' | sort )
+ 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 "${backdev}" "${croot}/${imagename}" || panic "Can not mount $backdev ($image) on ${croot}/${imagename}" && rofsstring="${croot}/${imagename}=${roopt}:${rofsstring}" && rofslist="${croot}/${imagename} ${rofslist}"
+ for image in ${image_string}; 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
- done
+ 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
+
rofsstring=${rofsstring%:}
mkdir -p /cow
+
cowdevice="tmpfs"
cow_fstype="tmpfs"
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
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}")
fi
done
elif [ "${fstype}" = "squashfs" -o \
- "${fstype}" = "ext3" ] -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
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)
- if [ ! -z "${livefs_root}" ]; then
+ for i in 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19; do
+ livefs_root=$(find_livefs $i)
+ if [ -n "${livefs_root}" ]; then
break
fi
sleep 1
panic "Unable to find a medium containing a live file system"
fi
- if [ ! -z "${TORAM}" ]; then
- copy_live_to "${livefs_root}" "ram"
- elif [ ! -z "${TODISK}" ]; then
- copy_live_to "${livefs_root}" "${TODISK}"
+ 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}"