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
11 LIVE_MEDIA_PATH="/live"
13 root_persistence="live-rw"
14 home_persistence="home-rw"
15 root_snapshot_label="live-sn"
16 home_snapshot_label="home-sn"
19 USERFULLNAME="Live user"
25 [ -f /etc/live.conf ] && . /etc/live.conf
26 export USERNAME USERFULLNAME HOSTNAME BUILD_SYSTEM
28 . /scripts/live-helpers
30 if [ ! -f /live.vars ]; then
38 # looking for live-initramfs specifics options as kernel parameters
40 for x in $(cat /proc/cmdline)
61 HOSTNAME=${x#hostname=}
63 export HOSTNAME LIVECONF
67 USERNAME=${x#username=}
69 export USERNAME LIVECONF
73 USERFULLNAME=${x#userfullname=}
75 export USERFULLNAME LIVECONF
81 if [ -z "${STATICIP}" ]
89 keyb=*|kbd-chooser/method=*)
94 klayout=*|console-setup/layoutcode=*)
99 kvariant=*|console-setup/variantcode=*)
104 kmodel=*|console-setup/modelcode=*)
110 KOPTIONS=${x#koptions=}
119 live-media=*|bootfrom=*)
124 live-media-encryption=*|encryption=*)
125 LIVE_MEDIA_ENCRYPTION=${x#*=}
126 export LIVE_MEDIA_ENCRYPTION
130 LIVE_MEDIA_OFFSET=${x#live-media-offset=}
131 export LIVE_MEDIA_OFFSET
135 LIVE_MEDIA_PATH="${x#live-media-path=}"
136 export LIVE_MEDIA_PATH
139 live-media-timeout=*)
140 LIVE_MEDIA_TIMEOUT=${x#live-media-timeout=}
141 export LIVE_MEDIA_TIMEOUT
144 locale=*|debian-installer/locale=*)
155 NETBOOT=${x#netboot=}
160 NFSOPTS=${x#nfsopts=}
199 preseed/file=*|file=*)
207 mount -n -o bind /sys /root/sys
208 mount -n -o bind /proc /root/proc
209 mount -n -o bind /dev /root/dev
211 mkdir -p /root/var/run/network
213 chroot /root wget -P /tmp "$location"
214 chroot /root ifdown -a
220 LOCATION="/tmp/$(basename "$location")"
226 PRESEEDS="${PRESEEDS}\"${question}=${value}\" "
237 TIMEZONE="${x#timezone=}"
252 UNIONTYPE="${x#union=}"
267 XVIDEOMODE="${x#xvideomode=}"
273 # sort of compatibility with netboot.h from linux docs
274 if [ -z "${NETBOOT}" ]
276 if [ "${ROOT}" = "/dev/nfs" ]
280 elif [ "${ROOT}" = "/dev/cifs" ]
287 if [ -z "${MODULE}" ]
293 if [ -z "${UNIONTYPE}" ]
304 if [ -d "${DIRECTORY}"/"${LIVE_MEDIA_PATH}" ]
306 for FILESYSTEM in squashfs ext2 ext3 xfs dir
308 if [ "`echo ${DIRECTORY}/${LIVE_MEDIA_PATH}/*.${FILESYSTEM}`" != "${DIRECTORY}/${LIVE_MEDIA_PATH}/*.${FILESYSTEM}" ]
318 get_backing_device() {
320 *.squashfs|*.ext2|*.ext3)
321 echo $(setup_loop "$1" "loop" "/sys/block/loop*" '0' "${LIVE_MEDIA_ENCRYPTION}")
327 panic "Unrecognized live filesystem: $1"
332 match_files_in_dir() {
333 # Does any files match pattern $1 ?
336 if [ "$(echo $pattern)" != "$pattern" ]; then
342 mount_images_in_directory() {
345 if match_files_in_dir "$directory/${LIVE_MEDIA_PATH}/*.squashfs" ||
346 match_files_in_dir "$directory/${LIVE_MEDIA_PATH}/*.ext2" ||
347 match_files_in_dir "$directory/${LIVE_MEDIA_PATH}/*.ext3" ||
348 match_files_in_dir "$directory/${LIVE_MEDIA_PATH}/*.dir"; then
349 setup_unionfs "$directory/${LIVE_MEDIA_PATH}" "$rootmnt"
356 sysfs_path="${1#/sys}"
357 if /lib/udev/path_id "${sysfs_path}" | grep -E -q "ID_PATH=(usb|pci-[^-]*-[ide|scsi|usb])"; then
364 # FIXME: do something better like the scan of supported filesystems
367 vfat|iso9660|udf|ext2|ext3|ntfs)
377 copyto="${copyfrom}_swap"
379 size=$(fs_size "" ${copyfrom} "used")
381 if [ "${copytodev}" = "ram" ]; then
383 freespace=$( expr $(awk '/MemFree/{print $2}' /proc/meminfo) + $( cat /proc/meminfo | grep Cached | head -n 1 | awk '/Cached/{print $2}' - ) )
384 mount_options="-o size=${size}k"
389 # it should be a writable block device
390 if [ -b "${copytodev}" ]; then
393 fstype=$(get_fstype "${dev}")
394 freespace=$(fs_size "${dev}")
396 [ "$quiet" != "y" ] && log_warning_msg "${copytodev} is not a block device."
400 if [ "${freespace}" -lt "${size}" ] ; then
401 [ "$quiet" != "y" ] && log_warning_msg "Not enough free ${free_string} (${freespace}k > ${size}k) to copy live media in ${copytodev}."
407 echo "mount -t ${fstype} ${mount_options} ${dev} ${copyto}"
408 mount -t "${fstype}" ${mount_options} "${dev}" "${copyto}"
409 cp -a ${copyfrom}/* ${copyto} # "cp -a" from busybox also copies hidden files
411 mount -r --move ${copyto} ${copyfrom}
419 modprobe "${MP_QUIET}" af_packet # For DHCP
424 ipconfig ${DEVICE} /tmp/net-${DEVICE}.conf | tee /netboot.config
426 if [ "${NFSROOT}" = "auto" ]; then
427 NFSROOT=${ROOTSERVER}:${ROOTPATH}
430 # source relevant ipconfig output
431 . /tmp/net-${DEVICE}.conf
434 if [ "${NFSROOT#*:}" = "$NFSROOT" ] && [ "$NETBOOT" != "cifs" ]; then
435 NFSROOT=${ROOTSERVER}:${NFSROOT}
438 [ "$quiet" != "y" ] && log_begin_msg "Trying netboot from ${NFSROOT}"
440 if [ "${NETBOOT}" != "nfs" ] && do_cifsmount ; then
442 elif do_nfsmount ; then
448 [ "$quiet" != "y" ] && log_end_msg
454 modprobe "${MP_QUIET}" nfs
455 if [ -z "${NFSOPTS}" ]; then
459 [ "$quiet" != "y" ] && log_begin_msg "Trying nfsmount -o nolock -o ro ${NFSOPTS} ${NFSROOT} ${mountpoint}"
460 # FIXME: This for loop is an ugly HACK round an nfs bug
461 for i in 0 1 2 3 4 5 6 7 8 9 a b c d e f 10 11 12 13; do
462 nfsmount -o nolock -o ro ${NFSOPTS} "${NFSROOT}" "${mountpoint}" && rc=0 && break
470 if [ -x "/sbin/mount.cifs" ]; then
471 if [ -z "${NFSOPTS}" ]; then
472 CIFSOPTS="-ouser=root,password="
474 CIFSOPTS="${NFSOPTS}"
477 [ "$quiet" != "y" ] && log_begin_msg "Trying mount.cifs ${NFSROOT} ${mountpoint} ${CIFSOPTS}"
478 modprobe "${MP_QUIET}" cifs
480 if mount.cifs "${NFSROOT}" "${mountpoint}" "${CIFSOPTS}" ; then
493 size=$(fs_size "${fromdev}" "" "used")
495 if [ -b "${fromdev}" ]; then
497 if [ -n "${HOMEMOUNTED}" -a "${snap_type}" = "HOME" ]; then
498 todev=$(cat /proc/mounts | grep -s " $(base_path ${todir}) " | awk '{print $1}' )
499 freespace=$(df -k | grep -s ${todev} | awk '{print $4}')
501 freespace=$( expr $(awk '/MemFree/{print $2}' /proc/meminfo) + $( cat /proc/meminfo | grep Cached | head -n 1 | awk '/Cached/{print $2}' - ))
504 tomount="/mnt/tmpsnap"
505 if [ ! -d "${tomount}" ] ; then
506 mkdir -p "${tomount}"
509 fstype=$(get_fstype "${fromdev}")
510 if [ -n "${fstype}" ]; then
512 mount -t "${fstype}" -o ro "${fromdev}" "${tomount}"
513 cp -a "${tomount}"/* ${todir}
516 log_warning_msg "Unrecognized fstype: ${fstype} on ${fromdev}:${snap_type}"
520 if echo ${fromdev} | grep -qs loop; then
521 losetup -d "${fromdev}"
526 [ "$quiet" != "y" ] && log_warning_msg "Unable to find the snapshot ${snap_type} medium"
532 # Look for $snap_label.* in block devices and copy the contents to $snap_mount
533 # and remember the device and filename for resync on exit in live-initramfs.init
539 snapdata=$(find_files "${snap_label}.squashfs ${snap_label}.cpio.gz ${snap_label}.ext2 ${snap_label}.ext3")
540 if [ ! -z "${snapdata}" ]; then
541 snapdev="$(echo ${snapdata} | cut -f1 -d ' ')"
542 snapback="$(echo ${snapdata} | cut -f2 -d ' ')"
543 snapfile="$(echo ${snapdata} | cut -f3 -d ' ')"
544 if echo "${snapfile}" | grep -qs '\(squashfs\|ext2\|ext3\)'; then
545 # squashfs or ext2/ext3 snapshot
546 dev=$(get_backing_device "${snapback}/${snapfile}")
547 if ! do_snap_copy "${dev}" "${snap_mount}" "${snap_type}"; then
548 log_warning_msg "Impossible to include the ${snapfile} Snapshot"
553 if ! (cd "${snap_mount}" && zcat "${snapback}/${snapfile}" | cpio -i -u -d 2>/dev/null) ; then
554 log_warning_msg "Impossible to include the ${snapfile} Snapshot"
560 dev=$(find_cow_device "${snap_label}")
561 if [ -b ${dev} ]; then
562 if echo "${dev}" | grep -qs loop; then
563 # strange things happens, user confused?
564 snaploop=$( losetup ${dev} | awk '{print $3}' | tr -d '()' )
565 snapfile=$(basename ${snaploop})
566 snapdev=$(cat /proc/mounts | awk '{print $2,$1}' | grep -es "^$( dirname ${snaploop} )" | cut -f2 -d ' ')
570 if ! do_snap_copy "${dev}" "${snap_mount}" "${snap_type}" ; then
571 log_warning_msg "Impossible to include the ${snap_label} Snapshot"
574 if [ -n "${snapfile}" ]; then
575 # it was a loop device, user confused
580 log_warning_msg "Impossible to include the ${snap_label} Snapshot"
584 echo "export ${snap_type}SNAP="${snap_mount}":${snapdev}:${snapfile}" >> /etc/live.conf # for resync on reboot/halt
592 modprobe "${MP_QUIET}" -b ${UNIONTYPE}
594 # run-init can't deal with images in a subdir, but we're going to
595 # move all of these away before it runs anyway. No, we're not,
596 # put them in / since move-mounting them into / breaks mono and
601 # Let's just mount the read-only file systems first
604 if [ "${NETBOOT}" = "nfs" ] ; then
605 roopt="nfsro" # go aroung a bug in nfs-unionfs locking
610 # Read image names from ${MODULE}.module if it exists
611 if [ -e "${image_directory}/filesystem.${MODULE}.module" ]
613 for IMAGE in `cat ${image_directory}/filesystem.${MODULE}.module`
615 image_string="${image_string} ${image_directory}/${image}"
617 elif [ -e "${image_directory}/${MODULE}.module" ]
619 for IMAGE in `cat ${image_directory}/${MODULE}.module`
621 image_string="${image_string} ${image_directory}/${image}"
624 # ${MODULE}.module does not exist, create a list of images
625 for FILESYSTEM in squashfs ext2 ext3 xfs dir
627 for IMAGE in "${image_directory}"/*."${FILESYSTEM}"
631 image_string="${image_string} ${IMAGE}"
637 image_string="`echo ${image_string} | sed -e 's/ /\n/g' | sort `"
641 for image in ${image_string}; do
642 imagename=$(basename "${image}")
643 if [ -d "${image}" ]; then
644 # it is a plain directory: do nothing
645 rofsstring="${image}=${roopt}:${rofsstring}"
646 rofslist="${image} ${rofslist}"
647 elif [ -f "${image}" ]; then
648 backdev=$(get_backing_device "$image")
649 fstype=$(get_fstype "${backdev}")
650 if [ "${fstype}" = "unknown" ]; then
651 panic "Unknown file system type on ${backdev} (${image})"
653 mkdir -p "${croot}/${imagename}"
654 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}"
657 rofsstring=${rofsstring%:}
663 # Looking for "${root_persistence}" device or file
664 if [ -n "${PERSISTENT}" ]; then
665 cowprobe=$(find_cow_device "${root_persistence}")
666 if [ -b "${cowprobe}" ]; then
667 cowdevice=${cowprobe}
668 cow_fstype=$(get_fstype "${cowprobe}")
670 [ "$quiet" != "y" ] && log_warning_msg "Unable to find the persistent medium"
674 mount ${cowdevice} -t ${cow_fstype} -o rw /cow || panic "Can not mount $cowdevice on /cow"
676 mount -t ${UNIONTYPE} -o dirs=/cow=rw:$rofsstring ${UNIONTYPE} "$rootmnt" || panic "${UNIONTYPE} mount failed"
678 # Adding other custom mounts
679 if [ -n "${PERSISTENT}" ]; then
680 # directly mount /home
681 # FIXME: add a custom mounts configurable system
682 homecow=$(find_cow_device "${home_persistence}" )
683 if [ -b "${homecow}" ]; then
684 mount -t $(get_fstype "${homecow}") -o rw "${homecow}" "${rootmnt}/home"
685 export HOMEMOUNTED=1 # used to proper calculate free space in do_snap_copy()
687 [ "$quiet" != "y" ] && log_warning_msg "Unable to find the persistent home medium"
689 # Look for other snapshots to copy in
690 try_snap "${root_snapshot_label}" "${rootmnt}" "ROOT"
691 try_snap "${home_snapshot_label}" "${rootmnt}/home" "HOME"
694 if [ -n "${SHOWMOUNTS}" ]; then
695 for d in ${rofslist}; do
696 mkdir -p "${rootmnt}/live/${d##*/}"
698 *.dir) # do nothing # mount -o bind "${d}" "${rootmnt}/live/${d##*/}"
700 *) mount --move "${d}" "${rootmnt}/live/${d##*/}"
706 # shows cow fs on /cow for use by live-snapshot
707 mkdir -p "${rootmnt}/live/cow"
708 mount -o bind /cow "${rootmnt}/live/cow"
715 if [ -z "${devname}" ]; then
716 devname=$(sys2dev "${sysdev}")
719 if [ -n "${LIVE_MEDIA_OFFSET}" ]; then
720 loopdevname=$(setup_loop "${devname}" "loop" "/sys/block/loop*" "${LIVE_MEDIA_OFFSET}" '')
721 devname="${loopdevname}"
724 fstype=$(get_fstype "${devname}")
725 if is_supported_fs ${fstype}; then
726 mount -t ${fstype} -o ro "${devname}" $mountpoint || continue
727 if is_live_path $mountpoint; then
735 if [ -n "${LIVE_MEDIA_OFFSET}" ]; then
736 losetup -d "${loopdevname}"
743 # first look at the one specified in the command line
744 if [ ! -z "${LIVE_MEDIA}" ]; then
745 if check_dev "null" "${LIVE_MEDIA}"; then
749 # don't start autodetection before timeout has expired
750 if [ -n "${LIVE_MEDIA_TIMEOUT}" ]; then
751 if [ "${timeout}" -lt "${LIVE_MEDIA_TIMEOUT}" ]; then
755 # or do the scan of block devices
756 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -v loop | grep -v ram); do
757 devname=$(sys2dev "${sysblock}")
758 fstype=$(get_fstype "${devname}")
759 if /lib/udev/cdrom_id ${devname} > /dev/null; then
760 if check_dev "null" "${devname}" ; then
763 elif is_nice_device "${sysblock}" ; then
764 for dev in $(subdevices "${sysblock}"); do
765 if check_dev "${dev}" ; then
769 elif [ "${fstype}" = "squashfs" -o \
770 "${fstype}" = "ext2" -o \
771 "${fstype}" = "ext3" ]; then
772 # This is an ugly hack situation, the block device has
773 # an image directly on it. It's hopefully
774 # live-initramfs, so take it and run with it.
775 ln -s "${devname}" "${devname}.${fstype}"
776 echo "${devname}.${fstype}"
784 if [ -x /sbin/usplash_write ]; then
785 /sbin/usplash_write "PULSATE"
789 set_usplash_timeout() {
790 if [ -x /sbin/usplash_write ]; then
791 /sbin/usplash_write "TIMEOUT 120"
804 [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/live-premount"
806 run_scripts /scripts/live-premount
807 [ "$quiet" != "y" ] && log_end_msg
809 # Needed here too because some things (*cough* udev *cough*)
810 # changes the timeout
814 if [ ! -z "${NETBOOT}" ]; then
815 if do_netmount ; then
816 livefs_root="${mountpoint}"
818 panic "Unable to find a live file system on the network"
821 # Scan local devices for the image
822 for i in 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19; do
823 livefs_root=$(find_livefs $i)
824 if [ -n "${livefs_root}" ]; then
831 if [ -z "${livefs_root}" ]; then
832 panic "Unable to find a medium containing a live file system"
835 if [ "${TORAM}" ]; then
837 elif [ "${TODISK}" ]; then
838 live_dest="${TODISK}"
840 if [ "${live_dest}" ]; then
841 log_begin_msg "Copying live media to ${live_dest}"
842 copy_live_to "${livefs_root}" "${live_dest}"
846 mount_images_in_directory "${livefs_root}" "${rootmnt}"
850 maybe_break live-bottom
851 [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/live-bottom"
854 run_scripts /scripts/live-bottom
855 [ "$quiet" != "y" ] && log_end_msg
859 cp live.log "${rootmnt}/var/log/"