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 # source relevant ipconfig output
401 . /tmp/net-${DEVICE}.conf
404 if [ "${NFSROOT#*:}" = "$NFSROOT" ]; then
405 NFSROOT=${ROOTSERVER}:${NFSROOT}
408 [ "$quiet" != "y" ] && log_begin_msg "Trying netboot from ${NFSROOT}"
410 if [ "${NETBOOT}" != "nfs" ] && do_cifsmount ; then
412 elif do_nfsmount ; then
418 [ "$quiet" != "y" ] && log_end_msg
424 modprobe "${MP_QUIET}" nfs
425 if [ -z "${NFSOPTS}" ]; then
429 [ "$quiet" != "y" ] && log_begin_msg "Trying nfsmount -o nolock -o ro ${NFSOPTS} ${NFSROOT} ${mountpoint}"
430 # FIXME: This for loop is an ugly HACK round an nfs bug
431 for i in 0 1 2 3 4 5 6 7 8 9 a b c d e f 10 11 12 13; do
432 nfsmount -o nolock -o ro ${NFSOPTS} "${NFSROOT}" "${mountpoint}" && rc=0 && break
440 if [ -x "/sbin/mount.cifs" ]; then
441 if [ -z "${NFSOPTS}" ]; then
442 CIFSOPTS="-ouser=root,password="
444 CIFSOPTS="${NFSOPTS}"
447 [ "$quiet" != "y" ] && log_begin_msg "Trying mount.cifs ${NFSROOT} ${mountpoint} ${CIFSOPTS}"
448 modprobe "${MP_QUIET}" cifs
450 if mount.cifs "${NFSROOT}" "${mountpoint}" "${CIFSOPTS}" ; then
463 size=$(fs_size "${fromdev}" "" "used")
465 if [ -b "${fromdev}" ]; then
467 if [ -n "${HOMEMOUNTED}" -a "${snap_type}" = "HOME" ]; then
468 todev=$(cat /proc/mounts | grep -s " $(base_path ${todir}) " | awk '{print $1}' )
469 freespace=$(df -k | grep -s ${todev} | awk '{print $4}')
471 freespace=$( expr $(awk '/MemFree/{print $2}' /proc/meminfo) + $( cat /proc/meminfo | grep Cached | head -n 1 | awk '/Cached/{print $2}' - ))
474 tomount="/mnt/tmpsnap"
475 if [ ! -d "${tomount}" ] ; then
476 mkdir -p "${tomount}"
479 fstype=$(get_fstype "${fromdev}")
480 if [ -n "${fstype}" ]; then
482 mount -t "${fstype}" -o ro "${fromdev}" "${tomount}"
483 cp -a "${tomount}"/* ${todir}
486 log_warning_msg "Unrecognized fstype: ${fstype} on ${fromdev}:${snap_type}"
490 if echo ${fromdev} | grep -qs loop; then
491 losetup -d "${fromdev}"
496 [ "$quiet" != "y" ] && log_warning_msg "Unable to find the snapshot ${snap_type} medium"
502 # Look for $snap_label.* in block devices and copy the contents to $snap_mount
503 # and remember the device and filename for resync on exit in live-initramfs.init
509 snapdata=$(find_files "${snap_label}.squashfs ${snap_label}.cpio.gz ${snap_label}.ext2 ${snap_label}.ext3")
510 if [ ! -z "${snapdata}" ]; then
511 snapdev="$(echo ${snapdata} | cut -f1 -d ' ')"
512 snapback="$(echo ${snapdata} | cut -f2 -d ' ')"
513 snapfile="$(echo ${snapdata} | cut -f3 -d ' ')"
514 if echo "${snapfile}" | grep -qs '\(squashfs\|ext2\|ext3\)'; then
515 # squashfs or ext2/ext3 snapshot
516 dev=$(get_backing_device "${snapback}/${snapfile}")
517 if ! do_snap_copy "${dev}" "${snap_mount}" "${snap_type}"; then
518 log_warning_msg "Impossible to include the ${snapfile} Snapshot"
523 if ! (cd "${snap_mount}" && zcat "${snapback}/${snapfile}" | cpio -i -u -d 2>/dev/null) ; then
524 log_warning_msg "Impossible to include the ${snapfile} Snapshot"
530 dev=$(find_cow_device "${snap_label}")
531 if [ -b ${dev} ]; then
532 if echo "${dev}" | grep -qs loop; then
533 # strange things happens, user confused?
534 snaploop=$( losetup ${dev} | awk '{print $3}' | tr -d '()' )
535 snapfile=$(basename ${snaploop})
536 snapdev=$(cat /proc/mounts | awk '{print $2,$1}' | grep -es "^$( dirname ${snaploop} )" | cut -f2 -d ' ')
540 if ! do_snap_copy "${dev}" "${snap_mount}" "${snap_type}" ; then
541 log_warning_msg "Impossible to include the ${snap_label} Snapshot"
544 if [ -n "${snapfile}" ]; then
545 # it was a loop device, user confused
550 log_warning_msg "Impossible to include the ${snap_label} Snapshot"
554 echo "export ${snap_type}SNAP="${snap_mount}":${snapdev}:${snapfile}" >> /etc/live.conf # for resync on reboot/halt
562 modprobe "${MP_QUIET}" -b ${UNIONTYPE}
564 # run-init can't deal with images in a subdir, but we're going to
565 # move all of these away before it runs anyway. No, we're not,
566 # put them in / since move-mounting them into / breaks mono and
571 # Let's just mount the read-only file systems first
574 if [ "${NETBOOT}" = "nfs" ] ; then
575 roopt="nfsro" # go aroung a bug in nfs-unionfs locking
580 # Read image names from ${MODULE}.module if it exists
581 if [ -e "${image_directory}/filesystem.${MODULE}.module" ]
583 for IMAGE in `cat ${image_directory}/filesystem.${MODULE}.module`
585 image_string="${image_string} ${image_directory}/${image}"
587 elif [ -e "${image_directory}/${MODULE}.module" ]
589 for IMAGE in `cat ${image_directory}/${MODULE}.module`
591 image_string="${image_string} ${image_directory}/${image}"
594 # ${MODULE}.module does not exist, create a list of images
595 for FILESYSTEM in squashfs ext2 ext3 xfs dir
597 for IMAGE in "${image_directory}"/*."${FILESYSTEM}"
601 image_string="${image_string} ${IMAGE}"
607 image_string="`echo ${image_string} | sed -e 's/ /\n/g' | sort `"
611 for image in ${image_string}; do
612 imagename=$(basename "${image}")
613 if [ -d "${image}" ]; then
614 # it is a plain directory: do nothing
615 rofsstring="${image}=${roopt}:${rofsstring}"
616 rofslist="${image} ${rofslist}"
617 elif [ -f "${image}" ]; then
618 backdev=$(get_backing_device "$image")
619 fstype=$(get_fstype "${backdev}")
620 if [ "${fstype}" = "unknown" ]; then
621 panic "Unknown file system type on ${backdev} (${image})"
623 mkdir -p "${croot}/${imagename}"
624 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}"
627 rofsstring=${rofsstring%:}
633 # Looking for "${root_persistence}" device or file
634 if [ -n "${PERSISTENT}" ]; then
635 cowprobe=$(find_cow_device "${root_persistence}")
636 if [ -b "${cowprobe}" ]; then
637 cowdevice=${cowprobe}
638 cow_fstype=$(get_fstype "${cowprobe}")
640 [ "$quiet" != "y" ] && log_warning_msg "Unable to find the persistent medium"
644 mount ${cowdevice} -t ${cow_fstype} -o rw /cow || panic "Can not mount $cowdevice on /cow"
646 mount -t ${UNIONTYPE} -o dirs=/cow=rw:$rofsstring ${UNIONTYPE} "$rootmnt" || panic "${UNIONTYPE} mount failed"
648 # Adding other custom mounts
649 if [ -n "${PERSISTENT}" ]; then
650 # directly mount /home
651 # FIXME: add a custom mounts configurable system
652 homecow=$(find_cow_device "${home_persistence}" )
653 if [ -b "${homecow}" ]; then
654 mount -t $(get_fstype "${homecow}") -o rw "${homecow}" "${rootmnt}/home"
655 export HOMEMOUNTED=1 # used to proper calculate free space in do_snap_copy()
657 [ "$quiet" != "y" ] && log_warning_msg "Unable to find the persistent home medium"
659 # Look for other snapshots to copy in
660 try_snap "${root_snapshot_label}" "${rootmnt}" "ROOT"
661 try_snap "${home_snapshot_label}" "${rootmnt}/home" "HOME"
664 if [ -n "${SHOWMOUNTS}" ]; then
665 for d in ${rofslist}; do
666 mkdir -p "${rootmnt}/live/${d##*/}"
668 *.dir) # do nothing # mount -o bind "${d}" "${rootmnt}/live/${d##*/}"
670 *) mount --move "${d}" "${rootmnt}/live/${d##*/}"
676 # shows cow fs on /cow for use by live-snapshot
677 mkdir -p "${rootmnt}/live/cow"
678 mount -o bind /cow "${rootmnt}/live/cow"
685 if [ -z "${devname}" ]; then
686 devname=$(sys2dev "${sysdev}")
689 if [ -n "${LIVE_MEDIA_OFFSET}" ]; then
690 loopdevname=$(setup_loop "${devname}" "loop" "/sys/block/loop*" "${LIVE_MEDIA_OFFSET}" '')
691 devname="${loopdevname}"
694 fstype=$(get_fstype "${devname}")
695 if is_supported_fs ${fstype}; then
696 mount -t ${fstype} -o ro "${devname}" $mountpoint || continue
697 if is_live_path $mountpoint; then
705 if [ -n "${LIVE_MEDIA_OFFSET}" ]; then
706 losetup -d "${loopdevname}"
713 # first look at the one specified in the command line
714 if [ ! -z "${LIVE_MEDIA}" ]; then
715 if check_dev "null" "${LIVE_MEDIA}"; then
719 # don't start autodetection before timeout has expired
720 if [ -n "${LIVE_MEDIA_TIMEOUT}" ]; then
721 if [ "${timeout}" -lt "${LIVE_MEDIA_TIMEOUT}" ]; then
725 # or do the scan of block devices
726 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -v loop | grep -v ram); do
727 devname=$(sys2dev "${sysblock}")
728 fstype=$(get_fstype "${devname}")
729 if /lib/udev/cdrom_id ${devname} > /dev/null; then
730 if check_dev "null" "${devname}" ; then
733 elif is_nice_device "${sysblock}" ; then
734 for dev in $(subdevices "${sysblock}"); do
735 if check_dev "${dev}" ; then
739 elif [ "${fstype}" = "squashfs" -o \
740 "${fstype}" = "ext2" -o \
741 "${fstype}" = "ext3" ]; then
742 # This is an ugly hack situation, the block device has
743 # an image directly on it. It's hopefully
744 # live-initramfs, so take it and run with it.
745 ln -s "${devname}" "${devname}.${fstype}"
746 echo "${devname}.${fstype}"
754 if [ -x /sbin/usplash_write ]; then
755 /sbin/usplash_write "PULSATE"
759 set_usplash_timeout() {
760 if [ -x /sbin/usplash_write ]; then
761 /sbin/usplash_write "TIMEOUT 120"
774 [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/live-premount"
776 run_scripts /scripts/live-premount
777 [ "$quiet" != "y" ] && log_end_msg
779 # Needed here too because some things (*cough* udev *cough*)
780 # changes the timeout
784 if [ ! -z "${NETBOOT}" ]; then
785 if do_netmount ; then
786 livefs_root="${mountpoint}"
788 panic "Unable to find a live file system on the network"
791 # Scan local devices for the image
792 for i in 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19; do
793 livefs_root=$(find_livefs $i)
794 if [ -n "${livefs_root}" ]; then
801 if [ -z "${livefs_root}" ]; then
802 panic "Unable to find a medium containing a live file system"
805 if [ "${TORAM}" ]; then
807 elif [ "${TODISK}" ]; then
808 live_dest="${TODISK}"
810 if [ "${live_dest}" ]; then
811 log_begin_msg "Copying live media to ${live_dest}"
812 copy_live_to "${livefs_root}" "${live_dest}"
816 mount_images_in_directory "${livefs_root}" "${rootmnt}"
820 maybe_break live-bottom
821 [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/live-bottom"
824 run_scripts /scripts/live-bottom
825 [ "$quiet" != "y" ] && log_end_msg
829 cp live.log "${rootmnt}/var/log/"