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"
23 mkdir -p "${mountpoint}"
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 for ARGUMENT in `cat /proc/cmdline`
42 ACCESS="${ARGUMENT#access=}"
47 DEFCONSOLE="${ARGUMENT#*=}"
59 FETCH="${ARGUMENT#fetch=}"
64 HOSTNAME="${ARGUMENT#hostname=}"
66 export HOSTNAME LIVECONF
70 USERNAME="${ARGUMENT#username=}"
72 export USERNAME LIVECONF
76 USERFULLNAME="${ARGUMENT#userfullname=}"
78 export USERFULLNAME LIVECONF
82 STATICIP="${ARGUMENT#ip=}"
84 if [ -z "${STATICIP}" ]
92 keyb=*|kbd-chooser/method=*)
97 klayout=*|console-setup/layoutcode=*)
98 KLAYOUT="${ARGUMENT#*=}"
102 kvariant=*|console-setup/variantcode=*)
103 KVARIANT="${ARGUMENT#*=}"
107 kmodel=*|console-setup/modelcode=*)
108 KMODEL="${ARGUMENT#*=}"
113 KOPTIONS="${ARGUMENT#koptions=}"
122 live-media=*|bootfrom=*)
123 LIVE_MEDIA="${ARGUMENT#*=}"
127 live-media-encryption=*|encryption=*)
128 LIVE_MEDIA_ENCRYPTION="${ARGUMENT#*=}"
129 export LIVE_MEDIA_ENCRYPTION
133 LIVE_MEDIA_OFFSET="${ARGUMENT#live-media-offset=}"
134 export LIVE_MEDIA_OFFSET
138 LIVE_MEDIA_PATH="${ARGUMENT#live-media-path=}"
139 export LIVE_MEDIA_PATH
142 live-media-timeout=*)
143 LIVE_MEDIA_TIMEOUT="${ARGUMENT#live-media-timeout=}"
144 export LIVE_MEDIA_TIMEOUT
147 locale=*|debian-installer/locale=*)
148 LOCALE="${ARGUMENT#*=}"
153 MODULE="${ARGUMENT#module=}"
158 NETBOOT="${ARGUMENT#netboot=}"
163 NFSOPTS="${ARGUMENT#nfsopts=}"
202 preseed/file=*|file=*)
203 LOCATION="${ARGUMENT#*=}"
208 location="${ARGUMENT#url=}"
210 mount -n -o bind /sys /root/sys
211 mount -n -o bind /proc /root/proc
212 mount -n -o bind /dev /root/dev
214 mkdir -p /root/var/run/network
216 chroot /root wget -P /tmp "$location"
217 chroot /root ifdown -a
223 LOCATION="/tmp/$(basename "$location")"
227 question="${ARGUMENT%%=*}"
228 value="${ARGUMENT#*=}"
229 PRESEEDS="${PRESEEDS}\"${question}=${value}\" "
239 TIMEZONE="${ARGUMENT#timezone=}"
244 TODISK="${ARGUMENT#todisk=}"
254 UNIONTYPE="${ARGUMENT#union=}"
259 UTC="${ARGUMENT#utc=}"
269 XVIDEOMODE="${ARGUMENT#xvideomode=}"
275 # sort of compatibility with netboot.h from linux docs
276 if [ -z "${NETBOOT}" ]
278 if [ "${ROOT}" = "/dev/nfs" ]
282 elif [ "${ROOT}" = "/dev/cifs" ]
289 if [ -z "${MODULE}" ]
295 if [ -z "${UNIONTYPE}" ]
306 if [ -d "${DIRECTORY}"/"${LIVE_MEDIA_PATH}" ]
308 for FILESYSTEM in squashfs ext2 ext3 xfs dir
310 if [ "`echo ${DIRECTORY}/${LIVE_MEDIA_PATH}/*.${FILESYSTEM}`" != "${DIRECTORY}/${LIVE_MEDIA_PATH}/*.${FILESYSTEM}" ]
320 get_backing_device() {
322 *.squashfs|*.ext2|*.ext3)
323 echo $(setup_loop "$1" "loop" "/sys/block/loop*" '0' "${LIVE_MEDIA_ENCRYPTION}")
329 panic "Unrecognized live filesystem: $1"
334 match_files_in_dir() {
335 # Does any files match pattern $1 ?
338 if [ "$(echo $pattern)" != "$pattern" ]; then
344 mount_images_in_directory() {
348 if match_files_in_dir "$directory/${LIVE_MEDIA_PATH}/*.squashfs" ||
349 match_files_in_dir "$directory/${LIVE_MEDIA_PATH}/*.ext2" ||
350 match_files_in_dir "$directory/${LIVE_MEDIA_PATH}/*.ext3" ||
351 match_files_in_dir "$directory/${LIVE_MEDIA_PATH}/*.dir"; then
352 setup_unionfs "$directory/${LIVE_MEDIA_PATH}" "$rootmnt"
359 sysfs_path="${1#/sys}"
360 if /lib/udev/path_id "${sysfs_path}" | grep -E -q "ID_PATH=(usb|pci-[^-]*-[ide|scsi|usb])"; then
367 # FIXME: do something better like the scan of supported filesystems
370 vfat|iso9660|udf|ext2|ext3|ntfs)
380 copyto="${copyfrom}_swap"
382 size=$(fs_size "" ${copyfrom} "used")
384 if [ "${copytodev}" = "ram" ]; then
386 freespace=$( expr $(awk '/MemFree/{print $2}' /proc/meminfo) + $( cat /proc/meminfo | grep Cached | head -n 1 | awk '/Cached/{print $2}' - ) )
387 mount_options="-o size=${size}k"
392 # it should be a writable block device
393 if [ -b "${copytodev}" ]; then
396 fstype=$(get_fstype "${dev}")
397 freespace=$(fs_size "${dev}")
399 [ "$quiet" != "y" ] && log_warning_msg "${copytodev} is not a block device."
403 if [ "${freespace}" -lt "${size}" ] ; then
404 [ "$quiet" != "y" ] && log_warning_msg "Not enough free ${free_string} (${freespace}k > ${size}k) to copy live media in ${copytodev}."
408 # begin copying (or uncompressing)
410 echo "mount -t ${fstype} ${mount_options} ${dev} ${copyto}"
411 mount -t "${fstype}" ${mount_options} "${dev}" "${copyto}"
413 if [ "$extension" == "tgz" ]; then
415 tar zxf "${copyfrom}/${LIVE_MEDIA_PATH}/$(basename ${FETCH})"
416 rm -f "${copyfrom}/${LIVE_MEDIA_PATH}/$(basename ${FETCH})"
417 mount -r --move "${copyto}" "${rootmnt}"
420 cp -a ${copyfrom}/* ${copyto} # "cp -a" from busybox also copies hidden files
422 mount -r --move ${copyto} ${copyfrom}
431 modprobe "${MP_QUIET}" af_packet # For DHCP
436 ipconfig ${DEVICE} /tmp/net-${DEVICE}.conf | tee /netboot.config
438 if [ "${NFSROOT}" = "auto" ]; then
439 NFSROOT=${ROOTSERVER}:${ROOTPATH}
442 # source relevant ipconfig output
443 . /tmp/net-${DEVICE}.conf
446 if [ -n "${FETCH}" ] && do_httpmount; then
451 if [ "${NFSROOT#*:}" = "$NFSROOT" ] && [ "$NETBOOT" != "cifs" ]; then
452 NFSROOT=${ROOTSERVER}:${NFSROOT}
455 [ "$quiet" != "y" ] && log_begin_msg "Trying netboot from ${NFSROOT}"
457 if [ "${NETBOOT}" != "nfs" ] && do_cifsmount ; then
459 elif do_nfsmount ; then
465 [ "$quiet" != "y" ] && log_end_msg
471 extension=`echo "${FETCH}" | sed 's/\(.*\)\.\(.*\)/\2/'`
472 case "${extension}" in
474 [ "$quiet" != "y" ] && log_begin_msg "Trying wget ${FETCH} -O ${mountpoint}/$(basename ${FETCH})"
475 mkdir -p "${mountpoint}/${LIVE_MEDIA_PATH}"
476 wget "${FETCH}" -O "${mountpoint}/${LIVE_MEDIA_PATH}/$(basename ${FETCH})"
478 [ "${extension}" == "tgz" ] && live_dest="ram"
481 [ "$quiet" != "y" ] && log_begin_msg "Unrecognized archive extension for ${FETCH}"
488 modprobe "${MP_QUIET}" nfs
489 if [ -z "${NFSOPTS}" ]; then
493 [ "$quiet" != "y" ] && log_begin_msg "Trying nfsmount -o nolock -o ro ${NFSOPTS} ${NFSROOT} ${mountpoint}"
494 # FIXME: This for loop is an ugly HACK round an nfs bug
495 for i in 0 1 2 3 4 5 6 7 8 9 a b c d e f 10 11 12 13; do
496 nfsmount -o nolock -o ro ${NFSOPTS} "${NFSROOT}" "${mountpoint}" && rc=0 && break
504 if [ -x "/sbin/mount.cifs" ]; then
505 if [ -z "${NFSOPTS}" ]; then
506 CIFSOPTS="-ouser=root,password="
508 CIFSOPTS="${NFSOPTS}"
511 [ "$quiet" != "y" ] && log_begin_msg "Trying mount.cifs ${NFSROOT} ${mountpoint} ${CIFSOPTS}"
512 modprobe "${MP_QUIET}" cifs
514 if mount.cifs "${NFSROOT}" "${mountpoint}" "${CIFSOPTS}" ; then
527 size=$(fs_size "${fromdev}" "" "used")
529 if [ -b "${fromdev}" ]; then
531 if [ -n "${HOMEMOUNTED}" -a "${snap_type}" = "HOME" ]; then
532 todev=$(cat /proc/mounts | grep -s " $(base_path ${todir}) " | awk '{print $1}' )
533 freespace=$(df -k | grep -s ${todev} | awk '{print $4}')
535 freespace=$( expr $(awk '/MemFree/{print $2}' /proc/meminfo) + $( cat /proc/meminfo | grep Cached | head -n 1 | awk '/Cached/{print $2}' - ))
538 tomount="/mnt/tmpsnap"
539 if [ ! -d "${tomount}" ] ; then
540 mkdir -p "${tomount}"
543 fstype=$(get_fstype "${fromdev}")
544 if [ -n "${fstype}" ]; then
546 mount -t "${fstype}" -o ro "${fromdev}" "${tomount}"
547 cp -a "${tomount}"/* ${todir}
550 log_warning_msg "Unrecognized fstype: ${fstype} on ${fromdev}:${snap_type}"
554 if echo ${fromdev} | grep -qs loop; then
555 losetup -d "${fromdev}"
560 [ "$quiet" != "y" ] && log_warning_msg "Unable to find the snapshot ${snap_type} medium"
566 # Look for $snap_label.* in block devices and copy the contents to $snap_mount
567 # and remember the device and filename for resync on exit in live-initramfs.init
573 snapdata=$(find_files "${snap_label}.squashfs ${snap_label}.cpio.gz ${snap_label}.ext2 ${snap_label}.ext3")
574 if [ ! -z "${snapdata}" ]; then
575 snapdev="$(echo ${snapdata} | cut -f1 -d ' ')"
576 snapback="$(echo ${snapdata} | cut -f2 -d ' ')"
577 snapfile="$(echo ${snapdata} | cut -f3 -d ' ')"
578 if echo "${snapfile}" | grep -qs '\(squashfs\|ext2\|ext3\)'; then
579 # squashfs or ext2/ext3 snapshot
580 dev=$(get_backing_device "${snapback}/${snapfile}")
581 if ! do_snap_copy "${dev}" "${snap_mount}" "${snap_type}"; then
582 log_warning_msg "Impossible to include the ${snapfile} Snapshot"
587 if ! (cd "${snap_mount}" && zcat "${snapback}/${snapfile}" | cpio -i -u -d 2>/dev/null) ; then
588 log_warning_msg "Impossible to include the ${snapfile} Snapshot"
594 dev=$(find_cow_device "${snap_label}")
595 if [ -b ${dev} ]; then
596 if echo "${dev}" | grep -qs loop; then
597 # strange things happens, user confused?
598 snaploop=$( losetup ${dev} | awk '{print $3}' | tr -d '()' )
599 snapfile=$(basename ${snaploop})
600 snapdev=$(cat /proc/mounts | awk '{print $2,$1}' | grep -es "^$( dirname ${snaploop} )" | cut -f2 -d ' ')
604 if ! do_snap_copy "${dev}" "${snap_mount}" "${snap_type}" ; then
605 log_warning_msg "Impossible to include the ${snap_label} Snapshot"
608 if [ -n "${snapfile}" ]; then
609 # it was a loop device, user confused
614 log_warning_msg "Impossible to include the ${snap_label} Snapshot"
618 echo "export ${snap_type}SNAP="${snap_mount}":${snapdev}:${snapfile}" >> /etc/live.conf # for resync on reboot/halt
626 modprobe "${MP_QUIET}" -b ${UNIONTYPE}
628 # run-init can't deal with images in a subdir, but we're going to
629 # move all of these away before it runs anyway. No, we're not,
630 # put them in / since move-mounting them into / breaks mono and
635 # Let's just mount the read-only file systems first
638 if [ "${NETBOOT}" = "nfs" ] ; then
639 roopt="nfsro" # go aroung a bug in nfs-unionfs locking
644 # Read image names from ${MODULE}.module if it exists
645 if [ -e "${image_directory}/filesystem.${MODULE}.module" ]
647 for IMAGE in `cat ${image_directory}/filesystem.${MODULE}.module`
649 image_string="${image_string} ${image_directory}/${image}"
651 elif [ -e "${image_directory}/${MODULE}.module" ]
653 for IMAGE in `cat ${image_directory}/${MODULE}.module`
655 image_string="${image_string} ${image_directory}/${image}"
658 # ${MODULE}.module does not exist, create a list of images
659 for FILESYSTEM in squashfs ext2 ext3 xfs dir
661 for IMAGE in "${image_directory}"/*."${FILESYSTEM}"
665 image_string="${image_string} ${IMAGE}"
671 image_string="`echo ${image_string} | sed -e 's/ /\n/g' | sort `"
675 for image in ${image_string}; do
676 imagename=$(basename "${image}")
677 if [ -d "${image}" ]; then
678 # it is a plain directory: do nothing
679 rofsstring="${image}=${roopt}:${rofsstring}"
680 rofslist="${image} ${rofslist}"
681 elif [ -f "${image}" ]; then
682 backdev=$(get_backing_device "$image")
683 fstype=$(get_fstype "${backdev}")
684 if [ "${fstype}" = "unknown" ]; then
685 panic "Unknown file system type on ${backdev} (${image})"
687 mkdir -p "${croot}/${imagename}"
688 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}"
691 rofsstring=${rofsstring%:}
697 # Looking for "${root_persistence}" device or file
698 if [ -n "${PERSISTENT}" ]; then
699 cowprobe=$(find_cow_device "${root_persistence}")
700 if [ -b "${cowprobe}" ]; then
701 cowdevice=${cowprobe}
702 cow_fstype=$(get_fstype "${cowprobe}")
704 [ "$quiet" != "y" ] && log_warning_msg "Unable to find the persistent medium"
708 mount ${cowdevice} -t ${cow_fstype} -o rw /cow || panic "Can not mount $cowdevice on /cow"
710 mount -t ${UNIONTYPE} -o dirs=/cow=rw:$rofsstring ${UNIONTYPE} "$rootmnt" || panic "${UNIONTYPE} mount failed"
712 # Adding other custom mounts
713 if [ -n "${PERSISTENT}" ]; then
714 # directly mount /home
715 # FIXME: add a custom mounts configurable system
716 homecow=$(find_cow_device "${home_persistence}" )
717 if [ -b "${homecow}" ]; then
718 mount -t $(get_fstype "${homecow}") -o rw "${homecow}" "${rootmnt}/home"
719 export HOMEMOUNTED=1 # used to proper calculate free space in do_snap_copy()
721 [ "$quiet" != "y" ] && log_warning_msg "Unable to find the persistent home medium"
723 # Look for other snapshots to copy in
724 try_snap "${root_snapshot_label}" "${rootmnt}" "ROOT"
725 try_snap "${home_snapshot_label}" "${rootmnt}/home" "HOME"
728 if [ -n "${SHOWMOUNTS}" ]; then
729 for d in ${rofslist}; do
730 mkdir -p "${rootmnt}/live/${d##*/}"
732 *.dir) # do nothing # mount -o bind "${d}" "${rootmnt}/live/${d##*/}"
734 *) mount --move "${d}" "${rootmnt}/live/${d##*/}"
740 # shows cow fs on /cow for use by live-snapshot
741 mkdir -p "${rootmnt}/live/cow"
742 mount -o bind /cow "${rootmnt}/live/cow"
749 if [ -z "${devname}" ]; then
750 devname=$(sys2dev "${sysdev}")
753 if [ -n "${LIVE_MEDIA_OFFSET}" ]; then
754 loopdevname=$(setup_loop "${devname}" "loop" "/sys/block/loop*" "${LIVE_MEDIA_OFFSET}" '')
755 devname="${loopdevname}"
758 fstype=$(get_fstype "${devname}")
759 if is_supported_fs ${fstype}; then
760 mount -t ${fstype} -o ro "${devname}" $mountpoint || continue
761 if is_live_path $mountpoint; then
769 if [ -n "${LIVE_MEDIA_OFFSET}" ]; then
770 losetup -d "${loopdevname}"
777 # first look at the one specified in the command line
778 if [ ! -z "${LIVE_MEDIA}" ]; then
779 if check_dev "null" "${LIVE_MEDIA}"; then
783 # don't start autodetection before timeout has expired
784 if [ -n "${LIVE_MEDIA_TIMEOUT}" ]; then
785 if [ "${timeout}" -lt "${LIVE_MEDIA_TIMEOUT}" ]; then
789 # or do the scan of block devices
790 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -v loop | grep -v ram); do
791 devname=$(sys2dev "${sysblock}")
792 fstype=$(get_fstype "${devname}")
793 if /lib/udev/cdrom_id ${devname} > /dev/null; then
794 if check_dev "null" "${devname}" ; then
797 elif is_nice_device "${sysblock}" ; then
798 for dev in $(subdevices "${sysblock}"); do
799 if check_dev "${dev}" ; then
803 elif [ "${fstype}" = "squashfs" -o \
804 "${fstype}" = "ext2" -o \
805 "${fstype}" = "ext3" ]; then
806 # This is an ugly hack situation, the block device has
807 # an image directly on it. It's hopefully
808 # live-initramfs, so take it and run with it.
809 ln -s "${devname}" "${devname}.${fstype}"
810 echo "${devname}.${fstype}"
818 if [ -x /sbin/usplash_write ]; then
819 /sbin/usplash_write "PULSATE"
823 set_usplash_timeout() {
824 if [ -x /sbin/usplash_write ]; then
825 /sbin/usplash_write "TIMEOUT 120"
838 [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/live-premount"
840 run_scripts /scripts/live-premount
841 [ "$quiet" != "y" ] && log_end_msg
843 # Needed here too because some things (*cough* udev *cough*)
844 # changes the timeout
848 if [ ! -z "${NETBOOT}" ] || [ ! -z "${FETCH}" ]; then
849 if do_netmount ; then
850 livefs_root="${mountpoint}"
852 panic "Unable to find a live file system on the network"
855 # Scan local devices for the image
856 for i in 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19; do
857 livefs_root=$(find_livefs $i)
858 if [ -n "${livefs_root}" ]; then
865 if [ -z "${livefs_root}" ]; then
866 panic "Unable to find a medium containing a live file system"
869 if [ "${TORAM}" ]; then
871 elif [ "${TODISK}" ]; then
872 live_dest="${TODISK}"
874 if [ "${live_dest}" ]; then
875 log_begin_msg "Copying live media to ${live_dest}"
876 copy_live_to "${livefs_root}" "${live_dest}"
880 mount_images_in_directory "${livefs_root}" "${rootmnt}"
884 maybe_break live-bottom
885 [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/live-bottom"
888 run_scripts /scripts/live-bottom
889 [ "$quiet" != "y" ] && log_end_msg
893 cp live.log "${rootmnt}/var/log/"