5 export PATH=/root/usr/bin:/root/usr/sbin:/root/bin:/root/sbin:/usr/bin:/usr/sbin:/bin:/sbin
9 root_persistence="casper-rw"
10 home_persistence="home-rw"
11 root_snapshot_label="casper-sn"
12 home_snapshot_label="home-sn"
15 USERFULLNAME="Live session user"
21 [ -f /etc/casper.conf ] && . /etc/casper.conf
22 export USERNAME USERFULLNAME HOSTNAME BUILD_SYSTEM
24 . /scripts/casper-helpers
26 if [ ! -f /casper.vars ]; then
33 # looking for casper specifics options as kernel parameters
34 for x in $(cat /proc/cmdline); do
37 export USERFULLNAME=${x#userfullname=}
38 export CASPERCONF="changed"
41 export HOSTNAME=${x#hostname=}
42 export CASPERCONF="changed"
45 export USERNAME=${x#username=}
46 export CASPERCONF="changed"
49 export NETBOOT=${x#netboot=} ;;
51 export ACCESS=${x#access=} ;;
53 export XDEBCONF="Yes" ;;
57 export TODISK=${x#todisk=} ;;
59 export SHOWMOUNTS="Yes" ;;
61 export PERSISTENT="Yes" ;;
63 export PERSISTENT="" ;;
66 if [ "${STATICIP}" == "" ]; then
71 export CASPERGETTY=1 ;;
72 bootfrom=*|live-media=*)
73 export LIVEMEDIA=${x#*=} ;;
74 live-media-encryption=*|encryption=*)
75 export LIVEMEDIA_ENCRYPTION=${x#*=} ;;
77 export LIVEMEDIA_TIMEOUT=${x#live-media-timeout=} ;;
79 export LIVEMEDIA_OFFSET=${x#live-media-offset=} ;;
80 locale=*|debian-installer/locale=*)
81 export LOCALE=${x#*=} ;;
82 keyb=*|kbd-chooser/method=*)
84 klayout=*|console-setup/layoutcode=*)
85 export KLAYOUT=${x#*=} ;;
87 export KOPTIONS=${x#koptions=} ;;
88 kvariant=*|console-setup/variantcode=*)
89 export KVARIANT=${x#*=} ;;
90 kmodel=*|console-setup/modelcode=*)
91 export KMODEL=${x#*=} ;;
93 export MODULE=${x#module=} ;;
94 preseed/file=*|file=*)
95 export LOCATION="${x#*=}" ;;
99 PRESEEDS="${PRESEEDS}\"${question}=${value}\" "
102 export DEFCONSOLE="${x#*=}" ;;
106 # sort of compatibility with netboot.h from linux docs
107 if [ -z "${NETBOOT}" ]; then
108 if [ "${ROOT}" == "/dev/nfs" ]; then
111 elif [ "${ROOT}" == "/dev/cifs" ]; then
117 if [ -z "${MODULE}" ]; then
124 if [ -d "$path/casper" ]; then
125 if [ "$(echo $path/casper/*.squashfs)" != "$path/casper/*.squashfs" ] ||
126 [ "$(echo $path/casper/*.ext2)" != "$path/casper/*.ext2" ] ||
127 [ "$(echo $path/casper/*.dir)" != "$path/casper/*.dir" ]; then
134 get_backing_device() {
137 echo $(setup_loop "$1" "loop" "/sys/block/loop*" '0' "${LIVEMEDIA_ENCRYPTION}")
143 panic "Unrecognized casper filesystem: $1"
148 match_files_in_dir() {
149 # Does any files match pattern $1 ?
152 if [ "$(echo $pattern)" != "$pattern" ]; then
158 mount_images_in_directory() {
161 if match_files_in_dir "$directory/casper/*.squashfs" ||
162 match_files_in_dir "$directory/casper/*.ext2" ||
163 match_files_in_dir "$directory/casper/*.dir"; then
164 setup_unionfs "$directory/casper" "$rootmnt"
171 sysfs_path="${1#/sys}"
172 if /lib/udev/path_id "${sysfs_path}" | grep -E -q "ID_PATH=(usb|pci-[^-]*-[ide|scsi|usb])"; then
179 # FIXME: do something better like the scan of supported filesystems
182 vfat|iso9660|udf|ext2|ext3|ntfs)
192 copyto="${copyfrom}_swap"
194 size=$(fs_size "" ${copyfrom} "used")
196 if [ "${copytodev}" = "ram" ]; then
198 freespace=$( expr $(awk '/MemFree/{print $2}' /proc/meminfo) + $( cat /proc/meminfo | grep Cached | head -n 1 | awk '/Cached/{print $2}' - ) )
199 mount_options="-o size=${size}k"
204 # it should be a writable block device
205 if [ -b "${copytodev}" ]; then
208 fstype=$(get_fstype "${dev}")
209 freespace=$(fs_size "${dev}")
211 [ "$quiet" != "y" ] && log_warning_msg "${copytodev} is not a block device."
215 if [ "${freespace}" -lt "${size}" ] ; then
216 [ "$quiet" != "y" ] && log_warning_msg "Not enough free ${free_string} (${freespace}k > ${size}k) to copy live media in ${copytodev}."
222 echo "mount -t ${fstype} ${mount_options} ${dev} ${copyto}"
223 mount -t "${fstype}" ${mount_options} "${dev}" "${copyto}"
224 cp -a ${copyfrom}/* ${copyto} # "cp -a" from busybox also copies hidden files
226 mount -r -o move ${copyto} ${copyfrom}
234 modprobe "${MP_QUIET}" af_packet # For DHCP
236 ipconfig ${DEVICE} /tmp/net-${DEVICE}.conf | tee /netboot.config
238 if [ "${NFSROOT}" = "auto" ]; then
239 NFSROOT=${ROOTSERVER}:${ROOTPATH}
242 [ "$quiet" != "y" ] && log_begin_msg "Trying netboot from ${NFSROOT}"
244 if [ "${NETBOOT}" != "nfs" ] && do_cifsmount ; then
246 elif do_nfsmount ; then
252 [ "$quiet" != "y" ] && log_end_msg
258 modprobe "${MP_QUIET}" nfs
259 if [ -z "${NFSOPTS}" ]; then
263 [ "$quiet" != "y" ] && log_begin_msg "Trying nfsmount -o nolock -o ro ${NFSOPTS} ${NFSROOT} ${mountpoint}"
264 # FIXME: This for loop is an ugly HACK round an nfs bug
265 for i in 0 1 2 3 4 5 6 7 8 9 a b c d e f 10 11 12 13; do
266 nfsmount -o nolock -o ro ${NFSOPTS} "${NFSROOT}" "${mountpoint}" && rc=0 && break
274 if [ -x "/sbin/mount.cifs" ]; then
275 if [ -z "${NFSOPTS}" ]; then
276 CIFSOPTS="-ouser=root,password="
278 CIFSOPTS="${NFSOPTS}"
281 [ "$quiet" != "y" ] && log_begin_msg "Trying mount.cifs ${NFSROOT} ${mountpoint} ${CIFSOPTS}"
282 modprobe "${MP_QUIET}" cifs
284 if mount.cifs "${NFSROOT}" "${mountpoint}" "${CIFSOPTS}" ; then
297 size=$(fs_size "${fromdev}" "" "used")
299 if [ -b "${fromdev}" ]; then
301 if [ -n "${HOMEMOUNTED}" -a "${snap_type}" = "HOME" ]; then
302 todev=$(cat /proc/mounts | grep -s " $(base_path ${todir}) " | awk '{print $1}' )
303 freespace=$(df -k | grep -s ${todev} | awk '{print $4}')
305 freespace=$( expr $(awk '/MemFree/{print $2}' /proc/meminfo) + $( cat /proc/meminfo | grep Cached | head -n 1 | awk '/Cached/{print $2}' - ))
308 tomount="/mnt/tmpsnap"
309 if [ ! -d "${tomount}" ] ; then
310 mkdir -p "${tomount}"
313 fstype=$(get_fstype "${fromdev}")
314 if [ -n "${fstype}" ]; then
316 mount -t "${fstype}" -o ro "${fromdev}" "${tomount}"
317 cp -a "${tomount}"/* ${todir}
320 log_warning_msg "Unrecognized fstype: ${fstype} on ${fromdev}:${snap_type}"
324 if echo ${fromdev} | grep -qs loop; then
325 losetup -d "${fromdev}"
330 [ "$quiet" != "y" ] && log_warning_msg "Unable to find the snapshot ${snap_type} medium"
336 # Look for $snap_label.* in block devices and copy the contents to $snap_mount
337 # and remember the device and filename for resync on exit in casper.init
343 snapdata=$(find_files "${snap_label}.squashfs ${snap_label}.cpio.gz ${snap_label}.ext2")
344 if [ ! -z "${snapdata}" ]; then
345 snapdev="$(echo ${snapdata} | cut -f1 -d ' ')"
346 snapback="$(echo ${snapdata} | cut -f2 -d ' ')"
347 snapfile="$(echo ${snapdata} | cut -f3 -d ' ')"
348 if echo "${snapfile}" | grep -qs '\(squashfs\|ext2\)'; then
349 # squashfs or ext2 snapshot
350 dev=$(get_backing_device "${snapback}/${snapfile}")
351 if ! do_snap_copy "${dev}" "${snap_mount}" "${snap_type}"; then
352 log_warning_msg "Impossible to include the ${snapfile} Snapshot"
357 if ! (cd "${snap_mount}" && zcat "${snapback}/${snapfile}" | cpio -i -u -d 2>/dev/null) ; then
358 log_warning_msg "Impossible to include the ${snapfile} Snapshot"
364 dev=$(find_cow_device "${snap_label}")
365 if [ -b ${dev} ]; then
366 if echo "${dev}" | grep -qs loop; then
367 # strange things happens, user confused?
368 snaploop=$( losetup ${dev} | awk '{print $3}' | tr -d '()' )
369 snapfile=$(basename ${snaploop})
370 snapdev=$(cat /proc/mounts | awk '{print $2,$1}' | grep -es "^$( dirname ${snaploop} )" | cut -f2 -d ' ')
374 if ! do_snap_copy "${dev}" "${snap_mount}" "${snap_type}" ; then
375 log_warning_msg "Impossible to include the ${snap_label} Snapshot"
378 if [ -n "${snapfile}" ]; then
379 # it was a loop device, user confused
384 log_warning_msg "Impossible to include the ${snap_label} Snapshot"
388 echo "export ${snap_type}SNAP="${snap_mount}":${snapdev}:${snapfile}" >> /etc/casper.conf # for resync on reboot/halt
396 modprobe "${MP_QUIET}" -b unionfs
398 # run-init can't deal with images in a subdir, but we're going to
399 # move all of these away before it runs anyway. No, we're not,
400 # put them in / since move-mounting them into / breaks mono and
405 # Let's just mount the read-only file systems first
408 if [ "${NETBOOT}" = "nfs" ] ; then
409 roopt="nfsro" # go aroung a bug in nfs-unionfs locking
414 # Read image names from ${MODULE}.lst if it exists
415 if [ -e "${image_directory}/${MODULE}.lst" ]; then
416 for image in $(cat "${image_directory}/${MODULE}.lst"); do
417 image_string="${image_string} ${image_directory}/${image}";
420 # If ${MODULE}.lst does not exist, create a list of images
421 for image_type in "ext2" "squashfs" "dir"; do
422 for image in "${image_directory}"/*."${image_type}"; do
423 if [ -e "${image}" ]; then
424 image_string="${image_string} ${image}";
429 image_string=$(echo ${image_string} | sed -e 's/ /\n/g' | sort )
433 for image in ${image_string}; do
434 imagename=$(basename "${image}")
435 if [ -d "${image}" ]; then
436 # it is a plain directory: do nothing
437 rofsstring="${image}=${roopt}:${rofsstring}"
438 rofslist="${image} ${rofslist}"
439 elif [ -f "${image}" ]; then
440 backdev=$(get_backing_device "$image")
441 fstype=$(get_fstype "${backdev}")
442 if [ "${fstype}" = "unknown" ]; then
443 panic "Unknown file system type on ${backdev} (${image})"
445 mkdir -p "${croot}/${imagename}"
446 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}"
450 rofsstring=${rofsstring%:}
457 # Looking for "${root_persistence}" device or file
458 if [ -n "${PERSISTENT}" ]; then
459 cowprobe=$(find_cow_device "${root_persistence}")
460 if [ -b "${cowprobe}" ]; then
461 cowdevice=${cowprobe}
462 cow_fstype=$(get_fstype "${cowprobe}")
464 [ "$quiet" != "y" ] && log_warning_msg "Unable to find the persistent medium"
468 mount ${cowdevice} -t ${cow_fstype} -o rw /cow || panic "Can not mount $cowdevice on /cow"
470 mount -t unionfs -o dirs=/cow=rw:$rofsstring unionfs "$rootmnt" || panic "Unionfs mount failed"
472 # Adding other custom mounts
473 if [ -n "${PERSISTENT}" ]; then
474 # directly mount /home
475 # FIXME: add a custom mounts configurable system
476 homecow=$(find_cow_device "${home_persistence}" )
477 if [ -b "${homecow}" ]; then
478 mount -t $(get_fstype "${homecow}") -o rw "${homecow}" "${rootmnt}/home"
479 export HOMEMOUNTED=1 # used to proper calculate free space in do_snap_copy()
481 [ "$quiet" != "y" ] && log_warning_msg "Unable to find the persistent home medium"
483 # Look for other snapshots to copy in
484 try_snap "${root_snapshot_label}" "${rootmnt}" "ROOT"
485 try_snap "${home_snapshot_label}" "${rootmnt}/home" "HOME"
488 if [ -n "${SHOWMOUNTS}" ]; then
489 for d in ${rofslist}; do
490 mkdir -p "${rootmnt}/casper/${d##*/}"
492 *.dir) # do nothing # mount -o bind "${d}" "${rootmnt}/casper/${d##*/}"
494 *) mount -o move "${d}" "${rootmnt}/casper/${d##*/}"
500 # shows cow fs on /cow for use by casper-snapshot
501 mkdir -p "${rootmnt}/cow"
502 mount -o bind /cow "${rootmnt}/cow"
509 if [ -z "${devname}" ]; then
510 devname=$(sys2dev "${sysdev}")
513 if [ -n "${LIVEMEDIA_OFFSET}" ]; then
514 loopdevname=$(setup_loop "${devname}" "loop" "/sys/block/loop*" "${LIVEMEDIA_OFFSET}" '')
515 devname="${loopdevname}"
518 fstype=$(get_fstype "${devname}")
519 if is_supported_fs ${fstype}; then
520 mount -t ${fstype} -o ro "${devname}" $mountpoint || continue
521 if is_casper_path $mountpoint; then
529 if [ -n "${LIVEMEDIA_OFFSET}" ]; then
530 losetup -d "${loopdevname}"
537 # first look at the one specified in the command line
538 if [ ! -z "${LIVEMEDIA}" ]; then
539 if check_dev "null" "${LIVEMEDIA}"; then
543 # don't start autodetection before timeout has expired
544 if [ -n "${LIVEMEDIA_TIMEOUT}" ]; then
545 if [ "${timeout}" -lt "${LIVEMEDIA_TIMEOUT}" ]; then
549 # or do the scan of block devices
550 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -v loop | grep -v ram); do
551 devname=$(sys2dev "${sysblock}")
552 fstype=$(get_fstype "${devname}")
553 if /lib/udev/cdrom_id ${devname} > /dev/null; then
554 if check_dev "null" "${devname}" ; then
557 elif is_nice_device "${sysblock}" ; then
558 for dev in $(subdevices "${sysblock}"); do
559 if check_dev "${dev}" ; then
563 elif [ "${fstype}" = "squashfs" -o \
564 "${fstype}" = "ext3" -o \
565 "${fstype}" = "ext2" ]; then
566 # This is an ugly hack situation, the block device has
567 # an image directly on it. It's hopefully
568 # casper, so take it and run with it.
569 ln -s "${devname}" "${devname}.${fstype}"
570 echo "${devname}.${fstype}"
578 if [ -x /sbin/usplash_write ]; then
579 /sbin/usplash_write "PULSATE"
583 set_usplash_timeout() {
584 if [ -x /sbin/usplash_write ]; then
585 /sbin/usplash_write "TIMEOUT 120"
598 [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/casper-premount"
600 run_scripts /scripts/casper-premount
601 [ "$quiet" != "y" ] && log_end_msg
603 # Needed here too because some things (*cough* udev *cough*)
604 # changes the timeout
608 if [ ! -z "${NETBOOT}" ]; then
609 if do_netmount ; then
610 livefs_root="${mountpoint}"
612 panic "Unable to find a the network rootfs live file system"
615 # Scan local devices for the image
616 for i in 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19; do
617 livefs_root=$(find_livefs $i)
618 if [ -n "${livefs_root}" ]; then
625 if [ -z "${livefs_root}" ]; then
626 panic "Unable to find a medium containing a live file system"
629 if [ "${TORAM}" ]; then
631 elif [ "${TODISK}" ]; then
632 live_dest="${TODISK}"
634 if [ "${live_dest}" ]; then
635 log_begin_msg "Copying live_media to ${live_dest}"
636 copy_live_to "${livefs_root}" "${live_dest}"
640 mount_images_in_directory "${livefs_root}" "${rootmnt}"
644 maybe_break casper-bottom
645 [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/casper-bottom"
648 run_scripts /scripts/casper-bottom
649 [ "$quiet" != "y" ] && log_end_msg
653 cp casper.log "${rootmnt}/var/log/"