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
28 # looking for casper specifics options as kernel parameters
29 for x in $(cat /proc/cmdline); do
32 export USERFULLNAME=${x#userfullname=}
33 export CASPERCONF="changed"
36 export HOSTNAME=${x#hostname=}
37 export CASPERCONF="changed"
40 export USERNAME=${x#username=}
41 export CASPERCONF="changed"
44 export NETBOOT=${x#netboot=} ;;
48 export TODISK=${x#todisk=} ;;
50 export SHOWMOUNTS=1 ;;
52 export PERSISTENT=1 ;;
55 if [ "${STATICIP}" == "" ]; then
60 export CASPERGETTY=1 ;;
62 export DEFCONSOLE=$(sed -e 's%.*console=%console=%' /proc/cmdline) ;;
64 export LIVEMEDIA=${x#bootfrom=} ;;
66 export LIVEMEDIA=${x#live-media=} ;;
67 debian-installer/locale=*)
68 export LOCALE=${x#debian-installer/locale=} ;;
70 export LOCALE=${x#locale=} ;;
72 export KBD=${x#kbd-chooser/method=} ;;
74 export KBD=${x#keyb=} ;;
75 console-setup/layoutcode=*)
76 export CSLAYOUT=${x#console-setup/layoutcode=} ;;
77 console-setup/variantcode=*)
78 export CSVARIANT=${x#console-setup/variantcode=} ;;
79 console-setup/modelcode=*)
80 export CSMODEL=${x#console-setup/modelcode=} ;;
84 # sort of compatibility with netboot.h from linux docs
85 if [ -z "${NETBOOT}" ]; then
86 if [ "${ROOT}" == "/dev/nfs" ]; then
89 elif [ "${ROOT}" == "/dev/cifs" ]; then
98 if [ -d "$path/casper" ]; then
99 if [ "$(echo $path/casper/*.squashfs)" != "$path/casper/*.squashfs" ] ||
100 [ "$(echo $path/casper/*.ext2)" != "$path/casper/*.ext2" ] ||
101 [ "$(echo $path/casper/*.dir)" != "$path/casper/*.dir" ]; then
108 get_backing_device() {
111 echo $(setup_loop "$1" "loop" "/sys/block/loop*")
117 panic "Unrecognized casper filesystem: $1"
122 match_files_in_dir() {
123 # Does any files match pattern $1 ?
126 if [ "$(echo $pattern)" != "$pattern" ]; then
132 mount_images_in_directory() {
135 if match_files_in_dir "$directory/casper/*.squashfs" ||
136 match_files_in_dir "$directory/casper/*.ext2" ||
137 match_files_in_dir "$directory/casper/*.dir"; then
138 setup_unionfs "$directory/casper" "$rootmnt"
145 sysfs_path="${1#/sys}"
146 if /lib/udev/path_id "${sysfs_path}" | grep -E -q "ID_PATH=(usb|pci-[^-]*-[ide|scsi|usb])"; then
154 # FIXME: do something better like the scan of supported filesystems
157 vfat|iso9660|udf|ext2|ext3|ntfs)
167 copyto="${copyfrom}_swap"
169 size=$(fs_size "" ${copyfrom} "used")
171 if [ "${copytodev}" = "ram" ]; then
173 freespace=$( expr $(awk '/MemFree/{print $2}' /proc/meminfo) + $( cat /proc/meminfo | grep Cached | head -n 1 | awk '/Cached/{print $2}' - ) )
174 mount_options="-o size=${size}k"
179 # it should be a writable block device
180 if [ -b "${copytodev}" ]; then
183 fstype=$(get_fstype "${dev}")
184 freespace=$(fs_size "${dev}")
186 [ "$quiet" != "y" ] && log_warning_msg "${copytodev} is not a block device."
190 if [ "${freespace}" -lt "${size}" ] ; then
191 [ "$quiet" != "y" ] && log_warning_msg "Not enough free ${free_string} (${freespace}k > ${size}k) to copy live media in ${copytodev}."
197 echo "mount -t ${fstype} ${mount_options} ${dev} ${copyto}"
198 mount -t "${fstype}" ${mount_options} "${dev}" "${copyto}"
199 cp -a ${copyfrom}/* ${copyto} # "cp -a" from busybox also copies hidden files
201 mount -r -o move ${copyto} ${copyfrom}
209 modprobe "${MP_QUIET}" af_packet # For DHCP
211 ipconfig ${DEVICE} /tmp/net-${DEVICE}.conf
213 if [ "${NFSROOT}" = "auto" ]; then
214 NFSROOT=${ROOTSERVER}:${ROOTPATH}
217 [ "$quiet" != "y" ] && log_begin_msg "Trying netboot from ${NFSROOT}"
219 if [ "${NETBOOT}" != "nfs" ] && do_cifsmount ; then
221 elif do_nfsmount ; then
227 [ "$quiet" != "y" ] && log_end_msg
233 modprobe "${MP_QUIET}" nfs
234 if [ -z "${NFSOPTS}" ]; then
238 [ "$quiet" != "y" ] && log_begin_msg "Trying nfsmount -o nolock -o ro ${NFSOPTS} ${NFSROOT} ${mountpoint}"
239 # FIXME: This for loop is an ugly HACK round an nfs bug
240 for i in 0 1 2 3 4 5 6 7 8 9 a b c d e f 10 11 12 13; do
241 nfsmount -o nolock -o ro ${NFSOPTS} "${NFSROOT}" "${mountpoint}" && rc=0 && break
249 if [ -x "/sbin/mount.cifs" ]; then
250 if [ -z "${NFSOPTS}" ]; then
251 CIFSOPTS="-ouser=root,password="
253 CIFSOPTS="${NFSOPTS}"
256 [ "$quiet" != "y" ] && log_begin_msg "Trying mount.cifs ${NFSROOT} ${mountpoint} ${CIFSOPTS}"
257 modprobe "${MP_QUIET}" cifs
259 if mount.cifs "${NFSROOT}" "${mountpoint}" "${CIFSOPTS}" ; then
272 size=$(fs_size "${fromdev}" "" "used")
274 if [ -b "${fromdev}" ]; then
276 if [ -n "${HOMEMOUNTED}" -a "${snap_type}" = "HOME" ]; then
277 todev=$(cat /proc/mounts | grep -s " $(base_path ${todir}) " | awk '{print $1}' )
278 freespace=$(df -k | grep -s ${todev} | awk '{print $4}')
280 freespace=$( expr $(awk '/MemFree/{print $2}' /proc/meminfo) + $( cat /proc/meminfo | grep Cached | head -n 1 | awk '/Cached/{print $2}' - ))
283 tomount="/mnt/tmpsnap"
284 if [ ! -d "${tomount}" ] ; then
285 mkdir -p "${tomount}"
288 fstype=$(get_fstype "${fromdev}")
289 if [ -n "${fstype}" ]; then
291 mount -t "${fstype}" -o ro "${fromdev}" "${tomount}"
292 cp -a "${tomount}"/* ${todir}
295 log_warning_msg "Unrecognized fstype: ${fstype} on ${fromdev}:${snap_type}"
299 if echo ${fromdev} | grep -qs loop; then
300 losetup -d "${fromdev}"
305 [ "$quiet" != "y" ] && log_warning_msg "Unable to find the snapshot ${snap_type} medium"
311 # Look for $snap_label.* in block devices and copy the contents to $snap_mount
312 # and remember the device and filename for resync on exit in casper.init
318 snapdata=$(find_files "${snap_label}.squashfs ${snap_label}.cpio.gz ${snap_label}.ext2")
319 if [ ! -z "${snapdata}" ]; then
320 snapdev="$(echo ${snapdata} | cut -f1 -d ' ')"
321 snapback="$(echo ${snapdata} | cut -f2 -d ' ')"
322 snapfile="$(echo ${snapdata} | cut -f3 -d ' ')"
323 if echo "${snapfile}" | grep -qs '\(squashfs\|ext2\)'; then
324 # squashfs or ext2 snapshot
325 dev=$(get_backing_device "${snapback}/${snapfile}")
326 if ! do_snap_copy "${dev}" "${snap_mount}" "${snap_type}"; then
327 log_warning_msg "Impossible to include the ${snapfile} Snapshot"
332 if ! (cd "${snap_mount}" && zcat "${snapback}/${snapfile}" | cpio -i -u -d 2>/dev/null) ; then
333 log_warning_msg "Impossible to include the ${snapfile} Snapshot"
339 dev=$(find_cow_device "${snap_label}")
340 if [ -b ${dev} ]; then
341 if echo "${dev}" | grep -qs loop; then
342 # strange things happens, user confused?
343 snaploop=$( losetup ${dev} | awk '{print $3}' | tr -d '()' )
344 snapfile=$(basename ${snaploop})
345 snapdev=$(cat /proc/mounts | awk '{print $2,$1}' | grep -es "^$( dirname ${snaploop} )" | cut -f2 -d ' ')
349 if ! do_snap_copy "${dev}" "${snap_mount}" "${snap_type}" ; then
350 log_warning_msg "Impossible to include the ${snap_label} Snapshot"
353 if [ -n "${snapfile}" ]; then
354 # it was a loop device, user confused
359 log_warning_msg "Impossible to include the ${snap_label} Snapshot"
363 echo "export ${snap_type}SNAP="${snap_mount}":${snapdev}:${snapfile}" >> /etc/casper.conf # for resync on reboot/halt
371 modprobe "${MP_QUIET}" -b unionfs
373 # run-init can't deal with images in a subdir, but we're going to
374 # move all of these away before it runs anyway. No, we're not,
375 # put them in / since move-mounting them into / breaks mono and
380 # Let's just mount the read-only file systems first
383 if [ "${NETBOOT}" == "nfs" ] ; then
384 roopt="nfsro" # go aroung a bug in nfs-unionfs locking
390 for image_type in "ext2" "squashfs" "dir" ; do
391 for image in "${image_directory}"/*."${image_type}"; do
392 imagename=$(basename "${image}")
393 if [ -d "${image}" ]; then
394 # it is a plain directory: do nothing
395 rofsstring="${image}=${roopt}:${rofsstring}"
396 rofslist="${image} ${rofslist}"
397 elif [ -f "${image}" ]; then
398 backdev=$(get_backing_device "$image")
399 fstype=$(get_fstype "${backdev}")
400 if [ "${fstype}" = "unknown" ]; then
401 panic "Unknown file system type on ${backdev} (${image})"
403 mkdir -p "${croot}/${imagename}"
404 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}"
408 rofsstring=${rofsstring%:}
414 # Looking for "${root_persistence}" device or file
415 if [ -n "${PERSISTENT}" ]; then
416 cowprobe=$(find_cow_device "${root_persistence}")
417 if [ -b "${cowprobe}" ]; then
418 cowdevice=${cowprobe}
419 cow_fstype=$(get_fstype "${cowprobe}")
421 [ "$quiet" != "y" ] && log_warning_msg "Unable to find the persistent medium"
425 mount ${cowdevice} -t ${cow_fstype} -o rw /cow || panic "Can not mount $cowdevice on /cow"
427 mount -t unionfs -o dirs=/cow=rw:$rofsstring unionfs "$rootmnt" || panic "Unionfs mount failed"
429 # Adding other custom mounts
430 if [ -n "${PERSISTENT}" ]; then
431 # directly mount /home
432 # FIXME: add a custom mounts configurable system
433 homecow=$(find_cow_device "${home_persistence}" )
434 if [ -b "${homecow}" ]; then
435 mount -t $(get_fstype "${homecow}") -o rw "${homecow}" "${rootmnt}/home"
436 export HOMEMOUNTED=1 # used to proper calculate free space in do_snap_copy()
438 [ "$quiet" != "y" ] && log_warning_msg "Unable to find the persistent home medium"
440 # Look for other snapshots to copy in
441 try_snap "${root_snapshot_label}" "${rootmnt}" "ROOT"
442 try_snap "${home_snapshot_label}" "${rootmnt}/home" "HOME"
445 if [ -n "${SHOWMOUNTS}" ]; then
446 for d in ${rofslist}; do
447 mkdir -p "${rootmnt}/casper/${d##*/}"
449 *.dir) # do nothing # mount -o bind "${d}" "${rootmnt}/casper/${d##*/}"
451 *) mount -o move "${d}" "${rootmnt}/casper/${d##*/}"
457 # shows cow fs on /cow for use by casper-snapshot
458 mkdir -p "${rootmnt}/cow"
459 mount -o bind /cow "${rootmnt}/cow"
466 if [ -z "${devname}" ]; then
467 devname=$(sys2dev "${sysdev}")
469 fstype=$(get_fstype "${devname}")
470 if is_supported_fs ${fstype}; then
471 mount -t ${fstype} -o ro "${devname}" $mountpoint || continue
472 if is_casper_path $mountpoint; then
483 # first look at the one specified in the command line
484 if [ ! -z "${LIVEMEDIA}" ]; then
485 if check_dev "null" "${LIVEMEDIA}"; then
489 # or do the scan of block devices
490 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -v loop | grep -v ram); do
491 devname=$(sys2dev "${sysblock}")
492 fstype=$(get_fstype "${devname}")
493 if /lib/udev/cdrom_id ${devname} > /dev/null; then
494 if check_dev "null" "${devname}" ; then
497 elif is_nice_device "${sysblock}" ; then
498 for dev in $(subdevices "${sysblock}"); do
499 if check_dev "${dev}" ; then
503 elif [ "${fstype}" = "squashfs" -o \
504 "${fstype}" = "ext3" ] -o \
505 "${fstype}" = "ext2" ]; then
506 # This is an ugly hack situation, the block device has
507 # an image directly on it. It's hopefully
508 # casper, so take it and run with it.
509 ln -s "${devname}" "${devname}.${fstype}"
510 echo "${devname}.${fstype}"
518 if [ -x /sbin/usplash_write ]; then
519 /sbin/usplash_write "PULSATE"
523 set_usplash_timeout() {
524 if [ -x /sbin/usplash_write ]; then
525 /sbin/usplash_write "TIMEOUT 120"
538 [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/casper-premount"
540 run_scripts /scripts/casper-premount
541 [ "$quiet" != "y" ] && log_end_msg
543 # Needed here too because some things (*cough* udev *cough*)
544 # changes the timeout
548 if [ ! -z "${NETBOOT}" ]; then
549 if do_netmount ; then
550 livefs_root="${mountpoint}"
552 panic "Unable to find a the network rootfs live file system"
555 # Scan local devices for the image
556 for i in 0 1 2 3 4 5 6 7 8 9 a b c d e f 10 11 12 13; do
557 livefs_root=$(find_livefs)
558 if [ ! -z "${livefs_root}" ]; then
565 if [ -z "${livefs_root}" ]; then
566 panic "Unable to find a medium containing a live file system"
569 if [ -n "${TORAM}" ]; then
571 elif [ -n "${TODISK}" ]; then
572 live_dest="${TODISK}"
574 if [ -n "${live_dest}" ]; then
575 [ "$quiet" != "y" ] && log_begin_msg "Copying live_media to ${live_dest}"
576 copy_live_to "${livefs_root}" "${live_dest}"
577 [ "$quiet" != "y" ] && log_end_msg
580 mount_images_in_directory "${livefs_root}" "${rootmnt}"
584 maybe_break casper-bottom
585 [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/casper-bottom"
588 run_scripts /scripts/casper-bottom
589 [ "$quiet" != "y" ] && log_end_msg
593 cp casper.log "${rootmnt}/var/log/"