5 export PATH=/root/usr/bin:/root/usr/sbin:/root/bin:/root/sbin:/usr/bin:/usr/sbin:/bin:/sbin
10 USERFULLNAME="Live session user"
16 [ -f /etc/casper.conf ] && . /etc/casper.conf
17 export USERNAME USERFULLNAME HOST BUILD_SYSTEM
19 . /scripts/casper-helpers
21 if [ ! -f /casper.vars ]; then
30 # looking for casper specifics options as kernel parameters
31 for x in $(cat /proc/cmdline); do
34 export USERFULLNAME=${x#userfullname=}
35 export CASPERCONF="changed"
38 export HOSTNAME=${x#hostname=}
39 export CASPERCONF="changed"
42 export USERNAME=${x#username=}
43 export CASPERCONF="changed"
46 export NETBOOT=${x#netboot=} ;;
48 export ACCESS=${x#access=} ;;
50 export XDEBCONF="Yes" ;;
54 export TODISK=${x#todisk=} ;;
56 export SHOWMOUNTS="Yes" ;;
58 export PERSISTENT="Yes" ;;
60 export PERSISTENT="" ;;
63 if [ "${STATICIP}" == "" ]; then
68 export CASPERGETTY=1 ;;
69 bootfrom=*|live-media=*)
70 export LIVEMEDIA=${x#*=} ;;
71 live-media-encryption=*|encryption=*)
72 export LIVEMEDIA_ENCRYPTION=${x#*=} ;;
74 export LIVEMEDIA_TIMEOUT=${x#live-media-timeout=} ;;
76 export LIVEMEDIA_OFFSET=${x#live-media-offset=} ;;
77 locale=*|debian-installer/locale=*)
78 export LOCALE=${x#*=} ;;
79 keyb=*|kbd-chooser/method=*)
81 klayout=*|console-setup/layoutcode=*)
82 export KLAYOUT=${x#*=} ;;
84 export KOPTIONS=${x#koptions=} ;;
85 kvariant=*|console-setup/variantcode=*)
86 export KVARIANT=${x#*=} ;;
87 kmodel=*|console-setup/modelcode=*)
88 export KMODEL=${x#*=} ;;
90 export MODULE=${x#module=} ;;
91 preseed/file=*|file=*)
92 export LOCATION="${x#*=}" ;;
96 PRESEEDS="${PRESEEDS}\"${question}=${value}\" "
99 export DEFCONSOLE="${x#*=}" ;;
103 # sort of compatibility with netboot.h from linux docs
104 if [ -z "${NETBOOT}" ]; then
105 if [ "${ROOT}" == "/dev/nfs" ]; then
108 elif [ "${ROOT}" == "/dev/cifs" ]; then
114 if [ -z "${MODULE}" ]; then
119 # Pendrivelinux fix ended
123 if [ -d "$path/casper" ]; then
124 if [ "$(echo $path/casper/*.squashfs)" != "$path/casper/*.squashfs" ] ||
125 [ "$(echo $path/casper/*.ext2)" != "$path/casper/*.ext2" ] ||
126 [ "$(echo $path/casper/*.dir)" != "$path/casper/*.dir" ]; then
133 get_backing_device() {
136 echo $(setup_loop "$1" "loop" "/sys/block/loop*")
142 panic "Unrecognized casper filesystem: $1"
147 match_files_in_dir() {
148 # Does any files match pattern $1 ?
151 if [ "$(echo $pattern)" != "$pattern" ]; then
157 mount_images_in_directory() {
160 if match_files_in_dir "$directory/casper/*.squashfs" ||
161 match_files_in_dir "$directory/casper/*.ext2" ||
162 match_files_in_dir "$directory/casper/*.dir"; then
163 setup_unionfs "$directory/casper" "$rootmnt"
170 sysfs_path="${1#/sys}"
171 if /lib/udev/path_id "${sysfs_path}" | grep -E -q "ID_PATH=(usb|pci-[^-]*-[ide|scsi|usb])"; then
178 # FIXME: do something better like the scan of supported filesystems
181 vfat|iso9660|udf|ext2|ext3|ntfs)
191 copyto="${copyfrom}_swap"
193 size=$(fs_size "" ${copyfrom} "used")
195 if [ "${copytodev}" = "ram" ]; then
197 freespace=$( expr $(awk '/MemFree/{print $2}' /proc/meminfo) + $( cat /proc/meminfo | grep Cached | head -n 1 | awk '/Cached/{print $2}' - ) )
198 mount_options="-o size=${size}k"
203 # it should be a writable block device
204 if [ -b "${copytodev}" ]; then
207 fstype=$(get_fstype "${dev}")
208 freespace=$(fs_size "${dev}")
210 [ "$quiet" != "y" ] && log_warning_msg "${copytodev} is not a block device."
214 if [ "${freespace}" -lt "${size}" ] ; then
215 [ "$quiet" != "y" ] && log_warning_msg "Not enough free ${free_string} (${freespace}k > ${size}k) to copy live media in ${copytodev}."
221 echo "mount -t ${fstype} ${mount_options} ${dev} ${copyto}"
222 mount -t "${fstype}" ${mount_options} "${dev}" "${copyto}"
225 for target in autorun.inf boot boot.catalog casper info initrd.gz logo.ico misc opt vmlinuz; do
226 cp -a ${copyfrom}/${target} ${copyto} # "cp -a" from busybox also copies hidden files
230 mount -r -o move ${copyto} ${copyfrom}
238 modprobe "${MP_QUIET}" af_packet # For DHCP
240 ipconfig ${DEVICE} /tmp/net-${DEVICE}.conf | tee /netboot.config
242 if [ "${NFSROOT}" = "auto" ]; then
243 NFSROOT=${ROOTSERVER}:${ROOTPATH}
246 [ "$quiet" != "y" ] && log_begin_msg "Trying netboot from ${NFSROOT}"
248 if [ "${NETBOOT}" != "nfs" ] && do_cifsmount ; then
250 elif do_nfsmount ; then
256 [ "$quiet" != "y" ] && log_end_msg
262 modprobe "${MP_QUIET}" nfs
263 if [ -z "${NFSOPTS}" ]; then
267 [ "$quiet" != "y" ] && log_begin_msg "Trying nfsmount -o nolock -o ro ${NFSOPTS} ${NFSROOT} ${mountpoint}"
268 # FIXME: This for loop is an ugly HACK round an nfs bug
269 for i in 0 1 2 3 4 5 6 7 8 9 a b c d e f 10 11 12 13; do
270 nfsmount -o nolock -o ro ${NFSOPTS} "${NFSROOT}" "${mountpoint}" && rc=0 && break
278 if [ -x "/sbin/mount.cifs" ]; then
279 if [ -z "${NFSOPTS}" ]; then
280 CIFSOPTS="-ouser=root,password="
282 CIFSOPTS="${NFSOPTS}"
285 [ "$quiet" != "y" ] && log_begin_msg "Trying mount.cifs ${NFSROOT} ${mountpoint} ${CIFSOPTS}"
286 modprobe "${MP_QUIET}" cifs
288 if mount.cifs "${NFSROOT}" "${mountpoint}" "${CIFSOPTS}" ; then
301 size=$(fs_size "${fromdev}" "" "used")
303 if [ -b "${fromdev}" ]; then
305 if [ -n "${HOMEMOUNTED}" -a "${snap_type}" = "HOME" ]; then
306 todev=$(cat /proc/mounts | grep -s " $(base_path ${todir}) " | awk '{print $1}' )
307 freespace=$(df -k | grep -s ${todev} | awk '{print $4}')
309 freespace=$( expr $(awk '/MemFree/{print $2}' /proc/meminfo) + $( cat /proc/meminfo | grep Cached | head -n 1 | awk '/Cached/{print $2}' - ))
312 tomount="/mnt/tmpsnap"
313 if [ ! -d "${tomount}" ] ; then
314 mkdir -p "${tomount}"
317 fstype=$(get_fstype "${fromdev}")
318 if [ -n "${fstype}" ]; then
320 mount -t "${fstype}" -o ro "${fromdev}" "${tomount}"
321 cp -a "${tomount}"/* ${todir}
324 log_warning_msg "Unrecognized fstype: ${fstype} on ${fromdev}:${snap_type}"
328 if echo ${fromdev} | grep -qs loop; then
329 losetup -d "${fromdev}"
334 [ "$quiet" != "y" ] && log_warning_msg "Unable to find the snapshot ${snap_type} medium"
340 # Look for $snap_label.* in block devices and copy the contents to $snap_mount
341 # and remember the device and filename for resync on exit in casper.init
347 snapdata=$(find_files "${snap_label}.squashfs ${snap_label}.cpio.gz ${snap_label}.ext2")
348 if [ ! -z "${snapdata}" ]; then
349 snapdev="$(echo ${snapdata} | cut -f1 -d ' ')"
350 snapback="$(echo ${snapdata} | cut -f2 -d ' ')"
351 snapfile="$(echo ${snapdata} | cut -f3 -d ' ')"
352 if echo "${snapfile}" | grep -qs '\(squashfs\|ext2\)'; then
353 # squashfs or ext2 snapshot
354 dev=$(get_backing_device "${snapback}/${snapfile}")
355 if ! do_snap_copy "${dev}" "${snap_mount}" "${snap_type}"; then
356 log_warning_msg "Impossible to include the ${snapfile} Snapshot"
361 if ! (cd "${snap_mount}" && zcat "${snapback}/${snapfile}" | cpio -i -u -d 2>/dev/null) ; then
362 log_warning_msg "Impossible to include the ${snapfile} Snapshot"
368 dev=$(find_cow_device "${snap_label}")
369 if [ -b ${dev} ]; then
370 if echo "${dev}" | grep -qs loop; then
371 # strange things happens, user confused?
372 snaploop=$( losetup ${dev} | awk '{print $3}' | tr -d '()' )
373 snapfile=$(basename ${snaploop})
374 snapdev=$(cat /proc/mounts | awk '{print $2,$1}' | grep -es "^$( dirname ${snaploop} )" | cut -f2 -d ' ')
378 if ! do_snap_copy "${dev}" "${snap_mount}" "${snap_type}" ; then
379 log_warning_msg "Impossible to include the ${snap_label} Snapshot"
382 if [ -n "${snapfile}" ]; then
383 # it was a loop device, user confused
388 log_warning_msg "Impossible to include the ${snap_label} Snapshot"
392 echo "export ${snap_type}SNAP="${snap_mount}":${snapdev}:${snapfile}" >> /etc/casper.conf # for resync on reboot/halt
402 # run-init can't deal with images in a subdir, but we're going to
403 # move all of these away before it runs anyway. No, we're not,
404 # put them in / since move-mounting them into / breaks mono and
409 # Let's just mount the read-only file systems first
412 if [ "${NETBOOT}" = "nfs" ] ; then
413 roopt="nfsro" # go aroung a bug in nfs-unionfs locking
419 for image_type in "ext2" "squashfs" "dir" ; do
420 for image in "${image_directory}"/*."${image_type}"; do
421 imagename=$(basename "${image}")
422 if [ -d "${image}" ]; then
423 # it is a plain directory: do nothing
424 rofsstring="${image}=${roopt}:${rofsstring}"
425 rofslist="${image} ${rofslist}"
426 elif [ -f "${image}" ]; then
427 backdev=$(get_backing_device "$image")
428 fstype=$(get_fstype "${backdev}")
429 if [ "${fstype}" = "unknown" ]; then
430 panic "Unknown file system type on ${backdev} (${image})"
432 if [ -z "${fstype}" ]; then
435 mkdir -p "${croot}/${imagename}"
436 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}"
440 rofsstring=${rofsstring%:}
446 # Looking for "${root_persistence}" device or file
447 if [ -n "${PERSISTENT}" ]; then
448 cowprobe=$(find_cow_device "${root_persistence}")
449 if [ -b "${cowprobe}" ]; then
450 cowdevice=${cowprobe}
451 cow_fstype=$(get_fstype "${cowprobe}")
453 [ "$quiet" != "y" ] && log_warning_msg "Unable to find the persistent medium"
457 mount ${cowdevice} -t ${cow_fstype} -o rw /cow || panic "Can not mount $cowdevice on /cow"
460 if grep -q aufs /proc/cmdline; then
462 mount -t aufs -o dirs=/cow=rw:$rofsstring unionfs "$rootmnt" || panic "Unionfs (aufs) mount failed"
464 modprobe "${MP_QUIET}" -b unionfs
465 mount -t unionfs -o dirs=/cow=rw:$rofsstring unionfs "$rootmnt" || panic "Unionfs (unionfs) mount failed"
468 # Adding other custom mounts
469 if [ -n "${PERSISTENT}" ]; then
470 # directly mount /home
471 # FIXME: add a custom mounts configurable system
472 homecow=$(find_cow_device "${home_persistence}" )
473 if [ -b "${homecow}" ]; then
474 mount -t $(get_fstype "${homecow}") -o rw "${homecow}" "${rootmnt}/home"
475 export HOMEMOUNTED=1 # used to proper calculate free space in do_snap_copy()
477 [ "$quiet" != "y" ] && log_warning_msg "Unable to find the persistent home medium"
479 # Look for other snapshots to copy in
480 try_snap "${root_snapshot_label}" "${rootmnt}" "ROOT"
481 try_snap "${home_snapshot_label}" "${rootmnt}/home" "HOME"
484 if [ -n "${SHOWMOUNTS}" ]; then
485 for d in ${rofslist}; do
486 mkdir -p "${rootmnt}/casper/${d##*/}"
488 *.dir) # do nothing # mount -o bind "${d}" "${rootmnt}/casper/${d##*/}"
490 *) mount -o move "${d}" "${rootmnt}/casper/${d##*/}"
494 # shows cow fs on /cow for use by casper-snapshot
495 mkdir -p "${rootmnt}/cow"
496 mount -o bind /cow "${rootmnt}/cow"
499 # move the first mount; no head in busybox-initramfs
500 for d in $(mount -t squashfs | cut -d\ -f 3); do
501 mkdir -p "${rootmnt}/rofs"
502 mount -o move "${d}" "${rootmnt}/rofs"
511 if [ -z "${devname}" ]; then
512 devname=$(sys2dev "${sysdev}")
515 if [ -n "${LIVEMEDIA_OFFSET}" ]; then
516 loopdevname=$(setup_loop "${devname}" "loop" "/sys/block/loop*" "${LIVEMEDIA_OFFSET}")
517 devname="${loopdevname}"
520 fstype=$(get_fstype "${devname}")
521 if is_supported_fs ${fstype}; then
522 mount -t ${fstype} -o ro "${devname}" $mountpoint || continue
523 if is_casper_path $mountpoint; then
531 if [ -n "${LIVEMEDIA_OFFSET}" ]; then
532 losetup -d "${loopdevname}"
539 # first look at the one specified in the command line
540 if [ ! -z "${LIVEMEDIA}" ]; then
541 if check_dev "null" "${LIVEMEDIA}"; then
545 # don't start autodetection before timeout has expired
546 if [ -n "${LIVEMEDIA_TIMEOUT}" ]; then
547 if [ "${timeout}" -lt "${LIVEMEDIA_TIMEOUT}" ]; then
551 # or do the scan of block devices
552 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -v loop | grep -v ram); do
553 devname=$(sys2dev "${sysblock}")
554 fstype=$(get_fstype "${devname}")
555 if /lib/udev/cdrom_id ${devname} > /dev/null; then
556 if check_dev "null" "${devname}" ; then
559 elif is_nice_device "${sysblock}" ; then
560 for dev in $(subdevices "${sysblock}"); do
561 if check_dev "${dev}" ; then
565 elif [ "${fstype}" = "squashfs" -o \
566 "${fstype}" = "ext3" -o \
567 "${fstype}" = "ext2" ]; then
568 # This is an ugly hack situation, the block device has
569 # an image directly on it. It's hopefully
570 # casper, so take it and run with it.
571 ln -s "${devname}" "${devname}.${fstype}"
572 echo "${devname}.${fstype}"
580 if [ -x /sbin/usplash_write ]; then
581 /sbin/usplash_write "PULSATE"
585 set_usplash_timeout() {
586 if [ -x /sbin/usplash_write ]; then
587 /sbin/usplash_write "TIMEOUT 120"
601 [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/casper-premount"
603 run_scripts /scripts/casper-premount
604 [ "$quiet" != "y" ] && log_end_msg
606 # Needed here too because some things (*cough* udev *cough*)
607 # changes the timeout
611 if [ ! -z "${NETBOOT}" ]; then
612 if do_netmount ; then
613 livefs_root="${mountpoint}"
615 panic "Unable to find a the network rootfs live file system"
618 # Scan local devices for the image
619 for i in 0 1 2 3 4 5 6 7 8 9 a b c d e f 10 11 12 13; do
620 livefs_root=$(find_livefs $i)
621 if [ "${livefs_root}" ]; then
628 if [ -z "${livefs_root}" ]; then
629 panic "Unable to find a medium containing a live file system"
632 if [ "${TORAM}" ]; then
634 elif [ "${TODISK}" ]; then
635 live_dest="${TODISK}"
637 if [ "${live_dest}" ]; then
638 log_begin_msg "Copying live_media to ${live_dest}"
639 copy_live_to "${livefs_root}" "${live_dest}"
643 mount_images_in_directory "${livefs_root}" "${rootmnt}"
647 maybe_break casper-bottom
648 [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/casper-bottom"
651 run_scripts /scripts/casper-bottom
652 [ "$quiet" != "y" ] && log_end_msg
656 cp casper.log "${rootmnt}/var/log/"