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 ]
39 for ARGUMENT in $(cat /proc/cmdline)
43 ACCESS="${ARGUMENT#access=}"
48 DEFCONSOLE="${ARGUMENT#*=}"
60 FETCH="${ARGUMENT#fetch=}"
65 HOSTNAME="${ARGUMENT#hostname=}"
67 export HOSTNAME LIVECONF
71 USERNAME="${ARGUMENT#username=}"
73 export USERNAME LIVECONF
77 USERFULLNAME="${ARGUMENT#userfullname=}"
79 export USERFULLNAME LIVECONF
86 STATICIP="${ARGUMENT#ip=}"
88 if [ -z "${STATICIP}" ]
96 keyb=*|kbd-chooser/method=*)
101 klayout=*|console-setup/layoutcode=*)
102 KLAYOUT="${ARGUMENT#*=}"
106 kvariant=*|console-setup/variantcode=*)
107 KVARIANT="${ARGUMENT#*=}"
111 kmodel=*|console-setup/modelcode=*)
112 KMODEL="${ARGUMENT#*=}"
117 KOPTIONS="${ARGUMENT#koptions=}"
126 live-media=*|bootfrom=*)
127 LIVE_MEDIA="${ARGUMENT#*=}"
131 live-media-encryption=*|encryption=*)
132 LIVE_MEDIA_ENCRYPTION="${ARGUMENT#*=}"
133 export LIVE_MEDIA_ENCRYPTION
137 LIVE_MEDIA_OFFSET="${ARGUMENT#live-media-offset=}"
138 export LIVE_MEDIA_OFFSET
142 LIVE_MEDIA_PATH="${ARGUMENT#live-media-path=}"
143 export LIVE_MEDIA_PATH
146 live-media-timeout=*)
147 LIVE_MEDIA_TIMEOUT="${ARGUMENT#live-media-timeout=}"
148 export LIVE_MEDIA_TIMEOUT
151 locale=*|debian-installer/locale=*)
152 LOCALE="${ARGUMENT#*=}"
157 MODULE="${ARGUMENT#module=}"
162 NETBOOT="${ARGUMENT#netboot=}"
167 NFSOPTS="${ARGUMENT#nfsopts=}"
172 NOACCESSIBILITY="Yes"
173 export NOACCESSIBILITY
197 NOCONSOLEKEYBOARD="Yes"
198 export NOCONSOLEKEYBOARD
222 NOKPERSONALIZER="Yes"
223 export NOKPERSONALIZER
232 NOLANGUAGESELECTOR="Yes"
233 export NOLANGUAGESELECTOR
247 NOPOWERMANAGEMENT="Yes"
248 export NOPOWERMANAGEMENT
252 NOPROGRAMCRASHES="Yes"
253 export NOPROGRAMCRASHES
257 NORESTRICTEDMANAGER="Yes"
258 export NORESTRICTEDMANAGER
272 NOUPDATENOTIFIER="Yes"
273 export NOUPDATENOTIFIER
288 export NOXSCREENSAVER
301 preseed/file=*|file=*)
302 LOCATION="${ARGUMENT#*=}"
312 location="${ARGUMENT#url=}"
314 mount -n -o bind /sys /root/sys
315 mount -n -o bind /proc /root/proc
316 mount -n -o bind /dev /root/dev
318 mkdir -p /root/var/run/network
320 chroot /root wget -P /tmp "${location}"
321 chroot /root ifdown -a
327 LOCATION="/tmp/$(basename "${location}")"
331 question="${ARGUMENT%%=*}"
332 value="${ARGUMENT#*=}"
333 PRESEEDS="${PRESEEDS}\"${question}=${value}\" "
348 TIMEZONE="${ARGUMENT#timezone=}"
358 TODISK="${ARGUMENT#todisk=}"
369 MODULETORAM="${ARGUMENT#toram=}"
370 export TORAM MODULETORAM
374 UNIONTYPE="${ARGUMENT#union=}"
379 UTC="${ARGUMENT#utc=}"
389 XVIDEOMODE="${ARGUMENT#xvideomode=}"
395 # sort of compatibility with netboot.h from linux docs
396 if [ -z "${NETBOOT}" ]
398 if [ "${ROOT}" = "/dev/nfs" ]
402 elif [ "${ROOT}" = "/dev/cifs" ]
409 if [ -z "${MODULE}" ]
415 if [ -z "${UNIONTYPE}" ]
426 if [ -d "${DIRECTORY}"/"${LIVE_MEDIA_PATH}" ]
428 for FILESYSTEM in squashfs ext2 ext3 xfs dir
430 if [ "$(echo ${DIRECTORY}/${LIVE_MEDIA_PATH}/*.${FILESYSTEM})" != "${DIRECTORY}/${LIVE_MEDIA_PATH}/*.${FILESYSTEM}" ]
441 if [ "$IGNORE_UUID" ] || [ ! -e /conf/uuid.conf ]; then
445 uuid="$(cat /conf/uuid.conf)"
446 for try_uuid_file in "$mountpoint/.disk/casper-uuid"*; do
447 [ -e "$try_uuid_file" ] || continue
448 try_uuid="$(cat "$try_uuid_file")"
449 if [ "$uuid" = "$try_uuid" ]; then
456 get_backing_device ()
459 *.squashfs|*.ext2|*.ext3)
460 echo $(setup_loop "${1}" "loop" "/sys/block/loop*" '0' "${LIVE_MEDIA_ENCRYPTION}")
468 panic "Unrecognized live filesystem: ${1}"
473 match_files_in_dir ()
475 # Does any files match pattern ${1} ?
478 if [ "$(echo ${pattern})" != "${pattern}" ]
486 mount_images_in_directory ()
491 if match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.squashfs" ||
492 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.ext2" ||
493 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.ext3" ||
494 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.dir"
496 setup_unionfs "${directory}/${LIVE_MEDIA_PATH}" "${rootmnt}"
504 sysfs_path="${1#/sys}"
506 if /lib/udev/path_id "${sysfs_path}" | grep -E -q "ID_PATH=(usb|pci-[^-]*-[ide|scsi|usb])"
516 # FIXME: do something better like the scan of supported filesystems
520 vfat|iso9660|udf|ext2|ext3|ntfs)
532 copyto="${copyfrom}_swap"
534 if [ -z "${MODULETORAM}" ]
536 size=$(fs_size "" ${copyfrom} "used")
538 MODULETORAMFILE="${copyfrom}/${LIVE_MEDIA_PATH}/${MODULETORAM}"
540 if [ -f "${MODULETORAMFILE}" ]
542 size=$( expr $(ls -la ${MODULETORAMFILE} | awk '{print $5}') / 1024 + 5000 )
544 log_warning_msg "Error: toram-module ${MODULETORAM} (${MODULETORAMFILE}) could not be read."
549 if [ "${copytodev}" = "ram" ]
552 freespace=$( expr $(awk '/MemFree/{print $2}' /proc/meminfo) + $( cat /proc/meminfo | grep Cached | head -n 1 | awk '/Cached/{print $2}' - ) )
553 mount_options="-o size=${size}k"
558 # it should be a writable block device
559 if [ -b "${copytodev}" ]
563 fstype=$(get_fstype "${dev}")
564 freespace=$(fs_size "${dev}")
566 [ "$quiet" != "y" ] && log_warning_msg "${copytodev} is not a block device."
571 if [ "${freespace}" -lt "${size}" ]
573 [ "${quiet}" != "y" ] && log_warning_msg "Not enough free ${free_string} (${freespace}k free, ${size}k needed) to copy live media in ${copytodev}."
577 # begin copying (or uncompressing)
579 echo "mount -t ${fstype} ${mount_options} ${dev} ${copyto}"
580 mount -t "${fstype}" ${mount_options} "${dev}" "${copyto}"
582 if [ "${extension}" = "tgz" ]
585 tar zxf "${copyfrom}/${LIVE_MEDIA_PATH}/$(basename ${FETCH})"
586 rm -f "${copyfrom}/${LIVE_MEDIA_PATH}/$(basename ${FETCH})"
587 mount -r --move "${copyto}" "${rootmnt}"
590 if [ -n "${MODULETORAMFILE}" ]
592 cp ${MODULETORAMFILE} ${copyto} # copy only the filesystem module
594 cp -a ${copyfrom}/* ${copyto} # "cp -a" from busybox also copies hidden files
599 mount -r --move ${copyto} ${copyfrom}
610 modprobe "${MP_QUIET}" af_packet # For DHCP
615 ipconfig ${DEVICE} | tee /netboot.config
617 # source relevant ipconfig output
618 OLDHOSTNAME=${HOSTNAME}
619 . /tmp/net-${DEVICE}.conf
620 [ -z ${HOSTNAME} ] && HOSTNAME=${OLDHOSTNAME}
623 if [ "${NFSROOT}" = "auto" ]
625 NFSROOT=${ROOTSERVER}:${ROOTPATH}
628 if [ -n "${FETCH}" ] && do_httpmount
634 if [ "${NFSROOT#*:}" = "${NFSROOT}" ] && [ "$NETBOOT" != "cifs" ]
636 NFSROOT=${ROOTSERVER}:${NFSROOT}
639 [ "${quiet}" != "y" ] && log_begin_msg "Trying netboot from ${NFSROOT}"
641 if [ "${NETBOOT}" != "nfs" ] && do_cifsmount
651 [ "${quiet}" != "y" ] && log_end_msg
658 extension=$(echo "${FETCH}" | sed 's/\(.*\)\.\(.*\)/\2/')
660 case "${extension}" in
662 [ "${quiet}" != "y" ] && log_begin_msg "Trying wget ${FETCH} -O ${mountpoint}/$(basename ${FETCH})"
663 mkdir -p "${mountpoint}/${LIVE_MEDIA_PATH}"
664 wget "${FETCH}" -O "${mountpoint}/${LIVE_MEDIA_PATH}/$(basename ${FETCH})"
665 [ ${?} -eq 0 ] && rc=0
666 [ "${extension}" = "tgz" ] && live_dest="ram"
670 [ "${quiet}" != "y" ] && log_begin_msg "Unrecognized archive extension for ${FETCH}"
680 modprobe "${MP_QUIET}" nfs
682 if [ -z "${NFSOPTS}" ]
687 [ "${quiet}" != "y" ] && log_begin_msg "Trying nfsmount -o nolock -o ro ${NFSOPTS} ${NFSROOT} ${mountpoint}"
689 # FIXME: This for loop is an ugly HACK round an nfs bug
690 for i in 0 1 2 3 4 5 6 7 8 9 a b c d e f 10 11 12 13
692 nfsmount -o nolock -o ro ${NFSOPTS} "${NFSROOT}" "${mountpoint}" && rc=0 && break
703 if [ -x "/sbin/mount.cifs" ]
705 if [ -z "${NFSOPTS}" ]
707 CIFSOPTS="-ouser=root,password="
709 CIFSOPTS="${NFSOPTS}"
712 [ "${quiet}" != "y" ] && log_begin_msg "Trying mount.cifs ${NFSROOT} ${mountpoint} ${CIFSOPTS}"
713 modprobe "${MP_QUIET}" cifs
715 if mount.cifs "${NFSROOT}" "${mountpoint}" "${CIFSOPTS}"
729 size=$(fs_size "${fromdev}" "" "used")
731 if [ -b "${fromdev}" ]
734 if [ -n "${HOMEMOUNTED}" -a "${snap_type}" = "HOME" ]
736 todev=$(cat /proc/mounts | grep -s " $(base_path ${todir}) " | awk '{print $1}' )
737 freespace=$(df -k | grep -s ${todev} | awk '{print $4}')
739 freespace=$( expr $(awk '/MemFree/{print $2}' /proc/meminfo) + $( cat /proc/meminfo | grep Cached | head -n 1 | awk '/Cached/{print $2}' - ))
742 tomount="/mnt/tmpsnap"
744 if [ ! -d "${tomount}" ]
746 mkdir -p "${tomount}"
749 fstype=$(get_fstype "${fromdev}")
751 if [ -n "${fstype}" ]
754 mount -t "${fstype}" -o ro,noatime,nodiratime "${fromdev}" "${tomount}"
755 cp -a "${tomount}"/* ${todir}
758 log_warning_msg "Unrecognized fstype: ${fstype} on ${fromdev}:${snap_type}"
763 if echo ${fromdev} | grep -qs loop
765 losetup -d "${fromdev}"
772 [ "${quiet}" != "y" ] && log_warning_msg "Unable to find the snapshot ${snap_type} medium"
778 # Look for ${snap_label}.* in block devices and copy the contents to ${snap_mount}
779 # and remember the device and filename for resync on exit in live-initramfs.init
784 snapdata=$(find_files "${snap_label}.squashfs ${snap_label}.cpio.gz ${snap_label}.ext2 ${snap_label}.ext3")
786 if [ ! -z "${snapdata}" ]
788 snapdev="$(echo ${snapdata} | cut -f1 -d ' ')"
789 snapback="$(echo ${snapdata} | cut -f2 -d ' ')"
790 snapfile="$(echo ${snapdata} | cut -f3 -d ' ')"
792 if echo "${snapfile}" | grep -qs '\(squashfs\|ext2\|ext3\)'
794 # squashfs or ext2/ext3 snapshot
795 dev=$(get_backing_device "${snapback}/${snapfile}")
797 if ! do_snap_copy "${dev}" "${snap_mount}" "${snap_type}"
799 log_warning_msg "Impossible to include the ${snapfile} Snapshot"
804 if ! (cd "${snap_mount}" && zcat "${snapback}/${snapfile}" | cpio -i -u -d 2>/dev/null)
806 log_warning_msg "Impossible to include the ${snapfile} Snapshot"
813 dev=$(find_cow_device "${snap_label}")
817 if echo "${dev}" | grep -qs loop
819 # strange things happens, user confused?
820 snaploop=$( losetup ${dev} | awk '{print $3}' | tr -d '()' )
821 snapfile=$(basename ${snaploop})
822 snapdev=$(cat /proc/mounts | awk '{print $2,$1}' | grep -es "^$( dirname ${snaploop} )" | cut -f2 -d ' ')
827 if ! do_snap_copy "${dev}" "${snap_mount}" "${snap_type}"
829 log_warning_msg "Impossible to include the ${snap_label} Snapshot"
832 if [ -n "${snapfile}" ]
834 # it was a loop device, user confused
839 log_warning_msg "Impossible to include the ${snap_label} Snapshot"
844 echo "export ${snap_type}SNAP="${snap_mount}":${snapdev}:${snapfile}" >> /etc/live.conf # for resync on reboot/halt
850 image_directory="${1}"
853 modprobe "${MP_QUIET}" -b ${UNIONTYPE}
855 # run-init can't deal with images in a subdir, but we're going to
856 # move all of these away before it runs anyway. No, we're not,
857 # put them in / since move-mounting them into / breaks mono and
862 # Let's just mount the read-only file systems first
865 minor_kernel_version=$(uname -r|cut -c 5-|sed 's/[^0-9].*//')
867 if [ "${NETBOOT}" = "nfs" ] && [ "${minor_kernel_version}" -lt 22 ]
869 # go aroung a bug in nfs-unionfs locking for unionfs <= 1.4
875 # Read image names from ${MODULE}.module if it exists
876 if [ -e "${image_directory}/filesystem.${MODULE}.module" ]
878 for IMAGE in $(cat ${image_directory}/filesystem.${MODULE}.module)
880 image_string="${image_string} ${image_directory}/${IMAGE}"
882 elif [ -e "${image_directory}/${MODULE}.module" ]
884 for IMAGE in $(cat ${image_directory}/${MODULE}.module)
886 image_string="${image_string} ${image_directory}/${IMAGE}"
889 # ${MODULE}.module does not exist, create a list of images
890 for FILESYSTEM in squashfs ext2 ext3 xfs dir
892 for IMAGE in "${image_directory}"/*."${FILESYSTEM}"
896 image_string="${image_string} ${IMAGE}"
902 image_string="$(echo ${image_string} | sed -e 's/ /\n/g' | sort )"
905 [ -n "${MODULETORAMFILE}" ] && image_string="${image_directory}/$(basename ${MODULETORAMFILE})"
909 for image in ${image_string}
911 imagename=$(basename "${image}")
915 # it is a plain directory: do nothing
916 rofsstring="${image}=${roopt}:${rofsstring}"
917 rofslist="${image} ${rofslist}"
918 elif [ -f "${image}" ]
920 backdev=$(get_backing_device "${image}")
921 fstype=$(get_fstype "${backdev}")
923 if [ "${fstype}" = "unknown" ]
925 panic "Unknown file system type on ${backdev} (${image})"
928 mkdir -p "${croot}/${imagename}"
929 echo "debug: Can not mount backdev ${backdev} (image = ${image}) on croot/imagename ${croot}/${imagename}"
930 mount -t "${fstype}" -o ro,noatime,nodiratime "${backdev}" "${croot}/${imagename}" || panic "Can not mount ${backdev} (${image}) on ${croot}/${imagename}" && rofsstring="${croot}/${imagename}=${roopt}:${rofsstring}" && rofslist="${croot}/${imagename} ${rofslist}"
934 rofsstring=${rofsstring%:}
940 # Looking for "${root_persistence}" device or file
941 if [ -n "${PERSISTENT}" ]
943 cowprobe=$(find_cow_device "${root_persistence}")
945 if [ -b "${cowprobe}" ]
947 cowdevice=${cowprobe}
948 cow_fstype=$(get_fstype "${cowprobe}")
950 [ "${quiet}" != "y" ] && log_warning_msg "Unable to find the persistent medium"
954 mount ${cowdevice} -t ${cow_fstype} -o rw,noatime,nodiratime /cow || panic "Can not mount ${cowdevice} on /cow"
956 mount -t ${UNIONTYPE} -o noatime,nodiratime,dirs=/cow=rw:${rofsstring} ${UNIONTYPE} "${rootmnt}" || panic "${UNIONTYPE} mount failed"
958 # Adding other custom mounts
959 if [ -n "${PERSISTENT}" ]
961 # directly mount /home
962 # FIXME: add a custom mounts configurable system
963 homecow=$(find_cow_device "${home_persistence}" )
965 if [ -b "${homecow}" ]
967 mount -t $(get_fstype "${homecow}") -o rw,noatime,nodiratime "${homecow}" "${rootmnt}/home"
968 export HOMEMOUNTED=1 # used to proper calculate free space in do_snap_copy()
970 [ "${quiet}" != "y" ] && log_warning_msg "Unable to find the persistent home medium"
973 # Look for other snapshots to copy in
974 try_snap "${root_snapshot_label}" "${rootmnt}" "ROOT"
975 try_snap "${home_snapshot_label}" "${rootmnt}/home" "HOME"
978 if [ -n "${SHOWMOUNTS}" ]
982 mkdir -p "${rootmnt}/live/${d##*/}"
986 # do nothing # mount -o bind "${d}" "${rootmnt}/live/${d##*/}"
990 mount --move "${d}" "${rootmnt}/live/${d##*/}"
996 # shows cow fs on /cow for use by live-snapshot
997 mkdir -p "${rootmnt}/live/cow"
998 mount -o move /cow "${rootmnt}/live/cow"
1005 skip_uuid_check="${3}"
1007 if [ -z "${devname}" ]
1009 devname=$(sys2dev "${sysdev}")
1012 if [ -n "${LIVE_MEDIA_OFFSET}" ]
1014 loopdevname=$(setup_loop "${devname}" "loop" "/sys/block/loop*" "${LIVE_MEDIA_OFFSET}" '')
1015 devname="${loopdevname}"
1018 fstype=$(get_fstype "${devname}")
1020 if is_supported_fs ${fstype}
1022 mount -t ${fstype} -o ro,noatime,nodiratime "${devname}" ${mountpoint} || continue
1024 if is_live_path ${mountpoint}
1025 if is_live_path $mountpoint && \
1026 ([ "$skip_uuid_check" ] || matches_uuid $mountpoint); then
1030 umount ${mountpoint}
1034 if [ -n "${LIVE_MEDIA_OFFSET}" ]
1036 losetup -d "${loopdevname}"
1046 # first look at the one specified in the command line
1047 if [ ! -z "${LIVE_MEDIA}" ]
1049 if check_dev "null" "${LIVE_MEDIA}" "skip_uuid_check"
1055 # don't start autodetection before timeout has expired
1056 if [ -n "${LIVE_MEDIA_TIMEOUT}" ]
1058 if [ "${timeout}" -lt "${LIVE_MEDIA_TIMEOUT}" ]
1064 # or do the scan of block devices
1065 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -v loop | grep -v ram)
1067 devname=$(sys2dev "${sysblock}")
1068 fstype=$(get_fstype "${devname}")
1070 if /lib/udev/cdrom_id ${devname} > /dev/null
1072 if check_dev "null" "${devname}"
1076 elif is_nice_device "${sysblock}"
1078 for dev in $(subdevices "${sysblock}")
1080 if check_dev "${dev}"
1085 elif [ "${fstype}" = "squashfs" -o \
1086 "${fstype}" = "ext2" -o \
1087 "${fstype}" = "ext3" ]
1089 # This is an ugly hack situation, the block device has
1090 # an image directly on it. It's hopefully
1091 # live-initramfs, so take it and run with it.
1092 ln -s "${devname}" "${devname}.${fstype}"
1093 echo "${devname}.${fstype}"
1103 if [ -x /sbin/usplash_write ]
1105 /sbin/usplash_write "PULSATE"
1109 set_usplash_timeout ()
1111 if [ -x /sbin/usplash_write ]
1113 /sbin/usplash_write "TIMEOUT 120"
1127 [ "${quiet}" != "y" ] && log_begin_msg "Running /scripts/live-premount"
1129 run_scripts /scripts/live-premount
1130 [ "${quiet}" != "y" ] && log_end_msg
1132 # Needed here too because some things (*cough* udev *cough*)
1133 # changes the timeout
1137 if [ ! -z "${NETBOOT}" ] || [ ! -z "${FETCH}" ]
1141 livefs_root="${mountpoint}"
1143 panic "Unable to find a live file system on the network"
1146 # Scan local devices for the image
1147 for i in 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
1149 livefs_root=$(find_livefs ${i})
1151 if [ -n "${livefs_root}" ]
1160 if [ -z "${livefs_root}" ]
1162 panic "Unable to find a medium containing a live file system"
1168 elif [ "${TODISK}" ]
1170 live_dest="${TODISK}"
1173 if [ "${live_dest}" ]
1175 log_begin_msg "Copying live media to ${live_dest}"
1176 copy_live_to "${livefs_root}" "${live_dest}"
1180 if [ -n "${MODULETORAMFILE}" ]
1182 setup_unionfs "${livefs_root}" "${rootmnt}"
1184 mount_images_in_directory "${livefs_root}" "${rootmnt}"
1189 maybe_break live-bottom
1190 [ "${quiet}" != "y" ] && log_begin_msg "Running /scripts/live-bottom"
1193 run_scripts /scripts/live-bottom
1194 [ "${quiet}" != "y" ] && log_end_msg
1198 cp live.log "${rootmnt}/var/log/"