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
88 STATICIP="${ARGUMENT#ip=}"
90 if [ -z "${STATICIP}" ]
98 keyb=*|kbd-chooser/method=*)
103 klayout=*|console-setup/layoutcode=*)
104 KLAYOUT="${ARGUMENT#*=}"
108 kvariant=*|console-setup/variantcode=*)
109 KVARIANT="${ARGUMENT#*=}"
113 kmodel=*|console-setup/modelcode=*)
114 KMODEL="${ARGUMENT#*=}"
119 KOPTIONS="${ARGUMENT#koptions=}"
128 live-media=*|bootfrom=*)
129 LIVE_MEDIA="${ARGUMENT#*=}"
133 live-media-encryption=*|encryption=*)
134 LIVE_MEDIA_ENCRYPTION="${ARGUMENT#*=}"
135 export LIVE_MEDIA_ENCRYPTION
139 LIVE_MEDIA_OFFSET="${ARGUMENT#live-media-offset=}"
140 export LIVE_MEDIA_OFFSET
144 LIVE_MEDIA_PATH="${ARGUMENT#live-media-path=}"
145 export LIVE_MEDIA_PATH
148 live-media-timeout=*)
149 LIVE_MEDIA_TIMEOUT="${ARGUMENT#live-media-timeout=}"
150 export LIVE_MEDIA_TIMEOUT
153 locale=*|debian-installer/locale=*)
154 LOCALE="${ARGUMENT#*=}"
159 MODULE="${ARGUMENT#module=}"
164 NETBOOT="${ARGUMENT#netboot=}"
169 NFSOPTS="${ARGUMENT#nfsopts=}"
174 NOACCESSIBILITY="Yes"
175 export NOACCESSIBILITY
199 NOCONSOLEKEYBOARD="Yes"
200 export NOCONSOLEKEYBOARD
224 NOKPERSONALIZER="Yes"
225 export NOKPERSONALIZER
234 NOLANGUAGESELECTOR="Yes"
235 export NOLANGUAGESELECTOR
249 NOPOWERMANAGEMENT="Yes"
250 export NOPOWERMANAGEMENT
254 NOPROGRAMCRASHES="Yes"
255 export NOPROGRAMCRASHES
259 NORESTRICTEDMANAGER="Yes"
260 export NORESTRICTEDMANAGER
274 NOUPDATENOTIFIER="Yes"
275 export NOUPDATENOTIFIER
290 export NOXSCREENSAVER
303 preseed/file=*|file=*)
304 LOCATION="${ARGUMENT#*=}"
314 location="${ARGUMENT#url=}"
316 mount -n -o bind /sys /root/sys
317 mount -n -o bind /proc /root/proc
318 mount -n -o bind /dev /root/dev
320 mkdir -p /root/var/run/network
322 chroot /root wget -P /tmp "${location}"
323 chroot /root ifdown -a
329 LOCATION="/tmp/$(basename "${location}")"
333 question="${ARGUMENT%%=*}"
334 value="${ARGUMENT#*=}"
335 PRESEEDS="${PRESEEDS}\"${question}=${value}\" "
350 TIMEZONE="${ARGUMENT#timezone=}"
360 TODISK="${ARGUMENT#todisk=}"
371 MODULETORAM="${ARGUMENT#toram=}"
372 export TORAM MODULETORAM
376 UNIONTYPE="${ARGUMENT#union=}"
381 UTC="${ARGUMENT#utc=}"
391 XVIDEOMODE="${ARGUMENT#xvideomode=}"
397 # sort of compatibility with netboot.h from linux docs
398 if [ -z "${NETBOOT}" ]
400 if [ "${ROOT}" = "/dev/nfs" ]
404 elif [ "${ROOT}" = "/dev/cifs" ]
411 if [ -z "${MODULE}" ]
417 if [ -z "${UNIONTYPE}" ]
428 if [ -d "${DIRECTORY}"/"${LIVE_MEDIA_PATH}" ]
430 for FILESYSTEM in squashfs ext2 ext3 xfs dir
432 if [ "$(echo ${DIRECTORY}/${LIVE_MEDIA_PATH}/*.${FILESYSTEM})" != "${DIRECTORY}/${LIVE_MEDIA_PATH}/*.${FILESYSTEM}" ]
444 if [ "${IGNORE_UUID}" ] || [ ! -e /conf/uuid.conf ]
450 uuid="$(cat /conf/uuid.conf)"
452 for try_uuid_file in "${mountpoint}/.disk/casper-uuid"*
454 [ -e "${try_uuid_file}" ] || continue
456 try_uuid="$(cat "${try_uuid_file}")"
458 if [ "${uuid}" = "${try_uuid}" ]
467 get_backing_device ()
470 *.squashfs|*.ext2|*.ext3)
471 echo $(setup_loop "${1}" "loop" "/sys/block/loop*" '0' "${LIVE_MEDIA_ENCRYPTION}")
479 panic "Unrecognized live filesystem: ${1}"
484 match_files_in_dir ()
486 # Does any files match pattern ${1} ?
489 if [ "$(echo ${pattern})" != "${pattern}" ]
497 mount_images_in_directory ()
502 if match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.squashfs" ||
503 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.ext2" ||
504 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.ext3" ||
505 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.dir"
507 setup_unionfs "${directory}/${LIVE_MEDIA_PATH}" "${rootmnt}"
515 sysfs_path="${1#/sys}"
517 if /lib/udev/path_id "${sysfs_path}" | grep -E -q "ID_PATH=(usb|pci-[^-]*-[ide|scsi|usb])"
527 # FIXME: do something better like the scan of supported filesystems
531 vfat|iso9660|udf|ext2|ext3|ntfs)
543 copyto="${copyfrom}_swap"
545 if [ -z "${MODULETORAM}" ]
547 size=$(fs_size "" ${copyfrom} "used")
549 MODULETORAMFILE="${copyfrom}/${LIVE_MEDIA_PATH}/${MODULETORAM}"
551 if [ -f "${MODULETORAMFILE}" ]
553 size=$( expr $(ls -la ${MODULETORAMFILE} | awk '{print $5}') / 1024 + 5000 )
555 log_warning_msg "Error: toram-module ${MODULETORAM} (${MODULETORAMFILE}) could not be read."
560 if [ "${copytodev}" = "ram" ]
563 freespace=$( expr $(awk '/MemFree/{print $2}' /proc/meminfo) + $( cat /proc/meminfo | grep Cached | head -n 1 | awk '/Cached/{print $2}' - ) )
564 mount_options="-o size=${size}k"
569 # it should be a writable block device
570 if [ -b "${copytodev}" ]
574 fstype=$(get_fstype "${dev}")
575 freespace=$(fs_size "${dev}")
577 [ "$quiet" != "y" ] && log_warning_msg "${copytodev} is not a block device."
582 if [ "${freespace}" -lt "${size}" ]
584 [ "${quiet}" != "y" ] && log_warning_msg "Not enough free ${free_string} (${freespace}k free, ${size}k needed) to copy live media in ${copytodev}."
588 # begin copying (or uncompressing)
590 echo "mount -t ${fstype} ${mount_options} ${dev} ${copyto}"
591 mount -t "${fstype}" ${mount_options} "${dev}" "${copyto}"
593 if [ "${extension}" = "tgz" ]
596 tar zxf "${copyfrom}/${LIVE_MEDIA_PATH}/$(basename ${FETCH})"
597 rm -f "${copyfrom}/${LIVE_MEDIA_PATH}/$(basename ${FETCH})"
598 mount -r --move "${copyto}" "${rootmnt}"
601 if [ -n "${MODULETORAMFILE}" ]
603 cp ${MODULETORAMFILE} ${copyto} # copy only the filesystem module
605 cp -a ${copyfrom}/* ${copyto} # "cp -a" from busybox also copies hidden files
610 mount -r --move ${copyto} ${copyfrom}
621 modprobe "${MP_QUIET}" af_packet # For DHCP
626 ipconfig ${DEVICE} | tee /netboot.config
628 # source relevant ipconfig output
629 OLDHOSTNAME=${HOSTNAME}
630 . /tmp/net-${DEVICE}.conf
631 [ -z ${HOSTNAME} ] && HOSTNAME=${OLDHOSTNAME}
634 if [ "${NFSROOT}" = "auto" ]
636 NFSROOT=${ROOTSERVER}:${ROOTPATH}
639 if [ -n "${FETCH}" ] && do_httpmount
645 if [ "${NFSROOT#*:}" = "${NFSROOT}" ] && [ "$NETBOOT" != "cifs" ]
647 NFSROOT=${ROOTSERVER}:${NFSROOT}
650 [ "${quiet}" != "y" ] && log_begin_msg "Trying netboot from ${NFSROOT}"
652 if [ "${NETBOOT}" != "nfs" ] && do_cifsmount
662 [ "${quiet}" != "y" ] && log_end_msg
669 extension=$(echo "${FETCH}" | sed 's/\(.*\)\.\(.*\)/\2/')
671 case "${extension}" in
673 [ "${quiet}" != "y" ] && log_begin_msg "Trying wget ${FETCH} -O ${mountpoint}/$(basename ${FETCH})"
674 mkdir -p "${mountpoint}/${LIVE_MEDIA_PATH}"
675 wget "${FETCH}" -O "${mountpoint}/${LIVE_MEDIA_PATH}/$(basename ${FETCH})"
676 [ ${?} -eq 0 ] && rc=0
677 [ "${extension}" = "tgz" ] && live_dest="ram"
681 [ "${quiet}" != "y" ] && log_begin_msg "Unrecognized archive extension for ${FETCH}"
691 modprobe "${MP_QUIET}" nfs
693 if [ -z "${NFSOPTS}" ]
698 [ "${quiet}" != "y" ] && log_begin_msg "Trying nfsmount -o nolock -o ro ${NFSOPTS} ${NFSROOT} ${mountpoint}"
700 # FIXME: This for loop is an ugly HACK round an nfs bug
701 for i in 0 1 2 3 4 5 6 7 8 9 a b c d e f 10 11 12 13
703 nfsmount -o nolock -o ro ${NFSOPTS} "${NFSROOT}" "${mountpoint}" && rc=0 && break
714 if [ -x "/sbin/mount.cifs" ]
716 if [ -z "${NFSOPTS}" ]
718 CIFSOPTS="-ouser=root,password="
720 CIFSOPTS="${NFSOPTS}"
723 [ "${quiet}" != "y" ] && log_begin_msg "Trying mount.cifs ${NFSROOT} ${mountpoint} ${CIFSOPTS}"
724 modprobe "${MP_QUIET}" cifs
726 if mount.cifs "${NFSROOT}" "${mountpoint}" "${CIFSOPTS}"
740 size=$(fs_size "${fromdev}" "" "used")
742 if [ -b "${fromdev}" ]
745 if [ -n "${HOMEMOUNTED}" -a "${snap_type}" = "HOME" ]
747 todev=$(cat /proc/mounts | grep -s " $(base_path ${todir}) " | awk '{print $1}' )
748 freespace=$(df -k | grep -s ${todev} | awk '{print $4}')
750 freespace=$( expr $(awk '/MemFree/{print $2}' /proc/meminfo) + $( cat /proc/meminfo | grep Cached | head -n 1 | awk '/Cached/{print $2}' - ))
753 tomount="/mnt/tmpsnap"
755 if [ ! -d "${tomount}" ]
757 mkdir -p "${tomount}"
760 fstype=$(get_fstype "${fromdev}")
762 if [ -n "${fstype}" ]
765 mount -t "${fstype}" -o ro,noatime,nodiratime "${fromdev}" "${tomount}"
766 cp -a "${tomount}"/* ${todir}
769 log_warning_msg "Unrecognized fstype: ${fstype} on ${fromdev}:${snap_type}"
774 if echo ${fromdev} | grep -qs loop
776 losetup -d "${fromdev}"
783 [ "${quiet}" != "y" ] && log_warning_msg "Unable to find the snapshot ${snap_type} medium"
789 # Look for ${snap_label}.* in block devices and copy the contents to ${snap_mount}
790 # and remember the device and filename for resync on exit in live-initramfs.init
795 snapdata=$(find_files "${snap_label}.squashfs ${snap_label}.cpio.gz ${snap_label}.ext2 ${snap_label}.ext3")
797 if [ ! -z "${snapdata}" ]
799 snapdev="$(echo ${snapdata} | cut -f1 -d ' ')"
800 snapback="$(echo ${snapdata} | cut -f2 -d ' ')"
801 snapfile="$(echo ${snapdata} | cut -f3 -d ' ')"
803 if echo "${snapfile}" | grep -qs '\(squashfs\|ext2\|ext3\)'
805 # squashfs or ext2/ext3 snapshot
806 dev=$(get_backing_device "${snapback}/${snapfile}")
808 if ! do_snap_copy "${dev}" "${snap_mount}" "${snap_type}"
810 log_warning_msg "Impossible to include the ${snapfile} Snapshot"
815 if ! (cd "${snap_mount}" && zcat "${snapback}/${snapfile}" | cpio -i -u -d 2>/dev/null)
817 log_warning_msg "Impossible to include the ${snapfile} Snapshot"
824 dev=$(find_cow_device "${snap_label}")
828 if echo "${dev}" | grep -qs loop
830 # strange things happens, user confused?
831 snaploop=$( losetup ${dev} | awk '{print $3}' | tr -d '()' )
832 snapfile=$(basename ${snaploop})
833 snapdev=$(cat /proc/mounts | awk '{print $2,$1}' | grep -es "^$( dirname ${snaploop} )" | cut -f2 -d ' ')
838 if ! do_snap_copy "${dev}" "${snap_mount}" "${snap_type}"
840 log_warning_msg "Impossible to include the ${snap_label} Snapshot"
843 if [ -n "${snapfile}" ]
845 # it was a loop device, user confused
850 log_warning_msg "Impossible to include the ${snap_label} Snapshot"
855 echo "export ${snap_type}SNAP="${snap_mount}":${snapdev}:${snapfile}" >> /etc/live.conf # for resync on reboot/halt
861 image_directory="${1}"
864 modprobe "${MP_QUIET}" -b ${UNIONTYPE}
866 # run-init can't deal with images in a subdir, but we're going to
867 # move all of these away before it runs anyway. No, we're not,
868 # put them in / since move-mounting them into / breaks mono and
873 # Let's just mount the read-only file systems first
876 minor_kernel_version=$(uname -r|cut -c 5-|sed 's/[^0-9].*//')
878 if [ "${NETBOOT}" = "nfs" ] && [ "${minor_kernel_version}" -lt 22 ]
880 # go aroung a bug in nfs-unionfs locking for unionfs <= 1.4
886 # Read image names from ${MODULE}.module if it exists
887 if [ -e "${image_directory}/filesystem.${MODULE}.module" ]
889 for IMAGE in $(cat ${image_directory}/filesystem.${MODULE}.module)
891 image_string="${image_string} ${image_directory}/${IMAGE}"
893 elif [ -e "${image_directory}/${MODULE}.module" ]
895 for IMAGE in $(cat ${image_directory}/${MODULE}.module)
897 image_string="${image_string} ${image_directory}/${IMAGE}"
900 # ${MODULE}.module does not exist, create a list of images
901 for FILESYSTEM in squashfs ext2 ext3 xfs dir
903 for IMAGE in "${image_directory}"/*."${FILESYSTEM}"
907 image_string="${image_string} ${IMAGE}"
913 image_string="$(echo ${image_string} | sed -e 's/ /\n/g' | sort )"
916 [ -n "${MODULETORAMFILE}" ] && image_string="${image_directory}/$(basename ${MODULETORAMFILE})"
920 for image in ${image_string}
922 imagename=$(basename "${image}")
926 # it is a plain directory: do nothing
927 rofsstring="${image}=${roopt}:${rofsstring}"
928 rofslist="${image} ${rofslist}"
929 elif [ -f "${image}" ]
931 backdev=$(get_backing_device "${image}")
932 fstype=$(get_fstype "${backdev}")
934 if [ "${fstype}" = "unknown" ]
936 panic "Unknown file system type on ${backdev} (${image})"
939 mkdir -p "${croot}/${imagename}"
940 echo "debug: Can not mount backdev ${backdev} (image = ${image}) on croot/imagename ${croot}/${imagename}"
941 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}"
945 rofsstring=${rofsstring%:}
951 # Looking for "${root_persistence}" device or file
952 if [ -n "${PERSISTENT}" ]
954 cowprobe=$(find_cow_device "${root_persistence}")
956 if [ -b "${cowprobe}" ]
958 cowdevice=${cowprobe}
959 cow_fstype=$(get_fstype "${cowprobe}")
961 [ "${quiet}" != "y" ] && log_warning_msg "Unable to find the persistent medium"
965 mount ${cowdevice} -t ${cow_fstype} -o rw,noatime,nodiratime /cow || panic "Can not mount ${cowdevice} on /cow"
967 mount -t ${UNIONTYPE} -o noatime,nodiratime,dirs=/cow=rw:${rofsstring} ${UNIONTYPE} "${rootmnt}" || panic "${UNIONTYPE} mount failed"
969 # Adding other custom mounts
970 if [ -n "${PERSISTENT}" ]
972 # directly mount /home
973 # FIXME: add a custom mounts configurable system
974 homecow=$(find_cow_device "${home_persistence}" )
976 if [ -b "${homecow}" ]
978 mount -t $(get_fstype "${homecow}") -o rw,noatime,nodiratime "${homecow}" "${rootmnt}/home"
979 export HOMEMOUNTED=1 # used to proper calculate free space in do_snap_copy()
981 [ "${quiet}" != "y" ] && log_warning_msg "Unable to find the persistent home medium"
984 # Look for other snapshots to copy in
985 try_snap "${root_snapshot_label}" "${rootmnt}" "ROOT"
986 try_snap "${home_snapshot_label}" "${rootmnt}/home" "HOME"
989 if [ -n "${SHOWMOUNTS}" ]
993 mkdir -p "${rootmnt}/live/${d##*/}"
997 # do nothing # mount -o bind "${d}" "${rootmnt}/live/${d##*/}"
1001 mount --move "${d}" "${rootmnt}/live/${d##*/}"
1007 # shows cow fs on /cow for use by live-snapshot
1008 mkdir -p "${rootmnt}/live/cow"
1009 mount -o move /cow "${rootmnt}/live/cow"
1016 skip_uuid_check="${3}"
1018 if [ -z "${devname}" ]
1020 devname=$(sys2dev "${sysdev}")
1023 if [ -n "${LIVE_MEDIA_OFFSET}" ]
1025 loopdevname=$(setup_loop "${devname}" "loop" "/sys/block/loop*" "${LIVE_MEDIA_OFFSET}" '')
1026 devname="${loopdevname}"
1029 fstype=$(get_fstype "${devname}")
1031 if is_supported_fs ${fstype}
1033 mount -t ${fstype} -o ro,noatime,nodiratime "${devname}" ${mountpoint} || continue
1035 if is_live_path ${mountpoint} && \
1036 ([ "${skip_uuid_check}" ] || matches_uuid ${mountpoint})
1041 umount ${mountpoint}
1045 if [ -n "${LIVE_MEDIA_OFFSET}" ]
1047 losetup -d "${loopdevname}"
1057 # first look at the one specified in the command line
1058 if [ ! -z "${LIVE_MEDIA}" ]
1060 if check_dev "null" "${LIVE_MEDIA}" "skip_uuid_check"
1066 # don't start autodetection before timeout has expired
1067 if [ -n "${LIVE_MEDIA_TIMEOUT}" ]
1069 if [ "${timeout}" -lt "${LIVE_MEDIA_TIMEOUT}" ]
1075 # or do the scan of block devices
1076 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -v loop | grep -v ram)
1078 devname=$(sys2dev "${sysblock}")
1079 fstype=$(get_fstype "${devname}")
1081 if /lib/udev/cdrom_id ${devname} > /dev/null
1083 if check_dev "null" "${devname}"
1087 elif is_nice_device "${sysblock}"
1089 for dev in $(subdevices "${sysblock}")
1091 if check_dev "${dev}"
1096 elif [ "${fstype}" = "squashfs" -o \
1097 "${fstype}" = "ext2" -o \
1098 "${fstype}" = "ext3" ]
1100 # This is an ugly hack situation, the block device has
1101 # an image directly on it. It's hopefully
1102 # live-initramfs, so take it and run with it.
1103 ln -s "${devname}" "${devname}.${fstype}"
1104 echo "${devname}.${fstype}"
1114 if [ -x /sbin/usplash_write ]
1116 /sbin/usplash_write "PULSATE"
1120 set_usplash_timeout ()
1122 if [ -x /sbin/usplash_write ]
1124 /sbin/usplash_write "TIMEOUT 120"
1138 [ "${quiet}" != "y" ] && log_begin_msg "Running /scripts/live-premount"
1140 run_scripts /scripts/live-premount
1141 [ "${quiet}" != "y" ] && log_end_msg
1143 # Needed here too because some things (*cough* udev *cough*)
1144 # changes the timeout
1148 if [ ! -z "${NETBOOT}" ] || [ ! -z "${FETCH}" ]
1152 livefs_root="${mountpoint}"
1154 panic "Unable to find a live file system on the network"
1157 # Scan local devices for the image
1158 for i in 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
1160 livefs_root=$(find_livefs ${i})
1162 if [ -n "${livefs_root}" ]
1171 if [ -z "${livefs_root}" ]
1173 panic "Unable to find a medium containing a live file system"
1179 elif [ "${TODISK}" ]
1181 live_dest="${TODISK}"
1184 if [ "${live_dest}" ]
1186 log_begin_msg "Copying live media to ${live_dest}"
1187 copy_live_to "${livefs_root}" "${live_dest}"
1191 if [ -n "${MODULETORAMFILE}" ]
1193 setup_unionfs "${livefs_root}" "${rootmnt}"
1195 mount_images_in_directory "${livefs_root}" "${rootmnt}"
1200 maybe_break live-bottom
1201 [ "${quiet}" != "y" ] && log_begin_msg "Running /scripts/live-bottom"
1204 run_scripts /scripts/live-bottom
1205 [ "${quiet}" != "y" ] && log_end_msg
1209 cp live.log "${rootmnt}/var/log/"