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/image
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)
60 HOSTNAME=${x#hostname=}
62 export HOSTNAME LIVECONF
66 USERNAME=${x#username=}
68 export USERNAME LIVECONF
72 USERFULLNAME=${x#userfullname=}
74 export USERFULLNAME LIVECONF
80 if [ -z "${STATICIP}" ]
88 keyb=*|kbd-chooser/method=*)
93 klayout=*|console-setup/layoutcode=*)
98 kvariant=*|console-setup/variantcode=*)
103 kmodel=*|console-setup/modelcode=*)
109 KOPTIONS=${x#koptions=}
118 live-media=*|bootfrom=*)
123 live-media-encryption=*|encryption=*)
124 LIVE_MEDIA_ENCRYPTION=${x#*=}
125 export LIVE_MEDIA_ENCRYPTION
129 LIVE_MEDIA_OFFSET=${x#live-media-offset=}
130 export LIVE_MEDIA_OFFSET
133 live-media-timeout=*)
134 LIVE_MEDIA_TIMEOUT=${x#live-media-timeout=}
135 export LIVE_MEDIA_TIMEOUT
138 locale=*|debian-installer/locale=*)
149 NETBOOT=${x#netboot=}
154 NFSOPTS=${x#nfsopts=}
193 preseed/file=*|file=*)
201 PRESEEDS="${PRESEEDS}\"${question}=${value}\" "
212 TIMEZONE="${x#timezone=}"
227 UNIONTYPE="${x#union=}"
237 XVIDEOMODE="${x#xvideomode=}"
243 # sort of compatibility with netboot.h from linux docs
244 if [ -z "${NETBOOT}" ]
246 if [ "${ROOT}" = "/dev/nfs" ]
250 elif [ "${ROOT}" = "/dev/cifs" ]
257 if [ -z "${MODULE}" ]
263 if [ -z "${UNIONTYPE}" ]
274 if [ -d "${DIRECTORY}"/live ]
276 for FILESYSTEM in squashfs ext2 ext3 xfs dir
278 if [ "`echo ${DIRECTORY}/live/*.${FILESYSTEM}`" != "${DIRECTORY}/live/*.${FILESYSTEM}" ]
288 get_backing_device() {
290 *.squashfs|*.ext2|*.ext3)
291 echo $(setup_loop "$1" "loop" "/sys/block/loop*" '0' "${LIVE_MEDIA_ENCRYPTION}")
297 panic "Unrecognized live filesystem: $1"
302 match_files_in_dir() {
303 # Does any files match pattern $1 ?
306 if [ "$(echo $pattern)" != "$pattern" ]; then
312 mount_images_in_directory() {
315 if match_files_in_dir "$directory/live/*.squashfs" ||
316 match_files_in_dir "$directory/live/*.ext2" ||
317 match_files_in_dir "$directory/live/*.ext3" ||
318 match_files_in_dir "$directory/live/*.dir"; then
319 setup_unionfs "$directory/live" "$rootmnt"
326 sysfs_path="${1#/sys}"
327 if /lib/udev/path_id "${sysfs_path}" | grep -E -q "ID_PATH=(usb|pci-[^-]*-[ide|scsi|usb])"; then
334 # FIXME: do something better like the scan of supported filesystems
337 vfat|iso9660|udf|ext2|ext3|ntfs)
347 copyto="${copyfrom}_swap"
349 size=$(fs_size "" ${copyfrom} "used")
351 if [ "${copytodev}" = "ram" ]; then
353 freespace=$( expr $(awk '/MemFree/{print $2}' /proc/meminfo) + $( cat /proc/meminfo | grep Cached | head -n 1 | awk '/Cached/{print $2}' - ) )
354 mount_options="-o size=${size}k"
359 # it should be a writable block device
360 if [ -b "${copytodev}" ]; then
363 fstype=$(get_fstype "${dev}")
364 freespace=$(fs_size "${dev}")
366 [ "$quiet" != "y" ] && log_warning_msg "${copytodev} is not a block device."
370 if [ "${freespace}" -lt "${size}" ] ; then
371 [ "$quiet" != "y" ] && log_warning_msg "Not enough free ${free_string} (${freespace}k > ${size}k) to copy live media in ${copytodev}."
377 echo "mount -t ${fstype} ${mount_options} ${dev} ${copyto}"
378 mount -t "${fstype}" ${mount_options} "${dev}" "${copyto}"
379 cp -a ${copyfrom}/* ${copyto} # "cp -a" from busybox also copies hidden files
381 mount -r --move ${copyto} ${copyfrom}
389 modprobe "${MP_QUIET}" af_packet # For DHCP
394 ipconfig ${DEVICE} /tmp/net-${DEVICE}.conf | tee /netboot.config
396 if [ "${NFSROOT}" = "auto" ]; then
397 NFSROOT=${ROOTSERVER}:${ROOTPATH}
400 [ "$quiet" != "y" ] && log_begin_msg "Trying netboot from ${NFSROOT}"
402 if [ "${NETBOOT}" != "nfs" ] && do_cifsmount ; then
404 elif do_nfsmount ; then
410 [ "$quiet" != "y" ] && log_end_msg
416 modprobe "${MP_QUIET}" nfs
417 if [ -z "${NFSOPTS}" ]; then
421 [ "$quiet" != "y" ] && log_begin_msg "Trying nfsmount -o nolock -o ro ${NFSOPTS} ${NFSROOT} ${mountpoint}"
422 # FIXME: This for loop is an ugly HACK round an nfs bug
423 for i in 0 1 2 3 4 5 6 7 8 9 a b c d e f 10 11 12 13; do
424 nfsmount -o nolock -o ro ${NFSOPTS} "${NFSROOT}" "${mountpoint}" && rc=0 && break
432 if [ -x "/sbin/mount.cifs" ]; then
433 if [ -z "${NFSOPTS}" ]; then
434 CIFSOPTS="-ouser=root,password="
436 CIFSOPTS="${NFSOPTS}"
439 [ "$quiet" != "y" ] && log_begin_msg "Trying mount.cifs ${NFSROOT} ${mountpoint} ${CIFSOPTS}"
440 modprobe "${MP_QUIET}" cifs
442 if mount.cifs "${NFSROOT}" "${mountpoint}" "${CIFSOPTS}" ; then
455 size=$(fs_size "${fromdev}" "" "used")
457 if [ -b "${fromdev}" ]; then
459 if [ -n "${HOMEMOUNTED}" -a "${snap_type}" = "HOME" ]; then
460 todev=$(cat /proc/mounts | grep -s " $(base_path ${todir}) " | awk '{print $1}' )
461 freespace=$(df -k | grep -s ${todev} | awk '{print $4}')
463 freespace=$( expr $(awk '/MemFree/{print $2}' /proc/meminfo) + $( cat /proc/meminfo | grep Cached | head -n 1 | awk '/Cached/{print $2}' - ))
466 tomount="/mnt/tmpsnap"
467 if [ ! -d "${tomount}" ] ; then
468 mkdir -p "${tomount}"
471 fstype=$(get_fstype "${fromdev}")
472 if [ -n "${fstype}" ]; then
474 mount -t "${fstype}" -o ro "${fromdev}" "${tomount}"
475 cp -a "${tomount}"/* ${todir}
478 log_warning_msg "Unrecognized fstype: ${fstype} on ${fromdev}:${snap_type}"
482 if echo ${fromdev} | grep -qs loop; then
483 losetup -d "${fromdev}"
488 [ "$quiet" != "y" ] && log_warning_msg "Unable to find the snapshot ${snap_type} medium"
494 # Look for $snap_label.* in block devices and copy the contents to $snap_mount
495 # and remember the device and filename for resync on exit in live-initramfs.init
501 snapdata=$(find_files "${snap_label}.squashfs ${snap_label}.cpio.gz ${snap_label}.ext2 ${snap_label}.ext3")
502 if [ ! -z "${snapdata}" ]; then
503 snapdev="$(echo ${snapdata} | cut -f1 -d ' ')"
504 snapback="$(echo ${snapdata} | cut -f2 -d ' ')"
505 snapfile="$(echo ${snapdata} | cut -f3 -d ' ')"
506 if echo "${snapfile}" | grep -qs '\(squashfs\|ext2\|ext3\)'; then
507 # squashfs or ext2/ext3 snapshot
508 dev=$(get_backing_device "${snapback}/${snapfile}")
509 if ! do_snap_copy "${dev}" "${snap_mount}" "${snap_type}"; then
510 log_warning_msg "Impossible to include the ${snapfile} Snapshot"
515 if ! (cd "${snap_mount}" && zcat "${snapback}/${snapfile}" | cpio -i -u -d 2>/dev/null) ; then
516 log_warning_msg "Impossible to include the ${snapfile} Snapshot"
522 dev=$(find_cow_device "${snap_label}")
523 if [ -b ${dev} ]; then
524 if echo "${dev}" | grep -qs loop; then
525 # strange things happens, user confused?
526 snaploop=$( losetup ${dev} | awk '{print $3}' | tr -d '()' )
527 snapfile=$(basename ${snaploop})
528 snapdev=$(cat /proc/mounts | awk '{print $2,$1}' | grep -es "^$( dirname ${snaploop} )" | cut -f2 -d ' ')
532 if ! do_snap_copy "${dev}" "${snap_mount}" "${snap_type}" ; then
533 log_warning_msg "Impossible to include the ${snap_label} Snapshot"
536 if [ -n "${snapfile}" ]; then
537 # it was a loop device, user confused
542 log_warning_msg "Impossible to include the ${snap_label} Snapshot"
546 echo "export ${snap_type}SNAP="${snap_mount}":${snapdev}:${snapfile}" >> /etc/live.conf # for resync on reboot/halt
554 modprobe "${MP_QUIET}" -b ${UNIONTYPE}
556 # run-init can't deal with images in a subdir, but we're going to
557 # move all of these away before it runs anyway. No, we're not,
558 # put them in / since move-mounting them into / breaks mono and
563 # Let's just mount the read-only file systems first
566 if [ "${NETBOOT}" = "nfs" ] ; then
567 roopt="nfsro" # go aroung a bug in nfs-unionfs locking
572 # Read image names from ${MODULE}.module if it exists
573 if [ -e "${image_directory}/filesystem.${MODULE}.module" ]
575 for IMAGE in `cat ${image_directory}/filesystem.${MODULE}.module`
577 image_string="${image_string} ${image_directory}/${image}"
579 elif [ -e "${image_directory}/${MODULE}.module" ]
581 for IMAGE in `cat ${image_directory}/${MODULE}.module`
583 image_string="${image_string} ${image_directory}/${image}"
586 # ${MODULE}.module does not exist, create a list of images
587 for FILESYSTEM in squashfs ext2 ext3 xfs dir
589 for IMAGE in "${image_directory}"/*."${FILESYSTEM}"
593 image_string="${image_string} ${IMAGE}"
599 image_string="`echo ${image_string} | sed -e 's/ /\n/g' | sort `"
603 for image in ${image_string}; do
604 imagename=$(basename "${image}")
605 if [ -d "${image}" ]; then
606 # it is a plain directory: do nothing
607 rofsstring="${image}=${roopt}:${rofsstring}"
608 rofslist="${image} ${rofslist}"
609 elif [ -f "${image}" ]; then
610 backdev=$(get_backing_device "$image")
611 fstype=$(get_fstype "${backdev}")
612 if [ "${fstype}" = "unknown" ]; then
613 panic "Unknown file system type on ${backdev} (${image})"
615 mkdir -p "${croot}/${imagename}"
616 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}"
619 rofsstring=${rofsstring%:}
625 # Looking for "${root_persistence}" device or file
626 if [ -n "${PERSISTENT}" ]; then
627 cowprobe=$(find_cow_device "${root_persistence}")
628 if [ -b "${cowprobe}" ]; then
629 cowdevice=${cowprobe}
630 cow_fstype=$(get_fstype "${cowprobe}")
632 [ "$quiet" != "y" ] && log_warning_msg "Unable to find the persistent medium"
636 mount ${cowdevice} -t ${cow_fstype} -o rw /cow || panic "Can not mount $cowdevice on /cow"
638 mount -t ${UNIONTYPE} -o dirs=/cow=rw:$rofsstring ${UNIONTYPE} "$rootmnt" || panic "${UNIONTYPE} mount failed"
640 # Adding other custom mounts
641 if [ -n "${PERSISTENT}" ]; then
642 # directly mount /home
643 # FIXME: add a custom mounts configurable system
644 homecow=$(find_cow_device "${home_persistence}" )
645 if [ -b "${homecow}" ]; then
646 mount -t $(get_fstype "${homecow}") -o rw "${homecow}" "${rootmnt}/home"
647 export HOMEMOUNTED=1 # used to proper calculate free space in do_snap_copy()
649 [ "$quiet" != "y" ] && log_warning_msg "Unable to find the persistent home medium"
651 # Look for other snapshots to copy in
652 try_snap "${root_snapshot_label}" "${rootmnt}" "ROOT"
653 try_snap "${home_snapshot_label}" "${rootmnt}/home" "HOME"
656 if [ -n "${SHOWMOUNTS}" ]; then
657 for d in ${rofslist}; do
658 mkdir -p "${rootmnt}/live/${d##*/}"
660 *.dir) # do nothing # mount -o bind "${d}" "${rootmnt}/live/${d##*/}"
662 *) mount --move "${d}" "${rootmnt}/live/${d##*/}"
668 # shows cow fs on /cow for use by live-snapshot
669 mkdir -p "${rootmnt}/live/cow"
670 mount -o bind /cow "${rootmnt}/live/cow"
677 if [ -z "${devname}" ]; then
678 devname=$(sys2dev "${sysdev}")
681 if [ -n "${LIVE_MEDIA_OFFSET}" ]; then
682 loopdevname=$(setup_loop "${devname}" "loop" "/sys/block/loop*" "${LIVE_MEDIA_OFFSET}" '')
683 devname="${loopdevname}"
686 fstype=$(get_fstype "${devname}")
687 if is_supported_fs ${fstype}; then
688 mount -t ${fstype} -o ro "${devname}" $mountpoint || continue
689 if is_live_path $mountpoint; then
697 if [ -n "${LIVE_MEDIA_OFFSET}" ]; then
698 losetup -d "${loopdevname}"
705 # first look at the one specified in the command line
706 if [ ! -z "${LIVE_MEDIA}" ]; then
707 if check_dev "null" "${LIVE_MEDIA}"; then
711 # don't start autodetection before timeout has expired
712 if [ -n "${LIVE_MEDIA_TIMEOUT}" ]; then
713 if [ "${timeout}" -lt "${LIVE_MEDIA_TIMEOUT}" ]; then
717 # or do the scan of block devices
718 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -v loop | grep -v ram); do
719 devname=$(sys2dev "${sysblock}")
720 fstype=$(get_fstype "${devname}")
721 if /lib/udev/cdrom_id ${devname} > /dev/null; then
722 if check_dev "null" "${devname}" ; then
725 elif is_nice_device "${sysblock}" ; then
726 for dev in $(subdevices "${sysblock}"); do
727 if check_dev "${dev}" ; then
731 elif [ "${fstype}" = "squashfs" -o \
732 "${fstype}" = "ext2" -o \
733 "${fstype}" = "ext3" ]; then
734 # This is an ugly hack situation, the block device has
735 # an image directly on it. It's hopefully
736 # live-initramfs, so take it and run with it.
737 ln -s "${devname}" "${devname}.${fstype}"
738 echo "${devname}.${fstype}"
746 if [ -x /sbin/usplash_write ]; then
747 /sbin/usplash_write "PULSATE"
751 set_usplash_timeout() {
752 if [ -x /sbin/usplash_write ]; then
753 /sbin/usplash_write "TIMEOUT 120"
766 [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/live-premount"
768 run_scripts /scripts/live-premount
769 [ "$quiet" != "y" ] && log_end_msg
771 # Needed here too because some things (*cough* udev *cough*)
772 # changes the timeout
776 if [ ! -z "${NETBOOT}" ]; then
777 if do_netmount ; then
778 livefs_root="${mountpoint}"
780 panic "Unable to find a live file system on the network"
783 # Scan local devices for the image
784 for i in 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19; do
785 livefs_root=$(find_livefs $i)
786 if [ -n "${livefs_root}" ]; then
793 if [ -z "${livefs_root}" ]; then
794 panic "Unable to find a medium containing a live file system"
797 if [ "${TORAM}" ]; then
799 elif [ "${TODISK}" ]; then
800 live_dest="${TODISK}"
802 if [ "${live_dest}" ]; then
803 log_begin_msg "Copying live media to ${live_dest}"
804 copy_live_to "${livefs_root}" "${live_dest}"
808 mount_images_in_directory "${livefs_root}" "${rootmnt}"
812 maybe_break live-bottom
813 [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/live-bottom"
816 run_scripts /scripts/live-bottom
817 [ "$quiet" != "y" ] && log_end_msg
821 cp live.log "${rootmnt}/var/log/"