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
32 # looking for casper specifics options as kernel parameters
33 for x in $(cat /proc/cmdline); do
36 export USERFULLNAME=${x#userfullname=}
37 export CASPERCONF="changed"
40 export HOSTNAME=${x#hostname=}
41 export CASPERCONF="changed"
44 export USERNAME=${x#username=}
45 export CASPERCONF="changed"
48 export NETBOOT=${x#netboot=} ;;
52 export TODISK=${x#todisk=} ;;
54 export SHOWMOUNTS=1 ;;
56 export PERSISTENT=1 ;;
59 if [ "${STATICIP}" == "" ]; then
64 export CASPERGETTY=1 ;;
66 export DEFCONSOLE=$(sed -e 's%.*console=%console=%' /proc/cmdline) ;;
68 export LIVEMEDIA=${x#bootfrom=} ;;
70 export LIVEMEDIA=${x#live-media=} ;;
72 export LIVEMEDIA_TIMEOUT=${x#live-media-timeout=} ;;
73 debian-installer/locale=*)
74 export LOCALE=${x#debian-installer/locale=} ;;
76 export LOCALE=${x#locale=} ;;
78 export KBD=${x#kbd-chooser/method=} ;;
80 export KBD=${x#keyb=} ;;
81 console-setup/layoutcode=*)
82 export CSLAYOUT=${x#console-setup/layoutcode=} ;;
83 console-setup/variantcode=*)
84 export CSVARIANT=${x#console-setup/variantcode=} ;;
85 console-setup/modelcode=*)
86 export CSMODEL=${x#console-setup/modelcode=} ;;
90 # sort of compatibility with netboot.h from linux docs
91 if [ -z "${NETBOOT}" ]; then
92 if [ "${ROOT}" == "/dev/nfs" ]; then
95 elif [ "${ROOT}" == "/dev/cifs" ]; then
104 if [ -d "$path/casper" ]; then
105 if [ "$(echo $path/casper/*.squashfs)" != "$path/casper/*.squashfs" ] ||
106 [ "$(echo $path/casper/*.ext2)" != "$path/casper/*.ext2" ] ||
107 [ "$(echo $path/casper/*.dir)" != "$path/casper/*.dir" ]; then
114 get_backing_device() {
117 echo $(setup_loop "$1" "loop" "/sys/block/loop*")
123 panic "Unrecognized casper filesystem: $1"
128 match_files_in_dir() {
129 # Does any files match pattern $1 ?
132 if [ "$(echo $pattern)" != "$pattern" ]; then
138 mount_images_in_directory() {
141 if match_files_in_dir "$directory/casper/*.squashfs" ||
142 match_files_in_dir "$directory/casper/*.ext2" ||
143 match_files_in_dir "$directory/casper/*.dir"; then
144 setup_unionfs "$directory/casper" "$rootmnt"
151 sysfs_path="${1#/sys}"
152 if /lib/udev/path_id "${sysfs_path}" | grep -E -q "ID_PATH=(usb|pci-[^-]*-[ide|scsi|usb])"; then
160 # FIXME: do something better like the scan of supported filesystems
163 vfat|iso9660|udf|ext2|ext3|ntfs)
173 copyto="${copyfrom}_swap"
175 size=$(fs_size "" ${copyfrom} "used")
177 if [ "${copytodev}" = "ram" ]; then
179 freespace=$( expr $(awk '/MemFree/{print $2}' /proc/meminfo) + $( cat /proc/meminfo | grep Cached | head -n 1 | awk '/Cached/{print $2}' - ) )
180 mount_options="-o size=${size}k"
185 # it should be a writable block device
186 if [ -b "${copytodev}" ]; then
189 fstype=$(get_fstype "${dev}")
190 freespace=$(fs_size "${dev}")
192 [ "$quiet" != "y" ] && log_warning_msg "${copytodev} is not a block device."
196 if [ "${freespace}" -lt "${size}" ] ; then
197 [ "$quiet" != "y" ] && log_warning_msg "Not enough free ${free_string} (${freespace}k > ${size}k) to copy live media in ${copytodev}."
203 echo "mount -t ${fstype} ${mount_options} ${dev} ${copyto}"
204 mount -t "${fstype}" ${mount_options} "${dev}" "${copyto}"
205 cp -a ${copyfrom}/* ${copyto} # "cp -a" from busybox also copies hidden files
207 mount -r -o move ${copyto} ${copyfrom}
215 modprobe "${MP_QUIET}" af_packet # For DHCP
217 ipconfig ${DEVICE} /tmp/net-${DEVICE}.conf
219 if [ "${NFSROOT}" = "auto" ]; then
220 NFSROOT=${ROOTSERVER}:${ROOTPATH}
223 [ "$quiet" != "y" ] && log_begin_msg "Trying netboot from ${NFSROOT}"
225 if [ "${NETBOOT}" != "nfs" ] && do_cifsmount ; then
227 elif do_nfsmount ; then
233 [ "$quiet" != "y" ] && log_end_msg
239 modprobe "${MP_QUIET}" nfs
240 if [ -z "${NFSOPTS}" ]; then
244 [ "$quiet" != "y" ] && log_begin_msg "Trying nfsmount -o nolock -o ro ${NFSOPTS} ${NFSROOT} ${mountpoint}"
245 # FIXME: This for loop is an ugly HACK round an nfs bug
246 for i in 0 1 2 3 4 5 6 7 8 9 a b c d e f 10 11 12 13; do
247 nfsmount -o nolock -o ro ${NFSOPTS} "${NFSROOT}" "${mountpoint}" && rc=0 && break
255 if [ -x "/sbin/mount.cifs" ]; then
256 if [ -z "${NFSOPTS}" ]; then
257 CIFSOPTS="-ouser=root,password="
259 CIFSOPTS="${NFSOPTS}"
262 [ "$quiet" != "y" ] && log_begin_msg "Trying mount.cifs ${NFSROOT} ${mountpoint} ${CIFSOPTS}"
263 modprobe "${MP_QUIET}" cifs
265 if mount.cifs "${NFSROOT}" "${mountpoint}" "${CIFSOPTS}" ; then
278 size=$(fs_size "${fromdev}" "" "used")
280 if [ -b "${fromdev}" ]; then
282 if [ -n "${HOMEMOUNTED}" -a "${snap_type}" = "HOME" ]; then
283 todev=$(cat /proc/mounts | grep -s " $(base_path ${todir}) " | awk '{print $1}' )
284 freespace=$(df -k | grep -s ${todev} | awk '{print $4}')
286 freespace=$( expr $(awk '/MemFree/{print $2}' /proc/meminfo) + $( cat /proc/meminfo | grep Cached | head -n 1 | awk '/Cached/{print $2}' - ))
289 tomount="/mnt/tmpsnap"
290 if [ ! -d "${tomount}" ] ; then
291 mkdir -p "${tomount}"
294 fstype=$(get_fstype "${fromdev}")
295 if [ -n "${fstype}" ]; then
297 mount -t "${fstype}" -o ro "${fromdev}" "${tomount}"
298 cp -a "${tomount}"/* ${todir}
301 log_warning_msg "Unrecognized fstype: ${fstype} on ${fromdev}:${snap_type}"
305 if echo ${fromdev} | grep -qs loop; then
306 losetup -d "${fromdev}"
311 [ "$quiet" != "y" ] && log_warning_msg "Unable to find the snapshot ${snap_type} medium"
317 # Look for $snap_label.* in block devices and copy the contents to $snap_mount
318 # and remember the device and filename for resync on exit in casper.init
324 snapdata=$(find_files "${snap_label}.squashfs ${snap_label}.cpio.gz ${snap_label}.ext2")
325 if [ ! -z "${snapdata}" ]; then
326 snapdev="$(echo ${snapdata} | cut -f1 -d ' ')"
327 snapback="$(echo ${snapdata} | cut -f2 -d ' ')"
328 snapfile="$(echo ${snapdata} | cut -f3 -d ' ')"
329 if echo "${snapfile}" | grep -qs '\(squashfs\|ext2\)'; then
330 # squashfs or ext2 snapshot
331 dev=$(get_backing_device "${snapback}/${snapfile}")
332 if ! do_snap_copy "${dev}" "${snap_mount}" "${snap_type}"; then
333 log_warning_msg "Impossible to include the ${snapfile} Snapshot"
338 if ! (cd "${snap_mount}" && zcat "${snapback}/${snapfile}" | cpio -i -u -d 2>/dev/null) ; then
339 log_warning_msg "Impossible to include the ${snapfile} Snapshot"
345 dev=$(find_cow_device "${snap_label}")
346 if [ -b ${dev} ]; then
347 if echo "${dev}" | grep -qs loop; then
348 # strange things happens, user confused?
349 snaploop=$( losetup ${dev} | awk '{print $3}' | tr -d '()' )
350 snapfile=$(basename ${snaploop})
351 snapdev=$(cat /proc/mounts | awk '{print $2,$1}' | grep -es "^$( dirname ${snaploop} )" | cut -f2 -d ' ')
355 if ! do_snap_copy "${dev}" "${snap_mount}" "${snap_type}" ; then
356 log_warning_msg "Impossible to include the ${snap_label} Snapshot"
359 if [ -n "${snapfile}" ]; then
360 # it was a loop device, user confused
365 log_warning_msg "Impossible to include the ${snap_label} Snapshot"
369 echo "export ${snap_type}SNAP="${snap_mount}":${snapdev}:${snapfile}" >> /etc/casper.conf # for resync on reboot/halt
377 modprobe "${MP_QUIET}" -b unionfs
379 # run-init can't deal with images in a subdir, but we're going to
380 # move all of these away before it runs anyway. No, we're not,
381 # put them in / since move-mounting them into / breaks mono and
386 # Let's just mount the read-only file systems first
389 if [ "${NETBOOT}" == "nfs" ] ; then
390 roopt="nfsro" # go aroung a bug in nfs-unionfs locking
396 for image_type in "ext2" "squashfs" "dir" ; do
397 for image in "${image_directory}"/*."${image_type}"; do
398 imagename=$(basename "${image}")
399 if [ -d "${image}" ]; then
400 # it is a plain directory: do nothing
401 rofsstring="${image}=${roopt}:${rofsstring}"
402 rofslist="${image} ${rofslist}"
403 elif [ -f "${image}" ]; then
404 backdev=$(get_backing_device "$image")
405 fstype=$(get_fstype "${backdev}")
406 if [ "${fstype}" = "unknown" ]; then
407 panic "Unknown file system type on ${backdev} (${image})"
409 mkdir -p "${croot}/${imagename}"
410 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}"
414 rofsstring=${rofsstring%:}
420 # Looking for "${root_persistence}" device or file
421 if [ -n "${PERSISTENT}" ]; then
422 cowprobe=$(find_cow_device "${root_persistence}")
423 if [ -b "${cowprobe}" ]; then
424 cowdevice=${cowprobe}
425 cow_fstype=$(get_fstype "${cowprobe}")
427 [ "$quiet" != "y" ] && log_warning_msg "Unable to find the persistent medium"
431 mount ${cowdevice} -t ${cow_fstype} -o rw /cow || panic "Can not mount $cowdevice on /cow"
433 mount -t unionfs -o dirs=/cow=rw:$rofsstring unionfs "$rootmnt" || panic "Unionfs mount failed"
435 # Adding other custom mounts
436 if [ -n "${PERSISTENT}" ]; then
437 # directly mount /home
438 # FIXME: add a custom mounts configurable system
439 homecow=$(find_cow_device "${home_persistence}" )
440 if [ -b "${homecow}" ]; then
441 mount -t $(get_fstype "${homecow}") -o rw "${homecow}" "${rootmnt}/home"
442 export HOMEMOUNTED=1 # used to proper calculate free space in do_snap_copy()
444 [ "$quiet" != "y" ] && log_warning_msg "Unable to find the persistent home medium"
446 # Look for other snapshots to copy in
447 try_snap "${root_snapshot_label}" "${rootmnt}" "ROOT"
448 try_snap "${home_snapshot_label}" "${rootmnt}/home" "HOME"
451 if [ -n "${SHOWMOUNTS}" ]; then
452 for d in ${rofslist}; do
453 mkdir -p "${rootmnt}/casper/${d##*/}"
455 *.dir) # do nothing # mount -o bind "${d}" "${rootmnt}/casper/${d##*/}"
457 *) mount -o move "${d}" "${rootmnt}/casper/${d##*/}"
463 # shows cow fs on /cow for use by casper-snapshot
464 mkdir -p "${rootmnt}/cow"
465 mount -o bind /cow "${rootmnt}/cow"
472 if [ -z "${devname}" ]; then
473 devname=$(sys2dev "${sysdev}")
475 fstype=$(get_fstype "${devname}")
476 if is_supported_fs ${fstype}; then
477 mount -t ${fstype} -o ro "${devname}" $mountpoint || continue
478 if is_casper_path $mountpoint; then
490 # first look at the one specified in the command line
491 if [ ! -z "${LIVEMEDIA}" ]; then
492 if check_dev "null" "${LIVEMEDIA}"; then
496 # don't start autodetection before timeout has expired
497 if [ -n "${LIVEMEDIA_TIMEOUT}" ]; then
498 if [ "${timeout}" -lt "${LIVEMEDIA_TIMEOUT}" ]; then
502 # or do the scan of block devices
503 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -v loop | grep -v ram); do
504 devname=$(sys2dev "${sysblock}")
505 fstype=$(get_fstype "${devname}")
506 if /lib/udev/cdrom_id ${devname} > /dev/null; then
507 if check_dev "null" "${devname}" ; then
510 elif is_nice_device "${sysblock}" ; then
511 for dev in $(subdevices "${sysblock}"); do
512 if check_dev "${dev}" ; then
516 elif [ "${fstype}" = "squashfs" -o \
517 "${fstype}" = "ext3" -o \
518 "${fstype}" = "ext2" ]; then
519 # This is an ugly hack situation, the block device has
520 # an image directly on it. It's hopefully
521 # casper, so take it and run with it.
522 ln -s "${devname}" "${devname}.${fstype}"
523 echo "${devname}.${fstype}"
531 if [ -x /sbin/usplash_write ]; then
532 /sbin/usplash_write "PULSATE"
536 set_usplash_timeout() {
537 if [ -x /sbin/usplash_write ]; then
538 /sbin/usplash_write "TIMEOUT 120"
551 [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/casper-premount"
553 run_scripts /scripts/casper-premount
554 [ "$quiet" != "y" ] && log_end_msg
556 # Needed here too because some things (*cough* udev *cough*)
557 # changes the timeout
561 if [ ! -z "${NETBOOT}" ]; then
562 if do_netmount ; then
563 livefs_root="${mountpoint}"
565 panic "Unable to find a the network rootfs live file system"
568 # Scan local devices for the image
569 for i in 0 1 2 3 4 5 6 7 8 9 a b c d e f 10 11 12 13; do
570 livefs_root=$(find_livefs $i)
571 if [ -n "${livefs_root}" ]; then
578 if [ -z "${livefs_root}" ]; then
579 panic "Unable to find a medium containing a live file system"
582 if [ -n "${TORAM}" ]; then
584 elif [ -n "${TODISK}" ]; then
585 live_dest="${TODISK}"
587 if [ -n "${live_dest}" ]; then
588 [ "$quiet" != "y" ] && log_begin_msg "Copying live_media to ${live_dest}"
589 copy_live_to "${livefs_root}" "${live_dest}"
590 [ "$quiet" != "y" ] && log_end_msg
593 mount_images_in_directory "${livefs_root}" "${rootmnt}"
597 maybe_break casper-bottom
598 [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/casper-bottom"
601 run_scripts /scripts/casper-bottom
602 [ "$quiet" != "y" ] && log_end_msg
604 if [ -f /casper.vars ]; then
612 cp casper.log "${rootmnt}/var/log/"