5 export PATH=/root/usr/bin:/root/usr/sbin:/root/bin:/root/sbin:/usr/bin:/usr/sbin:/bin:/sbin
7 echo "/root/lib" >> /etc/ld.so.conf
8 echo "/root/usr/lib" >> /etc/ld.so.conf
10 mountpoint=/live_media
12 root_persistence="live-rw"
13 home_persistence="home-rw"
14 root_snapshot_label="live-sn"
15 home_snapshot_label="home-sn"
18 USERFULLNAME="Live user"
24 [ -f /etc/live.conf ] && . /etc/live.conf
25 export USERNAME USERFULLNAME HOSTNAME BUILD_SYSTEM
27 . /scripts/live-helpers
29 if [ ! -f /live.vars ]; then
37 # looking for live-initramfs specifics options as kernel parameters
39 for x in $(cat /proc/cmdline)
53 HOSTNAME=${x#hostname=}
55 export HOSTNAME LIVECONF
59 USERNAME=${x#username=}
61 export USERNAME LIVECONF
65 USERFULLNAME=${x#userfullname=}
67 export USERFULLNAME LIVECONF
73 if [ -z "${STATICIP}" ]
81 keyb=*|kbd-chooser/method=*)
86 klayout=*|console-setup/layoutcode=*)
91 kvariant=*|console-setup/variantcode=*)
96 kmodel=*|console-setup/modelcode=*)
101 KOPTIONS=${x#koptions=}
109 live-media=*|bootfrom=*)
114 live-media-encryption=*|encryption=*)
115 LIVE_MEDIA_ENCRYPTION=${x#*=}
116 export LIVE_MEDIA_ENCRYPTION
120 LIVE_MEDIA_OFFSET=${x#live-media-offset=}
121 export LIVE_MEDIA_OFFSET
124 live-media-timeout=*)
125 LIVE_MEDIA_TIMEOUT=${x#live-media-timeout=}
126 export LIVE_MEDIA_TIMEOUT
129 locale=*|debian-installer/locale=*)
140 NETBOOT=${x#netboot=}
145 NFSOPTS=${x#nfsopts=}
179 preseed/file=*|file=*)
187 PRESEEDS="${PRESEEDS}\"${question}=${value}\" "
213 XVIDEOMODE="${x#xvideomode=}"
219 # sort of compatibility with netboot.h from linux docs
220 if [ -z "${NETBOOT}" ]
222 if [ "${ROOT}" = "/dev/nfs" ]
226 elif [ "${ROOT}" = "/dev/cifs" ]
233 if [ -z "${MODULE}" ]
243 if [ -d "${DIRECTORY}"/live ]
245 for FILESYSTEM in squashfs ext2 ext3 xfs dir
247 if [ "`echo ${DIRECTORY}/live/*.${FILESYSTEM}`" != "${DIRECTORY}/live/*.${FILESYSTEM}" ]
257 get_backing_device() {
259 *.squashfs|*.ext2|*.ext3)
260 echo $(setup_loop "$1" "loop" "/sys/block/loop*" '0' "${LIVE_MEDIA_ENCRYPTION}")
266 panic "Unrecognized live filesystem: $1"
271 match_files_in_dir() {
272 # Does any files match pattern $1 ?
275 if [ "$(echo $pattern)" != "$pattern" ]; then
281 mount_images_in_directory() {
284 if match_files_in_dir "$directory/live/*.squashfs" ||
285 match_files_in_dir "$directory/live/*.ext2" ||
286 match_files_in_dir "$directory/live/*.ext3" ||
287 match_files_in_dir "$directory/live/*.dir"; then
288 setup_unionfs "$directory/live" "$rootmnt"
295 sysfs_path="${1#/sys}"
296 if /lib/udev/path_id "${sysfs_path}" | grep -E -q "ID_PATH=(usb|pci-[^-]*-[ide|scsi|usb])"; then
303 # FIXME: do something better like the scan of supported filesystems
306 vfat|iso9660|udf|ext2|ext3|ntfs)
316 copyto="${copyfrom}_swap"
318 size=$(fs_size "" ${copyfrom} "used")
320 if [ "${copytodev}" = "ram" ]; then
322 freespace=$( expr $(awk '/MemFree/{print $2}' /proc/meminfo) + $( cat /proc/meminfo | grep Cached | head -n 1 | awk '/Cached/{print $2}' - ) )
323 mount_options="-o size=${size}k"
328 # it should be a writable block device
329 if [ -b "${copytodev}" ]; then
332 fstype=$(get_fstype "${dev}")
333 freespace=$(fs_size "${dev}")
335 [ "$quiet" != "y" ] && log_warning_msg "${copytodev} is not a block device."
339 if [ "${freespace}" -lt "${size}" ] ; then
340 [ "$quiet" != "y" ] && log_warning_msg "Not enough free ${free_string} (${freespace}k > ${size}k) to copy live media in ${copytodev}."
346 echo "mount -t ${fstype} ${mount_options} ${dev} ${copyto}"
347 mount -t "${fstype}" ${mount_options} "${dev}" "${copyto}"
348 cp -a ${copyfrom}/* ${copyto} # "cp -a" from busybox also copies hidden files
350 mount -r --move ${copyto} ${copyfrom}
358 modprobe "${MP_QUIET}" af_packet # For DHCP
363 ipconfig ${DEVICE} /tmp/net-${DEVICE}.conf | tee /netboot.config
365 if [ "${NFSROOT}" = "auto" ]; then
366 NFSROOT=${ROOTSERVER}:${ROOTPATH}
369 [ "$quiet" != "y" ] && log_begin_msg "Trying netboot from ${NFSROOT}"
371 if [ "${NETBOOT}" != "nfs" ] && do_cifsmount ; then
373 elif do_nfsmount ; then
379 [ "$quiet" != "y" ] && log_end_msg
385 modprobe "${MP_QUIET}" nfs
386 if [ -z "${NFSOPTS}" ]; then
390 [ "$quiet" != "y" ] && log_begin_msg "Trying nfsmount -o nolock -o ro ${NFSOPTS} ${NFSROOT} ${mountpoint}"
391 # FIXME: This for loop is an ugly HACK round an nfs bug
392 for i in 0 1 2 3 4 5 6 7 8 9 a b c d e f 10 11 12 13; do
393 nfsmount -o nolock -o ro ${NFSOPTS} "${NFSROOT}" "${mountpoint}" && rc=0 && break
401 if [ -x "/sbin/mount.cifs" ]; then
402 if [ -z "${NFSOPTS}" ]; then
403 CIFSOPTS="-ouser=root,password="
405 CIFSOPTS="${NFSOPTS}"
408 [ "$quiet" != "y" ] && log_begin_msg "Trying mount.cifs ${NFSROOT} ${mountpoint} ${CIFSOPTS}"
409 modprobe "${MP_QUIET}" cifs
411 if mount.cifs "${NFSROOT}" "${mountpoint}" "${CIFSOPTS}" ; then
424 size=$(fs_size "${fromdev}" "" "used")
426 if [ -b "${fromdev}" ]; then
428 if [ -n "${HOMEMOUNTED}" -a "${snap_type}" = "HOME" ]; then
429 todev=$(cat /proc/mounts | grep -s " $(base_path ${todir}) " | awk '{print $1}' )
430 freespace=$(df -k | grep -s ${todev} | awk '{print $4}')
432 freespace=$( expr $(awk '/MemFree/{print $2}' /proc/meminfo) + $( cat /proc/meminfo | grep Cached | head -n 1 | awk '/Cached/{print $2}' - ))
435 tomount="/mnt/tmpsnap"
436 if [ ! -d "${tomount}" ] ; then
437 mkdir -p "${tomount}"
440 fstype=$(get_fstype "${fromdev}")
441 if [ -n "${fstype}" ]; then
443 mount -t "${fstype}" -o ro "${fromdev}" "${tomount}"
444 cp -a "${tomount}"/* ${todir}
447 log_warning_msg "Unrecognized fstype: ${fstype} on ${fromdev}:${snap_type}"
451 if echo ${fromdev} | grep -qs loop; then
452 losetup -d "${fromdev}"
457 [ "$quiet" != "y" ] && log_warning_msg "Unable to find the snapshot ${snap_type} medium"
463 # Look for $snap_label.* in block devices and copy the contents to $snap_mount
464 # and remember the device and filename for resync on exit in live-initramfs.init
470 snapdata=$(find_files "${snap_label}.squashfs ${snap_label}.cpio.gz ${snap_label}.ext2 ${snap_label}.ext3")
471 if [ ! -z "${snapdata}" ]; then
472 snapdev="$(echo ${snapdata} | cut -f1 -d ' ')"
473 snapback="$(echo ${snapdata} | cut -f2 -d ' ')"
474 snapfile="$(echo ${snapdata} | cut -f3 -d ' ')"
475 if echo "${snapfile}" | grep -qs '\(squashfs\|ext2\|ext3\)'; then
476 # squashfs or ext2/ext3 snapshot
477 dev=$(get_backing_device "${snapback}/${snapfile}")
478 if ! do_snap_copy "${dev}" "${snap_mount}" "${snap_type}"; then
479 log_warning_msg "Impossible to include the ${snapfile} Snapshot"
484 if ! (cd "${snap_mount}" && zcat "${snapback}/${snapfile}" | cpio -i -u -d 2>/dev/null) ; then
485 log_warning_msg "Impossible to include the ${snapfile} Snapshot"
491 dev=$(find_cow_device "${snap_label}")
492 if [ -b ${dev} ]; then
493 if echo "${dev}" | grep -qs loop; then
494 # strange things happens, user confused?
495 snaploop=$( losetup ${dev} | awk '{print $3}' | tr -d '()' )
496 snapfile=$(basename ${snaploop})
497 snapdev=$(cat /proc/mounts | awk '{print $2,$1}' | grep -es "^$( dirname ${snaploop} )" | cut -f2 -d ' ')
501 if ! do_snap_copy "${dev}" "${snap_mount}" "${snap_type}" ; then
502 log_warning_msg "Impossible to include the ${snap_label} Snapshot"
505 if [ -n "${snapfile}" ]; then
506 # it was a loop device, user confused
511 log_warning_msg "Impossible to include the ${snap_label} Snapshot"
515 echo "export ${snap_type}SNAP="${snap_mount}":${snapdev}:${snapfile}" >> /etc/live.conf # for resync on reboot/halt
523 modprobe "${MP_QUIET}" -b unionfs
525 # run-init can't deal with images in a subdir, but we're going to
526 # move all of these away before it runs anyway. No, we're not,
527 # put them in / since move-mounting them into / breaks mono and
532 # Let's just mount the read-only file systems first
535 if [ "${NETBOOT}" = "nfs" ] ; then
536 roopt="nfsro" # go aroung a bug in nfs-unionfs locking
541 # Read image names from ${MODULE}.module if it exists
542 if [ -e "${image_directory}/filesystem.${MODULE}.module" ]
544 for IMAGE in `cat ${image_directory}/filesystem.${MODULE}.module`
546 image_string="${image_string} ${image_directory}/${image}"
548 elif [ -e "${image_directory}/${MODULE}.module" ]
550 for IMAGE in `cat ${image_directory}/${MODULE}.module`
552 image_string="${image_string} ${image_directory}/${image}"
555 # ${MODULE}.module does not exist, create a list of images
556 for FILESYSTEM in squashfs ext2 ext3 xfs dir
558 for IMAGE in "${image_directory}"/*."${FILESYSTEM}"
562 image_string="${image_string} ${IMAGE}"
568 image_string="`echo ${image_string} | sed -e 's/ /\n/g' | sort `"
572 for image in ${image_string}; do
573 imagename=$(basename "${image}")
574 if [ -d "${image}" ]; then
575 # it is a plain directory: do nothing
576 rofsstring="${image}=${roopt}:${rofsstring}"
577 rofslist="${image} ${rofslist}"
578 elif [ -f "${image}" ]; then
579 backdev=$(get_backing_device "$image")
580 fstype=$(get_fstype "${backdev}")
581 if [ "${fstype}" = "unknown" ]; then
582 panic "Unknown file system type on ${backdev} (${image})"
584 mkdir -p "${croot}/${imagename}"
585 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}"
588 rofsstring=${rofsstring%:}
594 # Looking for "${root_persistence}" device or file
595 if [ -n "${PERSISTENT}" ]; then
596 cowprobe=$(find_cow_device "${root_persistence}")
597 if [ -b "${cowprobe}" ]; then
598 cowdevice=${cowprobe}
599 cow_fstype=$(get_fstype "${cowprobe}")
601 [ "$quiet" != "y" ] && log_warning_msg "Unable to find the persistent medium"
605 mount ${cowdevice} -t ${cow_fstype} -o rw /cow || panic "Can not mount $cowdevice on /cow"
607 mount -t unionfs -o dirs=/cow=rw:$rofsstring unionfs "$rootmnt" || panic "Unionfs mount failed"
609 # Adding other custom mounts
610 if [ -n "${PERSISTENT}" ]; then
611 # directly mount /home
612 # FIXME: add a custom mounts configurable system
613 homecow=$(find_cow_device "${home_persistence}" )
614 if [ -b "${homecow}" ]; then
615 mount -t $(get_fstype "${homecow}") -o rw "${homecow}" "${rootmnt}/home"
616 export HOMEMOUNTED=1 # used to proper calculate free space in do_snap_copy()
618 [ "$quiet" != "y" ] && log_warning_msg "Unable to find the persistent home medium"
620 # Look for other snapshots to copy in
621 try_snap "${root_snapshot_label}" "${rootmnt}" "ROOT"
622 try_snap "${home_snapshot_label}" "${rootmnt}/home" "HOME"
625 if [ -n "${SHOWMOUNTS}" ]; then
626 for d in ${rofslist}; do
627 mkdir -p "${rootmnt}/live/${d##*/}"
629 *.dir) # do nothing # mount -o bind "${d}" "${rootmnt}/live/${d##*/}"
631 *) mount --move "${d}" "${rootmnt}/live/${d##*/}"
637 # shows cow fs on /cow for use by live-snapshot
638 mkdir -p "${rootmnt}/cow"
639 mount -o bind /cow "${rootmnt}/cow"
646 if [ -z "${devname}" ]; then
647 devname=$(sys2dev "${sysdev}")
650 if [ -n "${LIVE_MEDIA_OFFSET}" ]; then
651 loopdevname=$(setup_loop "${devname}" "loop" "/sys/block/loop*" "${LIVE_MEDIA_OFFSET}" '')
652 devname="${loopdevname}"
655 fstype=$(get_fstype "${devname}")
656 if is_supported_fs ${fstype}; then
657 mount -t ${fstype} -o ro "${devname}" $mountpoint || continue
658 if is_live_path $mountpoint; then
666 if [ -n "${LIVE_MEDIA_OFFSET}" ]; then
667 losetup -d "${loopdevname}"
674 # first look at the one specified in the command line
675 if [ ! -z "${LIVE_MEDIA}" ]; then
676 if check_dev "null" "${LIVE_MEDIA}"; then
680 # don't start autodetection before timeout has expired
681 if [ -n "${LIVE_MEDIA_TIMEOUT}" ]; then
682 if [ "${timeout}" -lt "${LIVE_MEDIA_TIMEOUT}" ]; then
686 # or do the scan of block devices
687 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -v loop | grep -v ram); do
688 devname=$(sys2dev "${sysblock}")
689 fstype=$(get_fstype "${devname}")
690 if /lib/udev/cdrom_id ${devname} > /dev/null; then
691 if check_dev "null" "${devname}" ; then
694 elif is_nice_device "${sysblock}" ; then
695 for dev in $(subdevices "${sysblock}"); do
696 if check_dev "${dev}" ; then
700 elif [ "${fstype}" = "squashfs" -o \
701 "${fstype}" = "ext2" -o \
702 "${fstype}" = "ext3" ]; then
703 # This is an ugly hack situation, the block device has
704 # an image directly on it. It's hopefully
705 # live-initramfs, so take it and run with it.
706 ln -s "${devname}" "${devname}.${fstype}"
707 echo "${devname}.${fstype}"
715 if [ -x /sbin/usplash_write ]; then
716 /sbin/usplash_write "PULSATE"
720 set_usplash_timeout() {
721 if [ -x /sbin/usplash_write ]; then
722 /sbin/usplash_write "TIMEOUT 120"
735 [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/live-premount"
737 run_scripts /scripts/live-premount
738 [ "$quiet" != "y" ] && log_end_msg
740 # Needed here too because some things (*cough* udev *cough*)
741 # changes the timeout
745 if [ ! -z "${NETBOOT}" ]; then
746 if do_netmount ; then
747 livefs_root="${mountpoint}"
749 panic "Unable to find a live file system on the network"
752 # Scan local devices for the image
753 for i in 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19; do
754 livefs_root=$(find_livefs $i)
755 if [ -n "${livefs_root}" ]; then
762 if [ -z "${livefs_root}" ]; then
763 panic "Unable to find a medium containing a live file system"
766 if [ "${TORAM}" ]; then
768 elif [ "${TODISK}" ]; then
769 live_dest="${TODISK}"
771 if [ "${live_dest}" ]; then
772 log_begin_msg "Copying live_media to ${live_dest}"
773 copy_live_to "${livefs_root}" "${live_dest}"
777 mount_images_in_directory "${livefs_root}" "${rootmnt}"
781 maybe_break live-bottom
782 [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/live-bottom"
785 run_scripts /scripts/live-bottom
786 [ "$quiet" != "y" ] && log_end_msg
790 cp live.log "${rootmnt}/var/log/"