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}"
25 # Create /etc/mtab for debug purpose and future syncs
36 [ -f /etc/live.conf ] && . /etc/live.conf
37 export USERNAME USERFULLNAME HOSTNAME
39 . /scripts/live-helpers
41 if [ ! -f /live.vars ]
50 [ -z "$network_started" ] || return
51 [ -z "$NETBOOT" ] || return
53 mount -n -o bind /sys /root/sys
54 mount -n -o bind /proc /root/proc
55 mount -n -o bind /dev /root/dev
56 mkdir -p /root/var/run/network
58 # Close inherited fd's to prevent debconf-communicate from
59 # continuing to run post-live-initramfs.
60 chroot /root dhclient eth0 3>&- 4<&-
67 [ "$network_started" ] || return
69 chroot /root ifconfig eth0 down
80 for ARGUMENT in $(cat /proc/cmdline)
88 NOCONSOLEKEYBOARD="Yes"
95 NOLANGUAGESELECTOR="Yes"
99 NOPOWERMANAGEMENT="Yes"
100 NOPROGRAMCRASHES="Yes"
103 NOUPDATENOTIFIER="Yes"
109 export NOACCESSIBILITY NOAPPARMOR NOAPTCDROM NOAUTOLOGIN NOCONSOLEKEYBOARD NOFASTBOOT NOFSTAB NOGNOMEPANEL NOHOSTS NOJOCKEY NOKPERSONALIZER NOLANGUAGESELECTOR NOLOCALES NONETWORKING NOPOLKITCONF NOPOWERMANAGEMENT NOPROGRAMCRASHES NOSUDO NOTIMEZONE NOUPDATENOTIFIER NOUSER NOXAUTOCONFIG NOXAUTOLOGIN NOXSCREENSAVER
113 ACCESS="${ARGUMENT#access=}"
118 DEFCONSOLE="${ARGUMENT#*=}"
130 DEVICE="${ARGUMENT#ethdevice=}"
135 ETHDEVICE="${ARGUMENT#ethdevice=}"
140 ETHDEV_TIMEOUT="${ARGUMENT#ethdevice-timeout=}"
141 export ETHDEV_TIMEOUT
145 FETCH="${ARGUMENT#fetch=}"
150 FORCEPERSISTENTFSCK="Yes"
151 export FORCEPERSISTENTFSCK
155 HOOK="${ARGUMENT#hook=}"
160 FTPFS="${ARGUMENT#ftpfs=}"
165 HTTPFS="${ARGUMENT#httpfs=}"
170 HOSTNAME="${ARGUMENT#hostname=}"
172 export HOSTNAME LIVECONF
176 FROMISO="${ARGUMENT#*=}"
181 USERNAME="${ARGUMENT#username=}"
183 export USERNAME LIVECONF
187 USERFULLNAME="${ARGUMENT#userfullname=}"
189 export USERFULLNAME LIVECONF
198 INTEGRITY_CHECK="Yes"
199 export INTEGRITY_CHECK
203 STATICIP="${ARGUMENT#ip=}"
205 if [ -z "${STATICIP}" ]
213 keyb=*|kbd-chooser/method=*)
218 klayout=*|console-setup/layoutcode=*)
219 KLAYOUT="${ARGUMENT#*=}"
223 kvariant=*|console-setup/variantcode=*)
224 KVARIANT="${ARGUMENT#*=}"
228 kmodel=*|console-setup/modelcode=*)
229 KMODEL="${ARGUMENT#*=}"
234 KOPTIONS="${ARGUMENT#koptions=}"
243 live-media=*|bootfrom=*)
244 LIVE_MEDIA="${ARGUMENT#*=}"
248 live-media-encryption=*|encryption=*)
249 LIVE_MEDIA_ENCRYPTION="${ARGUMENT#*=}"
250 export LIVE_MEDIA_ENCRYPTION
254 LIVE_MEDIA_OFFSET="${ARGUMENT#live-media-offset=}"
255 export LIVE_MEDIA_OFFSET
259 LIVE_MEDIA_PATH="${ARGUMENT#live-media-path=}"
260 export LIVE_MEDIA_PATH
263 live-media-timeout=*)
264 LIVE_MEDIA_TIMEOUT="${ARGUMENT#live-media-timeout=}"
265 export LIVE_MEDIA_TIMEOUT
268 language=*|debian-installer/language=*)
269 language=${x#debian-installer/language=}
270 locale="$(lang2locale "$language")"
274 locale=*|debian-installer/locale=*)
275 LOCALE="${ARGUMENT#*=}"
280 MODULE="${ARGUMENT#module=}"
285 NETBOOT="${ARGUMENT#netboot=}"
290 NFSOPTS="${ARGUMENT#nfsopts=}"
295 NFS_COW="${ARGUMENT#nfscow=}"
300 NOACCESSIBILITY="Yes"
301 export NOACCESSIBILITY
325 NOCONSOLEKEYBOARD="Yes"
326 export NOCONSOLEKEYBOARD
350 NOKPERSONALIZER="Yes"
351 export NOKPERSONALIZER
355 NOLANGUAGESELECTOR="Yes"
356 export NOLANGUAGESELECTOR
370 NOPOWERMANAGEMENT="Yes"
371 export NOPOWERMANAGEMENT
375 NOPROGRAMCRASHES="Yes"
376 export NOPROGRAMCRASHES
395 NOUPDATENOTIFIER="Yes"
396 export NOUPDATENOTIFIER
411 export NOXSCREENSAVER
420 PERSISTENT="${ARGUMENT#persistent=}"
421 if [ -z "${PERSISTENT}" ]
429 PERSISTENT_PATH="${ARGUMENT#persistent-path=}"
430 export PERSISTENT_PATH
433 persistent-subtext=*)
434 root_persistence="${root_persistence}-${ARGUMENT#persistent-subtext=}"
435 home_persistence="${home_persistence}-${ARGUMENT#persistent-subtext=}"
436 root_snapshot_label="${root_snapshot_label}-${ARGUMENT#persistent-subtext=}"
437 home_snapshot_label="${home_snapshot_label}-${ARGUMENT#persistent-subtext=}"
446 QUICKUSBMODULES="Yes"
447 export QUICKUSBMODULES
450 preseed/file=*|file=*)
451 LOCATIONS="${ARGUMENT#*=} ${LOCATIONS}"
461 URL_LOCATION="${ARGUMENT#url=}"
464 chroot /root wget -P /tmp "${URL_LOCATION}"
465 LOCATIONS="/tmp/$(basename ${URL_LOCATION}) ${LOCATIONS}"
469 question="${ARGUMENT%%=*}"
470 value="${ARGUMENT#*=}"
471 PRESEEDS="${PRESEEDS}\"${question}=${value}\" "
491 TIMEZONE="${ARGUMENT#timezone=}"
501 TODISK="${ARGUMENT#todisk=}"
512 MODULETORAM="${ARGUMENT#toram=}"
513 export TORAM MODULETORAM
527 SKIP_UNION_MOUNTS="Yes"
528 export SKIP_UNION_MOUNTS
532 ROOT="${ARGUMENT#root=}"
537 UNIONTYPE="${ARGUMENT#union=}"
542 UTC="${ARGUMENT#utc=}"
552 XDRIVER="${ARGUMENT#xdriver=}"
557 XVIDEOMODE="${ARGUMENT#xvideomode=}"
563 # sort of compatibility with netboot.h from linux docs
564 if [ -z "${NETBOOT}" ]
566 if [ "${ROOT}" = "/dev/nfs" ]
570 elif [ "${ROOT}" = "/dev/cifs" ]
577 if [ -z "${MODULE}" ]
583 if [ -z "${UNIONTYPE}" ]
594 if [ -d "${DIRECTORY}"/"${LIVE_MEDIA_PATH}" ]
596 for FILESYSTEM in squashfs ext2 ext3 ext4 xfs dir jffs2
598 if [ "$(echo ${DIRECTORY}/${LIVE_MEDIA_PATH}/*.${FILESYSTEM})" != "${DIRECTORY}/${LIVE_MEDIA_PATH}/*.${FILESYSTEM}" ]
610 if [ "${IGNORE_UUID}" ] || [ ! -e /conf/uuid.conf ]
616 uuid="$(cat /conf/uuid.conf)"
618 for try_uuid_file in "${path}/.disk/live-uuid"*
620 [ -e "${try_uuid_file}" ] || continue
622 try_uuid="$(cat "${try_uuid_file}")"
624 if [ "${uuid}" = "${try_uuid}" ]
633 get_backing_device ()
636 *.squashfs|*.ext2|*.ext3|*.ext4|*.jffs2)
637 echo $(setup_loop "${1}" "loop" "/sys/block/loop*" '0' "${LIVE_MEDIA_ENCRYPTION}" "${2}")
645 panic "Unrecognized live filesystem: ${1}"
650 match_files_in_dir ()
652 # Does any files match pattern ${1} ?
655 if [ "$(echo ${pattern})" != "${pattern}" ]
663 mount_images_in_directory ()
670 if match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.squashfs" ||
671 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.ext2" ||
672 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.ext3" ||
673 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.ext4" ||
674 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.jffs2" ||
675 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.dir"
677 [ -n "${mac}" ] && adddirectory="${directory}/${LIVE_MEDIA_PATH}/${mac}"
678 setup_unionfs "${directory}/${LIVE_MEDIA_PATH}" "${rootmnt}" "${adddirectory}"
680 panic "No supported filesystem images found at /${LIVE_MEDIA_PATH}."
686 sysfs_path="${1#/sys}"
688 if /lib/udev/path_id "${sysfs_path}" | egrep -q "ID_PATH=(usb|pci-|platform-orion-ehci|platform-mmc|platform-mxsdhci|)"
691 elif echo "${sysfs_path}" | grep -q '^/block/vd[a-z]$'
694 elif echo ${sysfs_path} | grep -q "^/block/dm-"
706 copyto="${copyfrom}_swap"
708 if [ -z "${MODULETORAM}" ]
710 size=$(fs_size "" ${copyfrom}/${LIVE_MEDIA_PATH} "used")
712 MODULETORAMFILE="${copyfrom}/${LIVE_MEDIA_PATH}/${MODULETORAM}"
714 if [ -f "${MODULETORAMFILE}" ]
716 size=$( expr $(ls -la ${MODULETORAMFILE} | awk '{print $5}') / 1024 + 5000 )
718 log_warning_msg "Error: toram-module ${MODULETORAM} (${MODULETORAMFILE}) could not be read."
723 if [ "${copytodev}" = "ram" ]
726 freespace=$(awk '/^MemFree:/{f=$2} /^Cached:/{c=$2} END{print f+c}' /proc/meminfo)
727 mount_options="-o size=${size}k"
732 # it should be a writable block device
733 if [ -b "${copytodev}" ]
737 fstype=$(get_fstype "${dev}")
738 freespace=$(fs_size "${dev}")
740 log_warning_msg "${copytodev} is not a block device."
745 if [ "${freespace}" -lt "${size}" ]
747 log_warning_msg "Not enough free ${free_string} (${freespace}k free, ${size}k needed) to copy live media in ${copytodev}."
751 # begin copying (or uncompressing)
753 log_begin_msg "mount -t ${fstype} ${mount_options} ${dev} ${copyto}"
754 mount -t "${fstype}" ${mount_options} "${dev}" "${copyto}"
756 if [ "${extension}" = "tgz" ]
759 tar zxf "${copyfrom}/${LIVE_MEDIA_PATH}/$(basename ${FETCH})"
760 rm -f "${copyfrom}/${LIVE_MEDIA_PATH}/$(basename ${FETCH})"
761 mount -r -o move "${copyto}" "${rootmnt}"
764 if [ -n "${MODULETORAMFILE}" ]
768 echo " * Copying $MODULETORAMFILE to RAM" 1>/dev/console
769 rsync -a --progress ${MODULETORAMFILE} ${copyto} 1>/dev/console # copy only the filesystem module
771 cp ${MODULETORAMFILE} ${copyto} # copy only the filesystem module
776 echo " * Copying whole medium to RAM" 1>/dev/console
777 rsync -a --progress ${copyfrom}/* ${copyto} 1>/dev/console # "cp -a" from busybox also copies hidden files
779 mkdir -p ${copyto}/${LIVE_MEDIA_PATH}
780 cp -a ${copyfrom}/${LIVE_MEDIA_PATH}/* ${copyto}/${LIVE_MEDIA_PATH}
781 if [ -e ${copyfrom}/${LIVE_MEDIA_PATH}/.disk ]
783 cp -a ${copyfrom}/${LIVE_MEDIA_PATH}/.disk ${copyto}
789 mount -r -o move ${copyto} ${copyfrom}
800 modprobe -q af_packet # For DHCP
805 if [ -z "${NETBOOT}" ] && [ -z "${FETCH}" ] && \
806 [ -z "${HTTPFS}" ] && [ -z "${FTPFS}" ]
809 # if ethdevice was not specified on the kernel command line
810 # make sure we try to get a working network configuration
811 # for *every* present network device (except for loopback of course)
812 if [ -z "$ETHDEVICE" ] ; then
813 echo "If you want to boot from a specific device use bootoption ethdevice=..."
814 for device in /sys/class/net/*; do
816 if [ "$dev" != "lo" ] ; then
817 ETHDEVICE="$ETHDEVICE $dev"
822 # split args of ethdevice=eth0,eth1 into "eth0 eth1"
823 for device in $(echo $ETHDEVICE | sed 's/,/ /g') ; do
824 devlist="$devlist $device"
827 [ -n "$ETHDEV_TIMEOUT" ] || ETHDEV_TIMEOUT=15
828 echo "Using timeout of $ETHDEV_TIMEOUT seconds for network configuration."
830 # this is tricky (and ugly) because ipconfig sometimes just hangs/runs into
831 # an endless loop; iff execution fails give it two further tries, that's
832 # why we use '$devlist $devlist $devlist' for the other for loop
833 for dev in $devlist $devlist $devlist ; do
834 echo "Executing ipconfig -t $ETHDEV_TIMEOUT $dev"
835 ipconfig -t "$ETHDEV_TIMEOUT" $dev | tee -a /netboot.config &
837 sleep "$ETHDEV_TIMEOUT" ; sleep 1
838 if [ -r /proc/"$jobid"/status ] ; then
839 echo "Killing job $jobid for device $dev as ipconfig ran into recursion..."
843 # if configuration of device worked we should have an assigned
844 # IP address, iff so let's use the according as $DEVICE for later usage
845 # simple and primitive approach which seems to work fine
846 if ifconfig $dev | grep -q 'inet.*addr:' ; then
853 ipconfig ${DEVICE} | tee /netboot.config
856 # source relevant ipconfig output
857 OLDHOSTNAME=${HOSTNAME}
858 . /tmp/net-${DEVICE}.conf
859 [ -z ${HOSTNAME} ] && HOSTNAME=${OLDHOSTNAME}
862 # Check if we have a network device at all
863 if ! ls /sys/class/net/"$DEVICE" > /dev/null 2>&1 && \
864 ! ls /sys/class/net/eth0 > /dev/null 2>&1 && \
865 ! ls /sys/class/net/wlan0 > /dev/null 2>&1 && \
866 ! ls /sys/class/net/ath0 > /dev/null 2>&1 && \
867 ! ls /sys/class/net/ra0 > /dev/null 2>&1
869 panic "No supported network device found, maybe a non-mainline driver is required."
872 if [ "${NFSROOT}" = "auto" ]
874 NFSROOT=${ROOTSERVER}:${ROOTPATH}
877 if ( [ -n "${FETCH}" ] || [ -n "${HTTPFS}" ] || [ -n "${FTPFS}" ] ) && do_httpmount
883 if [ "${NFSROOT#*:}" = "${NFSROOT}" ] && [ "$NETBOOT" != "cifs" ]
885 NFSROOT=${ROOTSERVER}:${NFSROOT}
888 log_begin_msg "Trying netboot from ${NFSROOT}"
890 if [ "${NETBOOT}" != "nfs" ] && do_cifsmount
907 dest="${mountpoint}/${LIVE_MEDIA_PATH}"
908 mount -t ramfs ram "${mountpoint}"
911 for webfile in HTTPFS FTPFS FETCH
913 url="$(eval echo \"\$\{${webfile}\}\")"
914 extension="$(echo "${url}" | sed 's/\(.*\)\.\(.*\)/\2/')"
918 case "${extension}" in
920 if [ "${webfile}" = "FETCH" ]
924 ip="$(dirname $url | sed -e 's|tftp://||g' -e 's|/.*$||g')"
925 rfile="$(echo $url | sed -e "s|tftp://$ip||g")"
926 lfile="$(basename $url)"
927 log_begin_msg "Trying tftp -g -b 10240 -r $rfile -l ${dest}/$lfile $ip"
928 tftp -g -b 10240 -r $rfile -l ${dest}/$lfile $ip
932 log_begin_msg "Trying wget ${url} -O ${dest}/$(basename ${url})"
933 wget "${url}" -O "${dest}/$(basename ${url})"
937 log_begin_msg "Trying to mount ${url} on ${dest}/$(basename ${url})"
938 if [ "${webfile}" = "FTPFS" ]
940 FUSE_MOUNT="curlftpfs"
941 url="$(dirname ${url})"
946 $FUSE_MOUNT "${url}" "${dest}"
948 [ ${?} -eq 0 ] && rc=0
949 [ "${extension}" = "tgz" ] && live_dest="ram"
954 log_begin_msg "Unrecognized archive extension for ${url}"
962 umount "${mountpoint}"
974 if [ -z "${NFSOPTS}" ]
979 log_begin_msg "Trying nfsmount -o nolock -o ro ${NFSOPTS} ${NFSROOT} ${mountpoint}"
981 # FIXME: This while loop is an ugly HACK round an nfs bug
983 while [ "$i" -lt 60 ]
985 nfsmount -o nolock -o ro ${NFSOPTS} "${NFSROOT}" "${mountpoint}" && rc=0 && break
997 if [ -x "/sbin/mount.cifs" ]
999 if [ -z "${NFSOPTS}" ]
1001 CIFSOPTS="-ouser=root,password="
1003 CIFSOPTS="${NFSOPTS}"
1006 log_begin_msg "Trying mount.cifs ${NFSROOT} ${mountpoint} ${CIFSOPTS}"
1009 if mount.cifs "${NFSROOT}" "${mountpoint}" "${CIFSOPTS}"
1023 size=$(fs_size "${fromdev}" "" "used")
1025 if [ -b "${fromdev}" ]
1028 if [ -n "${HOMEMOUNTED}" -a "${snap_type}" = "HOME" ]
1030 todev=$(awk -v pat="$(base_path ${todir})" '$2 == pat { print $1 }' /proc/mounts)
1031 freespace=$(df -k | awk '/'${todev}'/{print $4}')
1033 freespace=$(awk '/^MemFree:/{f=$2} /^Cached:/{c=$2} END{print f+c}' /proc/meminfo)
1036 tomount="/mnt/tmpsnap"
1038 if [ ! -d "${tomount}" ]
1040 mkdir -p "${tomount}"
1043 fstype=$(get_fstype "${fromdev}")
1045 if [ -n "${fstype}" ]
1048 mount -o ro -t "${fstype}" "${fromdev}" "${tomount}" || log_warning_msg "Error in mount -t ${fstype} -o ro ${fromdev} ${tomount}"
1049 cp -a "${tomount}"/* ${todir}
1052 log_warning_msg "Unrecognized fstype: ${fstype} on ${fromdev}:${snap_type}"
1057 if echo ${fromdev} | grep -qs loop
1059 losetup -d "${fromdev}"
1066 log_warning_msg "Unable to find the snapshot ${snap_type} medium"
1072 # Look for ${snap_label}.* in block devices
1075 if [ "${PERSISTENT}" != "nofiles" ]
1077 # search for image files
1078 snapdata=$(find_files "${PERSISTENT_PATH}${snap_label}.squashfs ${PERSISTENT_PATH}${snap_label}.cpio.gz ${PERSISTENT_PATH}${snap_label}.ext2 ${PERSISTENT_PATH}${snap_label}.ext3 ${PERSISTENT_PATH}${snap_label}.ext4 ${PERSISTENT_PATH}${snap_label}.jffs2")
1081 if [ -z "${snapdata}" ]
1083 snapdata=$(find_cow_device "${snap_label}")
1090 # copy the contents of previously found snapshot to ${snap_mount}
1091 # and remember the device and filename for resync on exit in live-initramfs.init
1097 if [ -n "${snapdata}" ] && [ ! -b "${snapdata}" ]
1099 log_success_msg "found snapshot: ${snapdata}"
1100 snapdev="$(echo ${snapdata} | cut -f1 -d ' ')"
1101 snapback="$(echo ${snapdata} | cut -f2 -d ' ')"
1102 snapfile="$(echo ${snapdata} | cut -f3 -d ' ')"
1105 if ! try_mount "${snapdev}" "${snapback}" "ro"
1110 if echo "${snapfile}" | grep -qs '\(squashfs\|ext2\|ext3\|ext4\|jffs2\)'
1112 # squashfs, jffs2 or ext2/ext3/ext4 snapshot
1113 dev=$(get_backing_device "${snapback}/${snapfile}")
1115 do_snap_copy "${dev}" "${snap_mount}" "${snap_type}"
1120 # Unfortunately klibc's cpio is incompatible with the
1121 # rest of the world; everything else requires -u -d,
1122 # while klibc doesn't implement them. Try to detect
1123 # whether it's in use.
1124 cpiopath="$(which cpio)" || true
1125 if [ "$cpiopath" ] && grep -aq /lib/klibc "$cpiopath"
1129 cpioargs='--unconditional --make-directories'
1132 if ! (cd "${snap_mount}" && zcat "${snapback}/${snapfile}" | cpio $cpioargs --extract --preserve-modification-time --no-absolute-filenames --sparse 2>/dev/null)
1134 log_warning_msg "failure to \"zcat ${snapback}/${snapfile} | cpio $cpioargs --extract --preserve-modification-time --no-absolute-filenames --sparse\""
1138 umount "${snapback}" || log_warning_msg "failure to \"umount ${snapback}\""
1140 if [ "${RES}" != "0" ]
1142 log_warning_msg "Impossible to include the ${snapfile} Snapshot file"
1145 elif [ -b "${snapdata}" ]
1147 # Try to find if it could be a snapshot partition
1149 log_success_msg "found snapshot ${snap_type} device on ${dev}"
1150 if echo "${dev}" | grep -qs loop
1152 # strange things happens, user confused?
1153 snaploop=$( losetup ${dev} | awk '{print $3}' | tr -d '()' )
1154 snapfile=$(basename ${snaploop})
1155 snapdev=$(awk -v pat="$( dirname ${snaploop})" '$2 == pat { print $1 }' /proc/mounts)
1160 if ! do_snap_copy "${dev}" "${snap_mount}" "${snap_type}"
1162 log_warning_msg "Impossible to include the ${snap_type} Snapshot"
1165 if [ -n "${snapfile}" ]
1167 # it was a loop device, user confused
1172 log_warning_msg "Impossible to include the ${snap_type} Snapshot"
1176 echo "export ${snap_type}SNAP="/cow${snap_mount#$rootmnt}":${snapdev}:${snapfile}" >> /etc/live.conf # for resync on reboot/halt
1182 image_directory="${1}"
1184 addimage_directory="${3}"
1186 case ${UNIONTYPE} in
1188 modprobe -q -b ${UNIONTYPE}
1190 if ! cut -f2 /proc/filesystems | grep -q "^${UNIONTYPE}\$" && [ -x /bin/unionfs-fuse ]
1192 echo "${UNIONTYPE} not available, falling back to unionfs-fuse."
1193 echo "This might be really slow."
1195 UNIONTYPE="unionfs-fuse"
1200 if [ "${UNIONTYPE}" = unionfs-fuse ]
1205 # run-init can't deal with images in a subdir, but we're going to
1206 # move all of these away before it runs anyway. No, we're not,
1207 # put them in / since move-mounting them into / breaks mono and
1212 # Let's just mount the read-only file systems first
1216 if [ "${UNIONTYPE}" = "aufs" ]
1219 noxino_opt="noxino,"
1220 elif [ "${UNIONTYPE}" = "unionfs-fuse" ]
1227 if [ -z "${PLAIN_ROOT}" ]
1229 # Read image names from ${MODULE}.module if it exists
1230 if [ -e "${image_directory}/filesystem.${MODULE}.module" ]
1232 for IMAGE in $(cat ${image_directory}/filesystem.${MODULE}.module)
1234 image_string="${image_string} ${image_directory}/${IMAGE}"
1236 elif [ -e "${image_directory}/${MODULE}.module" ]
1238 for IMAGE in $(cat ${image_directory}/${MODULE}.module)
1240 image_string="${image_string} ${image_directory}/${IMAGE}"
1243 # ${MODULE}.module does not exist, create a list of images
1244 for FILESYSTEM in squashfs ext2 ext3 ext4 xfs jffs2 dir
1246 for IMAGE in "${image_directory}"/*."${FILESYSTEM}"
1248 if [ -e "${IMAGE}" ]
1250 image_string="${image_string} ${IMAGE}"
1255 if [ -n "${addimage_directory}" ] && [ -d "${addimage_directory}" ]
1257 for FILESYSTEM in squashfs ext2 ext3 ext4 xfs jffs2 dir
1259 for IMAGE in "${addimage_directory}"/*."${FILESYSTEM}"
1261 if [ -e "${IMAGE}" ]
1263 image_string="${image_string} ${IMAGE}"
1270 image_string="$(echo ${image_string} | sed -e 's/ /\n/g' | sort )"
1273 [ -n "${MODULETORAMFILE}" ] && image_string="${image_directory}/$(basename ${MODULETORAMFILE})"
1277 for image in ${image_string}
1279 imagename=$(basename "${image}")
1281 export image devname
1282 maybe_break live-realpremount
1283 log_begin_msg "Running /scripts/live-realpremount"
1284 run_scripts /scripts/live-realpremount
1287 if [ -d "${image}" ]
1289 # it is a plain directory: do nothing
1290 rofsstring="${image}=${roopt}:${rofsstring}"
1291 rofslist="${image} ${rofslist}"
1292 elif [ -f "${image}" ]
1294 if losetup --help 2>&1 | grep -q -- "-r\b"
1296 backdev=$(get_backing_device "${image}" "-r")
1298 backdev=$(get_backing_device "${image}")
1300 fstype=$(get_fstype "${backdev}")
1302 if [ "${fstype}" = "unknown" ]
1304 panic "Unknown file system type on ${backdev} (${image})"
1307 if [ -z "${fstype}" ]
1309 fstype="${imagename##*.}"
1310 log_warning_msg "Unknown file system type on ${backdev} (${image}), assuming ${fstype}."
1313 mkdir -p "${croot}/${imagename}"
1314 log_begin_msg "Mounting \"${image}\" on \"${croot}${imagename}\" via \"${backdev}\""
1315 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}"
1320 # we have a plain root system
1321 mkdir -p "${croot}/filesystem"
1322 log_begin_msg "Mounting \"${image_directory}\" on \"${croot}/filesystem\""
1323 mount -t $(get_fstype "${image_directory}") -o ro,noatime "${image_directory}" "${croot}/filesystem" || panic "Can not mount ${image_directory} on ${croot}/filesystem" && rofsstring="${croot}/filesystem=${roopt}:${rofsstring}" && rofslist="${croot}/filesystem ${rofslist}"
1325 mount -o bind ${croot}/filesystem $mountpoint
1329 rofsstring=${rofsstring%:}
1333 # Looking for "${root_persistence}" device or file
1334 if [ -n "${PERSISTENT}" ] && [ -z "${NOPERSISTENT}" ]
1336 if [ -z "${QUICKUSBMODULES}" ]
1339 num_block=$(ls -l /sys/block | wc -l)
1340 for module in sd_mod uhci-hcd ehci-hcd ohci-hcd usb-storage
1342 modprobe -q -b ${module}
1348 # For some reason, udevsettle does not block in this scenario,
1349 # so we sleep for a little while.
1351 # See https://bugs.launchpad.net/ubuntu/+source/casper/+bug/84591
1352 for timeout in 5 4 3 2 1
1356 if [ $(ls -l /sys/block | wc -l) -gt ${num_block} ]
1363 # search for label and files (this could be hugely optimized)
1364 cowprobe=$(find_cow_device "${root_persistence}")
1365 if [ -b "${cowprobe}" ]
1367 # Blacklist /cow device, to avoid inconsistent setups for overlapping snapshots
1368 # makes sense to have both persistence for /cow and /home mounted, maybe also with
1369 # snapshots to be sure to really store some e.g key config files,
1370 # but not on the same media
1371 blacklistdev="${cowprobe}"
1372 PERSISTENCE_IS_ON="1"
1373 export PERSISTENCE_IS_ON
1375 # homecow just mount something on /home, this should be generalized some way
1376 homecow=$(find_cow_device "${home_persistence}" "${blacklistdev}")
1377 if [ -b "${homecow}" ]
1379 PERSISTENCE_IS_ON="1"
1380 export PERSISTENCE_IS_ON
1382 root_snapdata=$(find_snap "${root_snapshot_label}" "${blacklistdev}")
1383 # This second type should be removed when snapshot will get smarter,
1384 # hence when "/etc/live-snapshot*list" will be supported also by
1385 # ext2|ext3|ext4|jffs2 snapshot types.
1386 home_snapdata=$(find_snap "${home_snapshot_label}" "${blacklistdev}")
1388 if [ -b "${cowprobe}" ]
1390 cowdevice=${cowprobe}
1391 cow_fstype=$(get_fstype "${cowprobe}")
1392 cow_mountopt="rw,noatime"
1394 if [ "${FORCEPERSISTENTFSCK}" = "Yes" ]
1396 fsck -y ${cowdevice}
1399 log_warning_msg "Unable to find the persistent medium"
1402 cow_mountopt="rw,noatime,mode=755"
1404 elif [ -n "${NFS_COW}" ] && [ -z "${NOPERSISTENT}" ]
1406 # check if there are any nfs options
1407 if echo ${NFS_COW}|grep -q ','
1409 nfs_cow_opts="-o nolock,$(echo ${NFS_COW}|cut -d, -f2-)"
1410 nfs_cow=$(echo ${NFS_COW}|cut -d, -f1)
1412 nfs_cow_opts="-o nolock"
1418 cowdevice=$(echo ${nfs_cow}|sed "s/client_mac_address/${mac}/")
1421 panic "unable to determine mac address"
1426 cow_mountopt="rw,noatime,mode=755"
1429 if [ "${cow_fstype}" = "nfs" ]
1432 "Trying nfsmount ${nfs_cow_opts} ${cowdevice} /cow"
1433 nfsmount ${nfs_cow_opts} ${cowdevice} /cow || \
1434 panic "Can not mount ${cowdevice} (n: ${cow_fstype}) on /cow"
1436 mount -t ${cow_fstype} -o ${cow_mountopt} ${cowdevice} /cow || \
1437 panic "Can not mount ${cowdevice} (o: ${cow_fstype}) on /cow"
1440 rofscount=$(echo ${rofslist} |wc -w)
1442 if [ -n "${EXPOSED_ROOT}" ]
1444 if [ ${rofscount} -ne 1 ]
1446 panic "only one RO file system supported with exposedroot: ${rofslist}"
1448 exposedrootfs=${rofslist%% }
1450 mount --bind ${exposedrootfs} ${rootmnt} || \
1451 panic "bind mount of ${exposedrootfs} failed"
1453 if [ -z "${SKIP_UNION_MOUNTS}" ]
1455 cow_dirs='/var/tmp /var/lock /var/run /var/log /var/spool /home /var/lib/live'
1460 for dir in ${cow_dirs}; do
1463 case "${UNIONTYPE}" in
1465 (ulimit -n 16384; unionfs-fuse -o cow -o noinitgroups -o default_permissions -o allow_other -o use_ino -o suid /cow=RW:${exposedrootfs}${dir} "${rootmnt}${dir}" || panic "mount ${UNIONTYPE} on ${rootmnt}${dir} failed with option cow,noinitgroups,default_permissions,allow_other,use_ino,suid=/cow=RW:${exposedrootfs}${dir}")
1466 mkdir -p /dev/.initramfs/varrun
1467 pidof unionfs-fuse >> /dev/.initramfs/varrun/sendsigs.omit || true
1471 mount -t ${UNIONTYPE} -o rw,noatime,dirs=/cow${dir}=rw:${exposedrootfs}${dir}=ro ${UNIONTYPE} "${rootmnt}${dir}" || panic "mount ${UNIONTYPE} on ${rootmnt}${dir} failed with option rw,noatime,dirs=/cow${dir}=rw:${exposedrootfs}${dir}=ro"
1476 case "${UNIONTYPE}" in
1478 (ulimit -n 16384; unionfs-fuse -o cow -o noinitgroups -o default_permissions -o allow_other -o use_ino -o suid /cow=RW:${rofsstring} "${rootmnt}" || panic "mount ${UNIONTYPE} on ${rootmnt} failed with option cow,noinitgroups,default_permissions,allow_other,use_ino,suid=/cow:RW:${rofsstring}")
1479 mkdir -p /dev/.initramfs/varrun
1480 pidof unionfs-fuse >> /dev/.initramfs/varrun/sendsigs.omit || true
1484 mount -t ${UNIONTYPE} -o noatime,${noxino_opt}dirs=/cow=rw:${rofsstring} ${UNIONTYPE} "${rootmnt}" || panic "mount ${UNIONTYPE} on ${rootmnt} failed with option noatime,${noxino_opt}dirs=/cow=rw:${rofsstring}"
1489 # Correct the permissions of /:
1490 chmod 0755 "${rootmnt}"
1492 # tmpfs file systems
1494 mkdir -p "${rootmnt}/live"
1495 mount -t tmpfs tmpfs ${rootmnt}/live
1497 # Adding other custom mounts
1498 if [ -n "${PERSISTENT}" ] && [ -z "${NOPERSISTENT}" ]
1500 # directly mount /home
1501 # FIXME: add a custom mounts configurable system
1503 if [ -b "${homecow}" ]
1505 mount -t $(get_fstype "${homecow}") -o rw,noatime "${homecow}" "${rootmnt}/home"
1506 export HOMEMOUNTED=1 # used to proper calculate free space in do_snap_copy()
1508 log_warning_msg "Unable to find the persistent home medium"
1511 # Look for other snapshots to copy in
1512 try_snap "${root_snapdata}" "${rootmnt}" "ROOT"
1513 # This second type should be removed when snapshot grow smarter
1514 try_snap "${home_snapdata}" "${rootmnt}/home" "HOME"
1517 if [ -n "${SHOWMOUNTS}" ]
1519 for d in ${rofslist}
1521 mkdir -p "${rootmnt}/live/${d##*/}"
1525 # do nothing # mount -o bind "${d}" "${rootmnt}/live/${d##*/}"
1529 case "${UNIONTYPE}" in
1531 mount -o bind "${d}" "${rootmnt}/live/${d##*/}"
1535 mount -o move "${d}" "${rootmnt}/live/${d##*/}"
1543 # shows cow fs on /cow for use by live-snapshot
1544 mkdir -p "${rootmnt}/live/cow"
1545 mount -o move /cow "${rootmnt}/live/cow" >/dev/null 2>&1 || mount -o bind /cow "${rootmnt}/live/cow" || log_warning_msg "Unable to move or bind /cow to ${rootmnt}/live/cow"
1552 skip_uuid_check="${3}"
1554 # support for fromiso=.../isofrom=....
1555 if [ -n "$FROMISO" ]
1557 ISO_DEVICE=$(dirname $FROMISO)
1558 if ! [ -b $ISO_DEVICE ]
1560 # to support unusual device names like /dev/cciss/c0d0p1
1561 # as well we have to identify the block device name, let's
1562 # do that for up to 15 levels
1564 while [ -n "$ISO_DEVICE" ] && [ "$i" -gt 0 ]
1566 ISO_DEVICE=$(dirname ${ISO_DEVICE})
1567 [ -b "$ISO_DEVICE" ] && break
1572 if [ "$ISO_DEVICE" = "/" ]
1574 echo "Warning: device for bootoption isofrom= ($FROMISO) not found.">>/live.log
1577 mount "$ISO_DEVICE" /isofrom
1578 ISO_NAME="$(echo $FROMISO | sed "s|$ISO_DEVICE||")"
1579 loopdevname=$(setup_loop "/isofrom/${ISO_NAME}" "loop" "/sys/block/loop*" "" '')
1580 devname="${loopdevname}"
1584 if [ -z "${devname}" ]
1586 devname=$(sys2dev "${sysdev}")
1589 if [ -d "${devname}" ]
1591 mount -o bind "${devname}" $mountpoint || continue
1593 if is_live_path $mountpoint
1601 [ -e "$devname" ] || continue
1603 if [ -n "${LIVE_MEDIA_OFFSET}" ]
1605 loopdevname=$(setup_loop "${devname}" "loop" "/sys/block/loop*" "${LIVE_MEDIA_OFFSET}" '')
1606 devname="${loopdevname}"
1609 fstype=$(get_fstype "${devname}")
1611 if is_supported_fs ${fstype}
1613 devuid=$(blkid -o value -s UUID "$devname")
1614 [ -n "$devuid" ] && grep -qs "\<$devuid\>" $tried && continue
1615 mount -t ${fstype} -o ro,noatime "${devname}" ${mountpoint} || continue
1616 [ -n "$devuid" ] && echo "$devuid" >> $tried
1618 if is_live_path ${mountpoint} && \
1619 ([ "${skip_uuid_check}" ] || matches_uuid ${mountpoint})
1624 umount ${mountpoint}
1628 if [ -n "${LIVE_MEDIA_OFFSET}" ]
1630 losetup -d "${loopdevname}"
1640 # don't start autodetection before timeout has expired
1641 if [ -n "${LIVE_MEDIA_TIMEOUT}" ]
1643 if [ "${timeout}" -lt "${LIVE_MEDIA_TIMEOUT}" ]
1649 # first look at the one specified in the command line
1650 case "${LIVE_MEDIA}" in
1652 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -vE "/(loop|ram|dm-|fd)")
1654 if [ "$(cat ${sysblock}/removable)" = "1" ]
1656 if readlink ${sysblock} | grep -q usb ||
1657 readlink ${sysblock}/device | grep -q usb # linux < 2.6.29
1659 for dev in $(subdevices "${sysblock}")
1661 if check_dev "${dev}"
1673 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -vE "/(loop|ram|dm-|fd)")
1675 if [ "$(cat ${sysblock}/removable)" = "1" ]
1677 for dev in $(subdevices "${sysblock}")
1679 if check_dev "${dev}"
1690 if [ ! -z "${LIVE_MEDIA}" ]
1692 if check_dev "null" "${LIVE_MEDIA}" "skip_uuid_check"
1700 # or do the scan of block devices
1701 # prefer removable devices over non-removable devices, so scan them first
1702 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | egrep -v "/(loop|ram|dm-|fd)")
1704 if [ "$(cat ${sysblock}/removable)" = "1" ]
1706 removable_devices_to_scan="$removable_devices_to_scan $sysblock"
1708 nonremovable_devices_to_scan="$nonremovable_devices_to_scan $sysblock"
1711 devices_to_scan="$removable_devices_to_scan $nonremovable_devices_to_scan"
1713 for sysblock in $devices_to_scan
1715 devname=$(sys2dev "${sysblock}")
1716 [ -e "$devname" ] || continue
1717 fstype=$(get_fstype "${devname}")
1719 if /lib/udev/cdrom_id ${devname} > /dev/null
1721 if check_dev "null" "${devname}"
1725 elif is_nice_device "${sysblock}"
1727 for dev in $(subdevices "${sysblock}")
1729 if check_dev "${dev}"
1734 elif [ "${fstype}" = "squashfs" -o \
1735 "${fstype}" = "ext2" -o \
1736 "${fstype}" = "ext3" -o \
1737 "${fstype}" = "ext4" -o \
1738 "${fstype}" = "jffs2" ]
1740 # This is an ugly hack situation, the block device has
1741 # an image directly on it. It's hopefully
1742 # live-initramfs, so take it and run with it.
1743 ln -s "${devname}" "${devname}.${fstype}"
1744 echo "${devname}.${fstype}"
1752 set_usplash_timeout ()
1754 if [ -x /sbin/usplash_write ]
1756 /sbin/usplash_write "TIMEOUT 120"
1757 else if [ -x /sbin/splashy_update ] ; then
1758 /sbin/splashy_update "TIMEOUT 120"
1764 media_mountpoint="${1}"
1766 log_begin_msg "Checking media integrity"
1768 cd ${media_mountpoint}
1769 /bin/md5sum -c md5sum.txt < /dev/tty8 > /dev/tty8
1774 if [ "${RC}" -eq 0 ]
1776 log_success_msg "Everything ok, will reboot in 10 seconds."
1779 umount ${media_mountpoint}
1781 echo u > /proc/sysrq-trigger
1782 echo b > /proc/sysrq-trigger
1784 panic "Not ok, a media defect is likely, switch to VT8 for details."
1788 start_usplash_pulse ()
1790 if [ -x /sbin/usplash_write ]
1792 /sbin/usplash_write "PULSELOGO"
1798 if [ -x /scripts/local-top/cryptroot ]; then
1799 /scripts/local-top/cryptroot
1806 tail -f live.log >&7 &
1809 # Ensure 'panic' function is overridden
1810 . /scripts/live-functions
1817 maybe_break live-premount
1818 log_begin_msg "Running /scripts/live-premount"
1819 run_scripts /scripts/live-premount
1822 # Needed here too because some things (*cough* udev *cough*)
1823 # changes the timeout
1827 if [ ! -z "${NETBOOT}" ] || [ ! -z "${FETCH}" ] || [ ! -z "${HTTPFS}" ] || [ ! -z "${FTPFS}" ]
1831 livefs_root="${mountpoint}"
1833 panic "Unable to find a live file system on the network"
1836 if [ -n "${PLAIN_ROOT}" ] && [ -n "${ROOT}" ]
1838 # Do a local boot from hd
1841 # Scan local devices for the image
1843 while [ "$i" -lt 60 ]
1845 livefs_root=$(find_livefs ${i})
1847 if [ -n "${livefs_root}" ]
1858 if [ -z "${livefs_root}" ]
1860 panic "Unable to find a medium containing a live file system"
1863 if [ "${INTEGRITY_CHECK}" ]
1865 integrity_check "${livefs_root}"
1871 elif [ "${TODISK}" ]
1873 live_dest="${TODISK}"
1876 if [ "${live_dest}" ]
1878 log_begin_msg "Copying live media to ${live_dest}"
1879 copy_live_to "${livefs_root}" "${live_dest}"
1883 # if we do not unmount the ISO we can't run "fsck /dev/ice" later on
1884 # because the mountpoint is left behind in /proc/mounts, so let's get
1885 # rid of it when running from RAM
1886 if [ -n "$FROMISO" ] && [ "${TORAM}" ]
1888 losetup -d /dev/loop0
1889 grep -q /isofrom /proc/mounts && umount /isofrom
1892 if [ -n "${MODULETORAMFILE}" ] || [ -n "${PLAIN_ROOT}" ]
1894 setup_unionfs "${livefs_root}" "${rootmnt}"
1897 mac="$(echo ${mac} | sed 's/-//g')"
1898 mount_images_in_directory "${livefs_root}" "${rootmnt}" "${mac}"
1903 # unionfs-fuse needs /dev to be bind-mounted for the duration of
1904 # live-bottom; udev's init script will take care of things after that
1905 if [ "${UNIONTYPE}" = unionfs-fuse ]
1907 mount -n -o bind /dev "${rootmnt}/dev"
1910 # Open up two fifo's fd's for debconf-communicate to use. Speeds up
1911 # the live-initramfs process considerably.
1912 log_begin_msg "Creating debconf-communicate fifo mechanism"
1913 mkfifo /tmp/debconf-in.fifo
1914 mkfifo /tmp/debconf-out.fifo
1916 # Make the template database read-only, so that passthrough debconf
1917 # instances can write to it directly; otherwise templates are only
1918 # passed through when necessary. Use temporary config databases as
1919 # well; we'll copy their contents back at the end.
1920 DEBCONF_TMPDIR="$(chroot /root mktemp -dt debconf.XXXXXX)"
1921 cp -a /root/var/cache/debconf/config.dat "/root$DEBCONF_TMPDIR/"
1922 cp -a /root/var/cache/debconf/passwords.dat "/root$DEBCONF_TMPDIR/"
1923 sed "s,^Filename: /var/cache/debconf/\(config\|passwords\).dat$,Filename: $DEBCONF_TMPDIR/\1.dat,; /^Name: templatedb/a\
1924 +Readonly: true" /root/etc/debconf.conf >"/root$DEBCONF_TMPDIR/debconf.conf"
1926 # Save the PID so it can be killed later.
1927 DEBCONF_SYSTEMRC="$DEBCONF_TMPDIR/debconf.conf" chroot /root debconf-communicate -fnoninteractive live-initramfs > /tmp/debconf-out.fifo < /tmp/debconf-in.fifo &
1929 if [ ! -p /tmp/debconf-in.fifo ] || [ ! -p /tmp/debconf-out.fifo ]
1931 log_warning_msg "failed to setup debconf-communicate channel"
1936 # These file descriptors must stay open until we're finished with
1937 # debconf-communicate.
1938 exec 4</tmp/debconf-out.fifo 3>/tmp/debconf-in.fifo
1940 maybe_break live-bottom
1941 log_begin_msg "Running /scripts/live-bottom\n"
1943 run_scripts /scripts/live-bottom
1946 if [ "${UNIONFS}" = unionfs-fuse ]
1948 umount "${rootmnt}/dev"
1951 # Close the fd's associated with debconf-communicate
1953 rm -f /tmp/debconf-in.fifo
1954 rm -f /tmp/debconf-out.fifo
1956 # Copy config database changes back to the master files.
1957 chroot /root debconf-copydb tmpdb config \
1958 --config=Name:tmpdb --config=Driver:File \
1959 --config="Filename:$DEBCONF_TMPDIR/config.dat"
1960 chroot /root debconf-copydb tmpdb passwords \
1961 --config=Name:tmpdb --config=Driver:File \
1962 --config="Filename:$DEBCONF_TMPDIR/passwords.dat"
1963 rm -rf "$DEBCONF_TMPDIR"
1968 [ -w "${rootmnt}/var/log/" ] && cp live.log "${rootmnt}/var/log/" 2>/dev/null
1969 if [ -f /etc/live.conf ]
1971 cp /etc/live.conf "${rootmnt}/etc/"