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
83 STATICIP="${ARGUMENT#ip=}"
85 if [ -z "${STATICIP}" ]
93 keyb=*|kbd-chooser/method=*)
98 klayout=*|console-setup/layoutcode=*)
99 KLAYOUT="${ARGUMENT#*=}"
103 kvariant=*|console-setup/variantcode=*)
104 KVARIANT="${ARGUMENT#*=}"
108 kmodel=*|console-setup/modelcode=*)
109 KMODEL="${ARGUMENT#*=}"
114 KOPTIONS="${ARGUMENT#koptions=}"
123 live-media=*|bootfrom=*)
124 LIVE_MEDIA="${ARGUMENT#*=}"
128 live-media-encryption=*|encryption=*)
129 LIVE_MEDIA_ENCRYPTION="${ARGUMENT#*=}"
130 export LIVE_MEDIA_ENCRYPTION
134 LIVE_MEDIA_OFFSET="${ARGUMENT#live-media-offset=}"
135 export LIVE_MEDIA_OFFSET
139 LIVE_MEDIA_PATH="${ARGUMENT#live-media-path=}"
140 export LIVE_MEDIA_PATH
143 live-media-timeout=*)
144 LIVE_MEDIA_TIMEOUT="${ARGUMENT#live-media-timeout=}"
145 export LIVE_MEDIA_TIMEOUT
148 locale=*|debian-installer/locale=*)
149 LOCALE="${ARGUMENT#*=}"
154 MODULE="${ARGUMENT#module=}"
159 NETBOOT="${ARGUMENT#netboot=}"
164 NFSOPTS="${ARGUMENT#nfsopts=}"
169 NOACCESSIBILITY="Yes"
170 export NOACCESSIBILITY
189 NOCONSOLEKEYBOARD="Yes"
190 export NOCONSOLEKEYBOARD
214 NOKPERSONALIZER="Yes"
215 export NOKPERSONALIZER
224 NOLANGUAGESELECTOR="Yes"
225 export NOLANGUAGESELECTOR
239 NOPOWERMANAGEMENT="Yes"
240 export NOPOWERMANAGEMENT
244 NOPROGRAMCRASHES="Yes"
245 export NOPROGRAMCRASHES
249 NORESTRICTEDMANAGER="Yes"
250 export NORESTRICTEDMANAGER
264 NOUPDATENOTIFIER="Yes"
265 export NOUPDATENOTIFIER
280 export NOXSCREENSAVER
293 preseed/file=*|file=*)
294 LOCATION="${ARGUMENT#*=}"
304 location="${ARGUMENT#url=}"
306 mount -n -o bind /sys /root/sys
307 mount -n -o bind /proc /root/proc
308 mount -n -o bind /dev /root/dev
310 mkdir -p /root/var/run/network
312 chroot /root wget -P /tmp "$location"
313 chroot /root ifdown -a
319 LOCATION="/tmp/$(basename "$location")"
323 question="${ARGUMENT%%=*}"
324 value="${ARGUMENT#*=}"
325 PRESEEDS="${PRESEEDS}\"${question}=${value}\" "
335 TIMEZONE="${ARGUMENT#timezone=}"
345 TODISK="${ARGUMENT#todisk=}"
356 MODULETORAM="${ARGUMENT#toram=}"
357 export TORAM MODULETORAM
361 UNIONTYPE="${ARGUMENT#union=}"
366 UTC="${ARGUMENT#utc=}"
376 XVIDEOMODE="${ARGUMENT#xvideomode=}"
382 # sort of compatibility with netboot.h from linux docs
383 if [ -z "${NETBOOT}" ]
385 if [ "${ROOT}" = "/dev/nfs" ]
389 elif [ "${ROOT}" = "/dev/cifs" ]
396 if [ -z "${MODULE}" ]
402 if [ -z "${UNIONTYPE}" ]
413 if [ -d "${DIRECTORY}"/"${LIVE_MEDIA_PATH}" ]
415 for FILESYSTEM in squashfs ext2 ext3 xfs dir
417 if [ "`echo ${DIRECTORY}/${LIVE_MEDIA_PATH}/*.${FILESYSTEM}`" != "${DIRECTORY}/${LIVE_MEDIA_PATH}/*.${FILESYSTEM}" ]
427 get_backing_device ()
430 *.squashfs|*.ext2|*.ext3)
431 echo $(setup_loop "$1" "loop" "/sys/block/loop*" '0' "${LIVE_MEDIA_ENCRYPTION}")
439 panic "Unrecognized live filesystem: $1"
444 match_files_in_dir ()
446 # Does any files match pattern $1 ?
449 if [ "$(echo $pattern)" != "$pattern" ]
457 mount_images_in_directory ()
462 if match_files_in_dir "$directory/${LIVE_MEDIA_PATH}/*.squashfs" ||
463 match_files_in_dir "$directory/${LIVE_MEDIA_PATH}/*.ext2" ||
464 match_files_in_dir "$directory/${LIVE_MEDIA_PATH}/*.ext3" ||
465 match_files_in_dir "$directory/${LIVE_MEDIA_PATH}/*.dir"
467 setup_unionfs "$directory/${LIVE_MEDIA_PATH}" "$rootmnt"
475 sysfs_path="${1#/sys}"
477 if /lib/udev/path_id "${sysfs_path}" | grep -E -q "ID_PATH=(usb|pci-[^-]*-[ide|scsi|usb])"
487 # FIXME: do something better like the scan of supported filesystems
491 vfat|iso9660|udf|ext2|ext3|ntfs)
503 copyto="${copyfrom}_swap"
505 if [ -z "${MODULETORAM}" ]
507 size=$(fs_size "" ${copyfrom} "used")
509 MODULETORAMFILE="${copyfrom}/${LIVE_MEDIA_PATH}/${MODULETORAM}"
511 if [ -f "${MODULETORAMFILE}" ]
513 size=$( expr $(ls -la ${MODULETORAMFILE} | awk '{print $5}') / 1024 + 5000 )
515 log_warning_msg "Error: toram-module $MODULETORAM ($MODULETORAMFILE) could not be read."
520 if [ "${copytodev}" = "ram" ]
523 freespace=$( expr $(awk '/MemFree/{print $2}' /proc/meminfo) + $( cat /proc/meminfo | grep Cached | head -n 1 | awk '/Cached/{print $2}' - ) )
524 mount_options="-o size=${size}k"
529 # it should be a writable block device
530 if [ -b "${copytodev}" ]
534 fstype=$(get_fstype "${dev}")
535 freespace=$(fs_size "${dev}")
537 [ "$quiet" != "y" ] && log_warning_msg "${copytodev} is not a block device."
542 if [ "${freespace}" -lt "${size}" ]
544 [ "$quiet" != "y" ] && log_warning_msg "Not enough free ${free_string} (${freespace}k free, ${size}k needed) to copy live media in ${copytodev}."
548 # begin copying (or uncompressing)
550 echo "mount -t ${fstype} ${mount_options} ${dev} ${copyto}"
551 mount -t "${fstype}" ${mount_options} "${dev}" "${copyto}"
553 if [ "$extension" = "tgz" ]
556 tar zxf "${copyfrom}/${LIVE_MEDIA_PATH}/$(basename ${FETCH})"
557 rm -f "${copyfrom}/${LIVE_MEDIA_PATH}/$(basename ${FETCH})"
558 mount -r --move "${copyto}" "${rootmnt}"
561 if [ -n "${MODULETORAMFILE}" ]
563 cp ${MODULETORAMFILE} ${copyto} # copy only the filesystem module
565 cp -a ${copyfrom}/* ${copyto} # "cp -a" from busybox also copies hidden files
570 mount -r --move ${copyto} ${copyfrom}
581 modprobe "${MP_QUIET}" af_packet # For DHCP
586 ipconfig ${DEVICE} | tee /netboot.config
588 if [ "${NFSROOT}" = "auto" ]
590 NFSROOT=${ROOTSERVER}:${ROOTPATH}
593 # source relevant ipconfig output
594 OLDHOSTNAME=$HOSTNAME
595 . /tmp/net-${DEVICE}.conf
596 [ -z $HOSTNAME ] && HOSTNAME=$OLDHOSTNAME
599 if [ -n "${FETCH}" ] && do_httpmount
605 if [ "${NFSROOT#*:}" = "$NFSROOT" ] && [ "$NETBOOT" != "cifs" ]
607 NFSROOT=${ROOTSERVER}:${NFSROOT}
610 [ "$quiet" != "y" ] && log_begin_msg "Trying netboot from ${NFSROOT}"
612 if [ "${NETBOOT}" != "nfs" ] && do_cifsmount
622 [ "$quiet" != "y" ] && log_end_msg
629 extension=`echo "${FETCH}" | sed 's/\(.*\)\.\(.*\)/\2/'`
631 case "${extension}" in
633 [ "$quiet" != "y" ] && log_begin_msg "Trying wget ${FETCH} -O ${mountpoint}/$(basename ${FETCH})"
634 mkdir -p "${mountpoint}/${LIVE_MEDIA_PATH}"
635 wget "${FETCH}" -O "${mountpoint}/${LIVE_MEDIA_PATH}/$(basename ${FETCH})"
637 [ "${extension}" == "tgz" ] && live_dest="ram"
641 [ "$quiet" != "y" ] && log_begin_msg "Unrecognized archive extension for ${FETCH}"
651 modprobe "${MP_QUIET}" nfs
653 if [ -z "${NFSOPTS}" ]
658 [ "$quiet" != "y" ] && log_begin_msg "Trying nfsmount -o nolock -o ro ${NFSOPTS} ${NFSROOT} ${mountpoint}"
660 # FIXME: This for loop is an ugly HACK round an nfs bug
661 for i in 0 1 2 3 4 5 6 7 8 9 a b c d e f 10 11 12 13
663 nfsmount -o nolock -o ro ${NFSOPTS} "${NFSROOT}" "${mountpoint}" && rc=0 && break
674 if [ -x "/sbin/mount.cifs" ]
676 if [ -z "${NFSOPTS}" ]
678 CIFSOPTS="-ouser=root,password="
680 CIFSOPTS="${NFSOPTS}"
683 [ "$quiet" != "y" ] && log_begin_msg "Trying mount.cifs ${NFSROOT} ${mountpoint} ${CIFSOPTS}"
684 modprobe "${MP_QUIET}" cifs
686 if mount.cifs "${NFSROOT}" "${mountpoint}" "${CIFSOPTS}"
700 size=$(fs_size "${fromdev}" "" "used")
702 if [ -b "${fromdev}" ]
705 if [ -n "${HOMEMOUNTED}" -a "${snap_type}" = "HOME" ]
707 todev=$(cat /proc/mounts | grep -s " $(base_path ${todir}) " | awk '{print $1}' )
708 freespace=$(df -k | grep -s ${todev} | awk '{print $4}')
710 freespace=$( expr $(awk '/MemFree/{print $2}' /proc/meminfo) + $( cat /proc/meminfo | grep Cached | head -n 1 | awk '/Cached/{print $2}' - ))
713 tomount="/mnt/tmpsnap"
715 if [ ! -d "${tomount}" ]
717 mkdir -p "${tomount}"
720 fstype=$(get_fstype "${fromdev}")
722 if [ -n "${fstype}" ]
725 mount -t "${fstype}" -o ro "${fromdev}" "${tomount}"
726 cp -a "${tomount}"/* ${todir}
729 log_warning_msg "Unrecognized fstype: ${fstype} on ${fromdev}:${snap_type}"
734 if echo ${fromdev} | grep -qs loop
736 losetup -d "${fromdev}"
743 [ "$quiet" != "y" ] && log_warning_msg "Unable to find the snapshot ${snap_type} medium"
749 # Look for $snap_label.* in block devices and copy the contents to $snap_mount
750 # and remember the device and filename for resync on exit in live-initramfs.init
755 snapdata=$(find_files "${snap_label}.squashfs ${snap_label}.cpio.gz ${snap_label}.ext2 ${snap_label}.ext3")
757 if [ ! -z "${snapdata}" ]
759 snapdev="$(echo ${snapdata} | cut -f1 -d ' ')"
760 snapback="$(echo ${snapdata} | cut -f2 -d ' ')"
761 snapfile="$(echo ${snapdata} | cut -f3 -d ' ')"
763 if echo "${snapfile}" | grep -qs '\(squashfs\|ext2\|ext3\)'
765 # squashfs or ext2/ext3 snapshot
766 dev=$(get_backing_device "${snapback}/${snapfile}")
768 if ! do_snap_copy "${dev}" "${snap_mount}" "${snap_type}"
770 log_warning_msg "Impossible to include the ${snapfile} Snapshot"
775 if ! (cd "${snap_mount}" && zcat "${snapback}/${snapfile}" | cpio -i -u -d 2>/dev/null)
777 log_warning_msg "Impossible to include the ${snapfile} Snapshot"
784 dev=$(find_cow_device "${snap_label}")
788 if echo "${dev}" | grep -qs loop
790 # strange things happens, user confused?
791 snaploop=$( losetup ${dev} | awk '{print $3}' | tr -d '()' )
792 snapfile=$(basename ${snaploop})
793 snapdev=$(cat /proc/mounts | awk '{print $2,$1}' | grep -es "^$( dirname ${snaploop} )" | cut -f2 -d ' ')
798 if ! do_snap_copy "${dev}" "${snap_mount}" "${snap_type}"
800 log_warning_msg "Impossible to include the ${snap_label} Snapshot"
803 if [ -n "${snapfile}" ]
805 # it was a loop device, user confused
810 log_warning_msg "Impossible to include the ${snap_label} Snapshot"
815 echo "export ${snap_type}SNAP="${snap_mount}":${snapdev}:${snapfile}" >> /etc/live.conf # for resync on reboot/halt
824 modprobe "${MP_QUIET}" -b ${UNIONTYPE}
826 # run-init can't deal with images in a subdir, but we're going to
827 # move all of these away before it runs anyway. No, we're not,
828 # put them in / since move-mounting them into / breaks mono and
833 # Let's just mount the read-only file systems first
836 minor_kernel_version=`uname -r|cut -c 5-|sed 's/[^0-9].*//'`
838 if [ "${NETBOOT}" = "nfs" ] && [ "${minor_kernel_version}" -lt 22 ]
840 # go aroung a bug in nfs-unionfs locking for unionfs <= 1.4
846 # Read image names from ${MODULE}.module if it exists
847 if [ -e "${image_directory}/filesystem.${MODULE}.module" ]
849 for IMAGE in `cat ${image_directory}/filesystem.${MODULE}.module`
851 image_string="${image_string} ${image_directory}/${image}"
853 elif [ -e "${image_directory}/${MODULE}.module" ]
855 for IMAGE in `cat ${image_directory}/${MODULE}.module`
857 image_string="${image_string} ${image_directory}/${image}"
860 # ${MODULE}.module does not exist, create a list of images
861 for FILESYSTEM in squashfs ext2 ext3 xfs dir
863 for IMAGE in "${image_directory}"/*."${FILESYSTEM}"
867 image_string="${image_string} ${IMAGE}"
873 image_string="`echo ${image_string} | sed -e 's/ /\n/g' | sort `"
876 [ -n "${MODULETORAMFILE}" ] && image_string="${image_directory}/$(basename ${MODULETORAMFILE})"
880 for image in ${image_string}
882 imagename=$(basename "${image}")
886 # it is a plain directory: do nothing
887 rofsstring="${image}=${roopt}:${rofsstring}"
888 rofslist="${image} ${rofslist}"
889 elif [ -f "${image}" ]
891 backdev=$(get_backing_device "$image")
892 fstype=$(get_fstype "${backdev}")
894 if [ "${fstype}" = "unknown" ]
896 panic "Unknown file system type on ${backdev} (${image})"
899 mkdir -p "${croot}/${imagename}"
900 echo "debug: Can not mount backdev $backdev (image = $image) on croot/imagename ${croot}/${imagename}"
901 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}"
905 rofsstring=${rofsstring%:}
911 # Looking for "${root_persistence}" device or file
912 if [ -n "${PERSISTENT}" ]
914 cowprobe=$(find_cow_device "${root_persistence}")
916 if [ -b "${cowprobe}" ]
918 cowdevice=${cowprobe}
919 cow_fstype=$(get_fstype "${cowprobe}")
921 [ "$quiet" != "y" ] && log_warning_msg "Unable to find the persistent medium"
925 mount ${cowdevice} -t ${cow_fstype} -o rw /cow || panic "Can not mount $cowdevice on /cow"
927 mount -t ${UNIONTYPE} -o dirs=/cow=rw:$rofsstring ${UNIONTYPE} "$rootmnt" || panic "${UNIONTYPE} mount failed"
929 # Adding other custom mounts
930 if [ -n "${PERSISTENT}" ]
932 # directly mount /home
933 # FIXME: add a custom mounts configurable system
934 homecow=$(find_cow_device "${home_persistence}" )
936 if [ -b "${homecow}" ]
938 mount -t $(get_fstype "${homecow}") -o rw "${homecow}" "${rootmnt}/home"
939 export HOMEMOUNTED=1 # used to proper calculate free space in do_snap_copy()
941 [ "$quiet" != "y" ] && log_warning_msg "Unable to find the persistent home medium"
944 # Look for other snapshots to copy in
945 try_snap "${root_snapshot_label}" "${rootmnt}" "ROOT"
946 try_snap "${home_snapshot_label}" "${rootmnt}/home" "HOME"
949 if [ -n "${SHOWMOUNTS}" ]
953 mkdir -p "${rootmnt}/live/${d##*/}"
957 # do nothing # mount -o bind "${d}" "${rootmnt}/live/${d##*/}"
961 mount --move "${d}" "${rootmnt}/live/${d##*/}"
967 # shows cow fs on /cow for use by live-snapshot
968 mkdir -p "${rootmnt}/live/cow"
969 mount -o bind /cow "${rootmnt}/live/cow"
977 if [ -z "${devname}" ]
979 devname=$(sys2dev "${sysdev}")
982 if [ -n "${LIVE_MEDIA_OFFSET}" ]
984 loopdevname=$(setup_loop "${devname}" "loop" "/sys/block/loop*" "${LIVE_MEDIA_OFFSET}" '')
985 devname="${loopdevname}"
988 fstype=$(get_fstype "${devname}")
990 if is_supported_fs ${fstype}
992 mount -t ${fstype} -o ro "${devname}" $mountpoint || continue
994 if is_live_path $mountpoint
1003 if [ -n "${LIVE_MEDIA_OFFSET}" ]
1005 losetup -d "${loopdevname}"
1015 # first look at the one specified in the command line
1016 if [ ! -z "${LIVE_MEDIA}" ]
1018 if check_dev "null" "${LIVE_MEDIA}"
1024 # don't start autodetection before timeout has expired
1025 if [ -n "${LIVE_MEDIA_TIMEOUT}" ]
1027 if [ "${timeout}" -lt "${LIVE_MEDIA_TIMEOUT}" ]
1033 # or do the scan of block devices
1034 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -v loop | grep -v ram)
1036 devname=$(sys2dev "${sysblock}")
1037 fstype=$(get_fstype "${devname}")
1039 if /lib/udev/cdrom_id ${devname} > /dev/null
1041 if check_dev "null" "${devname}"
1045 elif is_nice_device "${sysblock}"
1047 for dev in $(subdevices "${sysblock}")
1049 if check_dev "${dev}"
1054 elif [ "${fstype}" = "squashfs" -o \
1055 "${fstype}" = "ext2" -o \
1056 "${fstype}" = "ext3" ]
1058 # This is an ugly hack situation, the block device has
1059 # an image directly on it. It's hopefully
1060 # live-initramfs, so take it and run with it.
1061 ln -s "${devname}" "${devname}.${fstype}"
1062 echo "${devname}.${fstype}"
1072 if [ -x /sbin/usplash_write ]
1074 /sbin/usplash_write "PULSATE"
1078 set_usplash_timeout ()
1080 if [ -x /sbin/usplash_write ]
1082 /sbin/usplash_write "TIMEOUT 120"
1096 [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/live-premount"
1098 run_scripts /scripts/live-premount
1099 [ "$quiet" != "y" ] && log_end_msg
1101 # Needed here too because some things (*cough* udev *cough*)
1102 # changes the timeout
1106 if [ ! -z "${NETBOOT}" ] || [ ! -z "${FETCH}" ]
1110 livefs_root="${mountpoint}"
1112 panic "Unable to find a live file system on the network"
1115 # Scan local devices for the image
1116 for i in 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
1118 livefs_root=$(find_livefs $i)
1120 if [ -n "${livefs_root}" ]
1129 if [ -z "${livefs_root}" ]
1131 panic "Unable to find a medium containing a live file system"
1137 elif [ "${TODISK}" ]
1139 live_dest="${TODISK}"
1142 if [ "${live_dest}" ]
1144 log_begin_msg "Copying live media to ${live_dest}"
1145 copy_live_to "${livefs_root}" "${live_dest}"
1149 if [ -n "${MODULETORAMFILE}" ]
1151 setup_unionfs "${livefs_root}" "$rootmnt"
1153 mount_images_in_directory "${livefs_root}" "${rootmnt}"
1158 maybe_break live-bottom
1159 [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/live-bottom"
1162 run_scripts /scripts/live-bottom
1163 [ "$quiet" != "y" ] && log_end_msg
1167 cp live.log "${rootmnt}/var/log/"