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"
22 mkdir -p "${mountpoint}"
24 [ -f /etc/live.conf ] && . /etc/live.conf
25 export USERNAME USERFULLNAME HOSTNAME
27 . /scripts/live-helpers
29 if [ ! -f /live.vars ]
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
87 STATICIP="${ARGUMENT#ip=}"
89 if [ -z "${STATICIP}" ]
97 keyb=*|kbd-chooser/method=*)
102 klayout=*|console-setup/layoutcode=*)
103 KLAYOUT="${ARGUMENT#*=}"
107 kvariant=*|console-setup/variantcode=*)
108 KVARIANT="${ARGUMENT#*=}"
112 kmodel=*|console-setup/modelcode=*)
113 KMODEL="${ARGUMENT#*=}"
118 KOPTIONS="${ARGUMENT#koptions=}"
127 live-media=*|bootfrom=*)
128 LIVE_MEDIA="${ARGUMENT#*=}"
132 live-media-encryption=*|encryption=*)
133 LIVE_MEDIA_ENCRYPTION="${ARGUMENT#*=}"
134 export LIVE_MEDIA_ENCRYPTION
138 LIVE_MEDIA_OFFSET="${ARGUMENT#live-media-offset=}"
139 export LIVE_MEDIA_OFFSET
143 LIVE_MEDIA_PATH="${ARGUMENT#live-media-path=}"
144 export LIVE_MEDIA_PATH
147 live-media-timeout=*)
148 LIVE_MEDIA_TIMEOUT="${ARGUMENT#live-media-timeout=}"
149 export LIVE_MEDIA_TIMEOUT
152 locale=*|debian-installer/locale=*)
153 LOCALE="${ARGUMENT#*=}"
158 MODULE="${ARGUMENT#module=}"
163 NETBOOT="${ARGUMENT#netboot=}"
168 NFSOPTS="${ARGUMENT#nfsopts=}"
173 NOACCESSIBILITY="Yes"
174 export NOACCESSIBILITY
198 NOCONSOLEKEYBOARD="Yes"
199 export NOCONSOLEKEYBOARD
223 NOKPERSONALIZER="Yes"
224 export NOKPERSONALIZER
233 NOLANGUAGESELECTOR="Yes"
234 export NOLANGUAGESELECTOR
248 NOPOWERMANAGEMENT="Yes"
249 export NOPOWERMANAGEMENT
253 NOPROGRAMCRASHES="Yes"
254 export NOPROGRAMCRASHES
258 NORESTRICTEDMANAGER="Yes"
259 export NORESTRICTEDMANAGER
273 NOUPDATENOTIFIER="Yes"
274 export NOUPDATENOTIFIER
289 export NOXSCREENSAVER
302 preseed/file=*|file=*)
303 LOCATION="${ARGUMENT#*=}"
313 location="${ARGUMENT#url=}"
315 mount -n -o bind /sys /root/sys
316 mount -n -o bind /proc /root/proc
317 mount -n -o bind /dev /root/dev
319 mkdir -p /root/var/run/network
321 chroot /root wget -P /tmp "${location}"
322 chroot /root ifdown -a
328 LOCATION="/tmp/$(basename "${location}")"
332 question="${ARGUMENT%%=*}"
333 value="${ARGUMENT#*=}"
334 PRESEEDS="${PRESEEDS}\"${question}=${value}\" "
349 TIMEZONE="${ARGUMENT#timezone=}"
359 TODISK="${ARGUMENT#todisk=}"
370 MODULETORAM="${ARGUMENT#toram=}"
371 export TORAM MODULETORAM
375 UNIONTYPE="${ARGUMENT#union=}"
380 UTC="${ARGUMENT#utc=}"
390 XVIDEOMODE="${ARGUMENT#xvideomode=}"
396 # sort of compatibility with netboot.h from linux docs
397 if [ -z "${NETBOOT}" ]
399 if [ "${ROOT}" = "/dev/nfs" ]
403 elif [ "${ROOT}" = "/dev/cifs" ]
410 if [ -z "${MODULE}" ]
416 if [ -z "${UNIONTYPE}" ]
427 if [ -d "${DIRECTORY}"/"${LIVE_MEDIA_PATH}" ]
429 for FILESYSTEM in squashfs ext2 ext3 xfs dir
431 if [ "$(echo ${DIRECTORY}/${LIVE_MEDIA_PATH}/*.${FILESYSTEM})" != "${DIRECTORY}/${LIVE_MEDIA_PATH}/*.${FILESYSTEM}" ]
443 if [ "${IGNORE_UUID}" ] || [ ! -e /conf/uuid.conf ]
449 uuid="$(cat /conf/uuid.conf)"
451 for try_uuid_file in "${mountpoint}/.disk/casper-uuid"*
453 [ -e "${try_uuid_file}" ] || continue
455 try_uuid="$(cat "${try_uuid_file}")"
457 if [ "${uuid}" = "${try_uuid}" ]
466 get_backing_device ()
469 *.squashfs|*.ext2|*.ext3)
470 echo $(setup_loop "${1}" "loop" "/sys/block/loop*" '0' "${LIVE_MEDIA_ENCRYPTION}")
478 panic "Unrecognized live filesystem: ${1}"
483 match_files_in_dir ()
485 # Does any files match pattern ${1} ?
488 if [ "$(echo ${pattern})" != "${pattern}" ]
496 mount_images_in_directory ()
501 if match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.squashfs" ||
502 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.ext2" ||
503 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.ext3" ||
504 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.dir"
506 setup_unionfs "${directory}/${LIVE_MEDIA_PATH}" "${rootmnt}"
514 sysfs_path="${1#/sys}"
516 if /lib/udev/path_id "${sysfs_path}" | grep -E -q "ID_PATH=(usb|pci-[^-]*-[ide|scsi|usb])"
526 # FIXME: do something better like the scan of supported filesystems
530 vfat|iso9660|udf|ext2|ext3|ntfs)
542 copyto="${copyfrom}_swap"
544 if [ -z "${MODULETORAM}" ]
546 size=$(fs_size "" ${copyfrom} "used")
548 MODULETORAMFILE="${copyfrom}/${LIVE_MEDIA_PATH}/${MODULETORAM}"
550 if [ -f "${MODULETORAMFILE}" ]
552 size=$( expr $(ls -la ${MODULETORAMFILE} | awk '{print $5}') / 1024 + 5000 )
554 log_warning_msg "Error: toram-module ${MODULETORAM} (${MODULETORAMFILE}) could not be read."
559 if [ "${copytodev}" = "ram" ]
562 freespace=$( expr $(awk '/MemFree/{print $2}' /proc/meminfo) + $( cat /proc/meminfo | grep Cached | head -n 1 | awk '/Cached/{print $2}' - ) )
563 mount_options="-o size=${size}k"
568 # it should be a writable block device
569 if [ -b "${copytodev}" ]
573 fstype=$(get_fstype "${dev}")
574 freespace=$(fs_size "${dev}")
576 [ "$quiet" != "y" ] && log_warning_msg "${copytodev} is not a block device."
581 if [ "${freespace}" -lt "${size}" ]
583 [ "${quiet}" != "y" ] && log_warning_msg "Not enough free ${free_string} (${freespace}k free, ${size}k needed) to copy live media in ${copytodev}."
587 # begin copying (or uncompressing)
589 echo "mount -t ${fstype} ${mount_options} ${dev} ${copyto}"
590 mount -t "${fstype}" ${mount_options} "${dev}" "${copyto}"
592 if [ "${extension}" = "tgz" ]
595 tar zxf "${copyfrom}/${LIVE_MEDIA_PATH}/$(basename ${FETCH})"
596 rm -f "${copyfrom}/${LIVE_MEDIA_PATH}/$(basename ${FETCH})"
597 mount -r --move "${copyto}" "${rootmnt}"
600 if [ -n "${MODULETORAMFILE}" ]
602 cp ${MODULETORAMFILE} ${copyto} # copy only the filesystem module
604 cp -a ${copyfrom}/* ${copyto} # "cp -a" from busybox also copies hidden files
609 mount -r --move ${copyto} ${copyfrom}
620 modprobe -q af_packet # For DHCP
625 ipconfig ${DEVICE} | tee /netboot.config
627 # source relevant ipconfig output
628 OLDHOSTNAME=${HOSTNAME}
629 . /tmp/net-${DEVICE}.conf
630 [ -z ${HOSTNAME} ] && HOSTNAME=${OLDHOSTNAME}
633 if [ "${NFSROOT}" = "auto" ]
635 NFSROOT=${ROOTSERVER}:${ROOTPATH}
638 if [ -n "${FETCH}" ] && do_httpmount
644 if [ "${NFSROOT#*:}" = "${NFSROOT}" ] && [ "$NETBOOT" != "cifs" ]
646 NFSROOT=${ROOTSERVER}:${NFSROOT}
649 [ "${quiet}" != "y" ] && log_begin_msg "Trying netboot from ${NFSROOT}"
651 if [ "${NETBOOT}" != "nfs" ] && do_cifsmount
661 [ "${quiet}" != "y" ] && log_end_msg
668 extension=$(echo "${FETCH}" | sed 's/\(.*\)\.\(.*\)/\2/')
670 case "${extension}" in
672 [ "${quiet}" != "y" ] && log_begin_msg "Trying wget ${FETCH} -O ${mountpoint}/$(basename ${FETCH})"
673 mkdir -p "${mountpoint}/${LIVE_MEDIA_PATH}"
674 wget "${FETCH}" -O "${mountpoint}/${LIVE_MEDIA_PATH}/$(basename ${FETCH})"
675 [ ${?} -eq 0 ] && rc=0
676 [ "${extension}" = "tgz" ] && live_dest="ram"
680 [ "${quiet}" != "y" ] && log_begin_msg "Unrecognized archive extension for ${FETCH}"
692 if [ -z "${NFSOPTS}" ]
697 [ "${quiet}" != "y" ] && log_begin_msg "Trying nfsmount -o nolock -o ro ${NFSOPTS} ${NFSROOT} ${mountpoint}"
699 # FIXME: This for loop is an ugly HACK round an nfs bug
700 for i in 0 1 2 3 4 5 6 7 8 9 a b c d e f 10 11 12 13
702 nfsmount -o nolock -o ro ${NFSOPTS} "${NFSROOT}" "${mountpoint}" && rc=0 && break
713 if [ -x "/sbin/mount.cifs" ]
715 if [ -z "${NFSOPTS}" ]
717 CIFSOPTS="-ouser=root,password="
719 CIFSOPTS="${NFSOPTS}"
722 [ "${quiet}" != "y" ] && log_begin_msg "Trying mount.cifs ${NFSROOT} ${mountpoint} ${CIFSOPTS}"
725 if mount.cifs "${NFSROOT}" "${mountpoint}" "${CIFSOPTS}"
739 size=$(fs_size "${fromdev}" "" "used")
741 if [ -b "${fromdev}" ]
744 if [ -n "${HOMEMOUNTED}" -a "${snap_type}" = "HOME" ]
746 todev=$(cat /proc/mounts | grep -s " $(base_path ${todir}) " | awk '{print $1}' )
747 freespace=$(df -k | grep -s ${todev} | awk '{print $4}')
749 freespace=$( expr $(awk '/MemFree/{print $2}' /proc/meminfo) + $( cat /proc/meminfo | grep Cached | head -n 1 | awk '/Cached/{print $2}' - ))
752 tomount="/mnt/tmpsnap"
754 if [ ! -d "${tomount}" ]
756 mkdir -p "${tomount}"
759 fstype=$(get_fstype "${fromdev}")
761 if [ -n "${fstype}" ]
764 mount -t "${fstype}" -o ro,noatime "${fromdev}" "${tomount}"
765 cp -a "${tomount}"/* ${todir}
768 log_warning_msg "Unrecognized fstype: ${fstype} on ${fromdev}:${snap_type}"
773 if echo ${fromdev} | grep -qs loop
775 losetup -d "${fromdev}"
782 [ "${quiet}" != "y" ] && log_warning_msg "Unable to find the snapshot ${snap_type} medium"
788 # Look for ${snap_label}.* in block devices and copy the contents to ${snap_mount}
789 # and remember the device and filename for resync on exit in live-initramfs.init
794 snapdata=$(find_files "${snap_label}.squashfs ${snap_label}.cpio.gz ${snap_label}.ext2 ${snap_label}.ext3")
796 if [ ! -z "${snapdata}" ]
798 snapdev="$(echo ${snapdata} | cut -f1 -d ' ')"
799 snapback="$(echo ${snapdata} | cut -f2 -d ' ')"
800 snapfile="$(echo ${snapdata} | cut -f3 -d ' ')"
802 if echo "${snapfile}" | grep -qs '\(squashfs\|ext2\|ext3\)'
804 # squashfs or ext2/ext3 snapshot
805 dev=$(get_backing_device "${snapback}/${snapfile}")
807 if ! do_snap_copy "${dev}" "${snap_mount}" "${snap_type}"
809 log_warning_msg "Impossible to include the ${snapfile} Snapshot"
814 if ! (cd "${snap_mount}" && zcat "${snapback}/${snapfile}" | cpio -i -u -d 2>/dev/null)
816 log_warning_msg "Impossible to include the ${snapfile} Snapshot"
823 dev=$(find_cow_device "${snap_label}")
827 if echo "${dev}" | grep -qs loop
829 # strange things happens, user confused?
830 snaploop=$( losetup ${dev} | awk '{print $3}' | tr -d '()' )
831 snapfile=$(basename ${snaploop})
832 snapdev=$(cat /proc/mounts | awk '{print $2,$1}' | grep -es "^$( dirname ${snaploop} )" | cut -f2 -d ' ')
837 if ! do_snap_copy "${dev}" "${snap_mount}" "${snap_type}"
839 log_warning_msg "Impossible to include the ${snap_label} Snapshot"
842 if [ -n "${snapfile}" ]
844 # it was a loop device, user confused
849 log_warning_msg "Impossible to include the ${snap_label} Snapshot"
854 echo "export ${snap_type}SNAP="${snap_mount}":${snapdev}:${snapfile}" >> /etc/live.conf # for resync on reboot/halt
860 image_directory="${1}"
863 modprobe -q -b ${UNIONTYPE}
865 # run-init can't deal with images in a subdir, but we're going to
866 # move all of these away before it runs anyway. No, we're not,
867 # put them in / since move-mounting them into / breaks mono and
872 # Let's just mount the read-only file systems first
875 minor_kernel_version=$(uname -r|cut -c 5-|sed 's/[^0-9].*//')
877 if [ "${NETBOOT}" = "nfs" ] && [ "${minor_kernel_version}" -lt 22 ]
879 # go aroung a bug in nfs-unionfs locking for unionfs <= 1.4
885 # Read image names from ${MODULE}.module if it exists
886 if [ -e "${image_directory}/filesystem.${MODULE}.module" ]
888 for IMAGE in $(cat ${image_directory}/filesystem.${MODULE}.module)
890 image_string="${image_string} ${image_directory}/${IMAGE}"
892 elif [ -e "${image_directory}/${MODULE}.module" ]
894 for IMAGE in $(cat ${image_directory}/${MODULE}.module)
896 image_string="${image_string} ${image_directory}/${IMAGE}"
899 # ${MODULE}.module does not exist, create a list of images
900 for FILESYSTEM in squashfs ext2 ext3 xfs dir
902 for IMAGE in "${image_directory}"/*."${FILESYSTEM}"
906 image_string="${image_string} ${IMAGE}"
912 image_string="$(echo ${image_string} | sed -e 's/ /\n/g' | sort )"
915 [ -n "${MODULETORAMFILE}" ] && image_string="${image_directory}/$(basename ${MODULETORAMFILE})"
919 for image in ${image_string}
921 imagename=$(basename "${image}")
925 # it is a plain directory: do nothing
926 rofsstring="${image}=${roopt}:${rofsstring}"
927 rofslist="${image} ${rofslist}"
928 elif [ -f "${image}" ]
930 backdev=$(get_backing_device "${image}")
931 fstype=$(get_fstype "${backdev}")
933 if [ "${fstype}" = "unknown" ]
935 panic "Unknown file system type on ${backdev} (${image})"
938 mkdir -p "${croot}/${imagename}"
939 echo "debug: Can not mount backdev ${backdev} (image = ${image}) on croot/imagename ${croot}/${imagename}"
940 mount -t "${fstype}" -o ro,noatime "${backdev}" "${croot}/${imagename}" || panic "Can not mount ${backdev} (${image}) on ${croot}/${imagename}" && rofsstring="${croot}/${imagename}=${roopt}:${rofsstring}" && rofslist="${croot}/${imagename} ${rofslist}"
944 rofsstring=${rofsstring%:}
950 # Looking for "${root_persistence}" device or file
951 if [ -n "${PERSISTENT}" ]
953 cowprobe=$(find_cow_device "${root_persistence}")
955 if [ -b "${cowprobe}" ]
957 cowdevice=${cowprobe}
958 cow_fstype=$(get_fstype "${cowprobe}")
960 [ "${quiet}" != "y" ] && log_warning_msg "Unable to find the persistent medium"
964 mount ${cowdevice} -t ${cow_fstype} -o rw,noatime /cow || panic "Can not mount ${cowdevice} on /cow"
966 mount -t ${UNIONTYPE} -o noatime,dirs=/cow=rw:${rofsstring} ${UNIONTYPE} "${rootmnt}" || panic "${UNIONTYPE} mount failed"
968 # Adding other custom mounts
969 if [ -n "${PERSISTENT}" ]
971 # directly mount /home
972 # FIXME: add a custom mounts configurable system
973 homecow=$(find_cow_device "${home_persistence}" )
975 if [ -b "${homecow}" ]
977 mount -t $(get_fstype "${homecow}") -o rw,noatime "${homecow}" "${rootmnt}/home"
978 export HOMEMOUNTED=1 # used to proper calculate free space in do_snap_copy()
980 [ "${quiet}" != "y" ] && log_warning_msg "Unable to find the persistent home medium"
983 # Look for other snapshots to copy in
984 try_snap "${root_snapshot_label}" "${rootmnt}" "ROOT"
985 try_snap "${home_snapshot_label}" "${rootmnt}/home" "HOME"
988 if [ -n "${SHOWMOUNTS}" ]
992 mkdir -p "${rootmnt}/live/${d##*/}"
996 # do nothing # mount -o bind "${d}" "${rootmnt}/live/${d##*/}"
1000 mount --move "${d}" "${rootmnt}/live/${d##*/}"
1006 # shows cow fs on /cow for use by live-snapshot
1007 mkdir -p "${rootmnt}/live/cow"
1008 mount -o move /cow "${rootmnt}/live/cow"
1015 skip_uuid_check="${3}"
1017 if [ -z "${devname}" ]
1019 devname=$(sys2dev "${sysdev}")
1022 if [ -n "${LIVE_MEDIA_OFFSET}" ]
1024 loopdevname=$(setup_loop "${devname}" "loop" "/sys/block/loop*" "${LIVE_MEDIA_OFFSET}" '')
1025 devname="${loopdevname}"
1028 fstype=$(get_fstype "${devname}")
1030 if is_supported_fs ${fstype}
1032 mount -t ${fstype} -o ro,noatime "${devname}" ${mountpoint} || continue
1034 if is_live_path ${mountpoint} && \
1035 ([ "${skip_uuid_check}" ] || matches_uuid ${mountpoint})
1040 umount ${mountpoint}
1044 if [ -n "${LIVE_MEDIA_OFFSET}" ]
1046 losetup -d "${loopdevname}"
1056 # first look at the one specified in the command line
1057 if [ ! -z "${LIVE_MEDIA}" ]
1059 if check_dev "null" "${LIVE_MEDIA}" "skip_uuid_check"
1065 # don't start autodetection before timeout has expired
1066 if [ -n "${LIVE_MEDIA_TIMEOUT}" ]
1068 if [ "${timeout}" -lt "${LIVE_MEDIA_TIMEOUT}" ]
1074 # or do the scan of block devices
1075 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -v loop | grep -v ram)
1077 devname=$(sys2dev "${sysblock}")
1078 fstype=$(get_fstype "${devname}")
1080 if /lib/udev/cdrom_id ${devname} > /dev/null
1082 if check_dev "null" "${devname}"
1086 elif is_nice_device "${sysblock}"
1088 for dev in $(subdevices "${sysblock}")
1090 if check_dev "${dev}"
1095 elif [ "${fstype}" = "squashfs" -o \
1096 "${fstype}" = "ext2" -o \
1097 "${fstype}" = "ext3" ]
1099 # This is an ugly hack situation, the block device has
1100 # an image directly on it. It's hopefully
1101 # live-initramfs, so take it and run with it.
1102 ln -s "${devname}" "${devname}.${fstype}"
1103 echo "${devname}.${fstype}"
1113 if [ -x /sbin/usplash_write ]
1115 /sbin/usplash_write "PULSATE"
1119 set_usplash_timeout ()
1121 if [ -x /sbin/usplash_write ]
1123 /sbin/usplash_write "TIMEOUT 120"
1137 [ "${quiet}" != "y" ] && log_begin_msg "Running /scripts/live-premount"
1139 run_scripts /scripts/live-premount
1140 [ "${quiet}" != "y" ] && log_end_msg
1142 # Needed here too because some things (*cough* udev *cough*)
1143 # changes the timeout
1147 if [ ! -z "${NETBOOT}" ] || [ ! -z "${FETCH}" ]
1151 livefs_root="${mountpoint}"
1153 panic "Unable to find a live file system on the network"
1156 # Scan local devices for the image
1157 for i in 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
1159 livefs_root=$(find_livefs ${i})
1161 if [ -n "${livefs_root}" ]
1170 if [ -z "${livefs_root}" ]
1172 panic "Unable to find a medium containing a live file system"
1178 elif [ "${TODISK}" ]
1180 live_dest="${TODISK}"
1183 if [ "${live_dest}" ]
1185 log_begin_msg "Copying live media to ${live_dest}"
1186 copy_live_to "${livefs_root}" "${live_dest}"
1190 if [ -n "${MODULETORAMFILE}" ]
1192 setup_unionfs "${livefs_root}" "${rootmnt}"
1194 mount_images_in_directory "${livefs_root}" "${rootmnt}"
1199 maybe_break live-bottom
1200 [ "${quiet}" != "y" ] && log_begin_msg "Running /scripts/live-bottom"
1203 run_scripts /scripts/live-bottom
1204 [ "${quiet}" != "y" ] && log_end_msg
1208 cp live.log "${rootmnt}/var/log/"