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 # Create /etc/mtab for debug purpose and future syncs
35 [ -f /etc/live.conf ] && . /etc/live.conf
36 export USERNAME USERFULLNAME HOSTNAME
38 . /scripts/live-helpers
40 if [ ! -f /live.vars ]
49 for ARGUMENT in $(cat /proc/cmdline)
57 NOCONSOLEKEYBOARD="Yes"
64 NOLANGUAGESELECTOR="Yes"
68 NOPOWERMANAGEMENT="Yes"
69 NOPROGRAMCRASHES="Yes"
72 NOUPDATENOTIFIER="Yes"
78 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
82 ACCESS="${ARGUMENT#access=}"
87 DEFCONSOLE="${ARGUMENT#*=}"
99 DEVICE="${ARGUMENT#ethdevice=}"
104 FETCH="${ARGUMENT#fetch=}"
109 FORCEPERSISTENTFSCK="Yes"
110 export FORCEPERSISTENTFSCK
114 HOOK="${ARGUMENT#hook=}"
119 FTPFS="${ARGUMENT#ftpfs=}"
124 HTTPFS="${ARGUMENT#httpfs=}"
129 HOSTNAME="${ARGUMENT#hostname=}"
131 export HOSTNAME LIVECONF
135 FROMISO="${ARGUMENT#*=}"
140 USERNAME="${ARGUMENT#username=}"
142 export USERNAME LIVECONF
146 USERFULLNAME="${ARGUMENT#userfullname=}"
148 export USERFULLNAME LIVECONF
157 INTEGRITY_CHECK="Yes"
158 export INTEGRITY_CHECK
162 STATICIP="${ARGUMENT#ip=}"
164 if [ -z "${STATICIP}" ]
172 keyb=*|kbd-chooser/method=*)
177 klayout=*|console-setup/layoutcode=*)
178 KLAYOUT="${ARGUMENT#*=}"
182 kvariant=*|console-setup/variantcode=*)
183 KVARIANT="${ARGUMENT#*=}"
187 kmodel=*|console-setup/modelcode=*)
188 KMODEL="${ARGUMENT#*=}"
193 KOPTIONS="${ARGUMENT#koptions=}"
202 live-media=*|bootfrom=*)
203 LIVE_MEDIA="${ARGUMENT#*=}"
207 live-media-encryption=*|encryption=*)
208 LIVE_MEDIA_ENCRYPTION="${ARGUMENT#*=}"
209 export LIVE_MEDIA_ENCRYPTION
213 LIVE_MEDIA_OFFSET="${ARGUMENT#live-media-offset=}"
214 export LIVE_MEDIA_OFFSET
218 LIVE_MEDIA_PATH="${ARGUMENT#live-media-path=}"
219 export LIVE_MEDIA_PATH
222 live-media-timeout=*)
223 LIVE_MEDIA_TIMEOUT="${ARGUMENT#live-media-timeout=}"
224 export LIVE_MEDIA_TIMEOUT
227 language=*|debian-installer/language=*)
228 language=${x#debian-installer/language=}
229 locale="$(lang2locale "$language")"
233 locale=*|debian-installer/locale=*)
234 LOCALE="${ARGUMENT#*=}"
239 MODULE="${ARGUMENT#module=}"
244 NETBOOT="${ARGUMENT#netboot=}"
249 NFSOPTS="${ARGUMENT#nfsopts=}"
254 NFS_COW="${ARGUMENT#nfscow=}"
259 NOACCESSIBILITY="Yes"
260 export NOACCESSIBILITY
284 NOCONSOLEKEYBOARD="Yes"
285 export NOCONSOLEKEYBOARD
309 NOKPERSONALIZER="Yes"
310 export NOKPERSONALIZER
314 NOLANGUAGESELECTOR="Yes"
315 export NOLANGUAGESELECTOR
329 NOPOWERMANAGEMENT="Yes"
330 export NOPOWERMANAGEMENT
334 NOPROGRAMCRASHES="Yes"
335 export NOPROGRAMCRASHES
354 NOUPDATENOTIFIER="Yes"
355 export NOUPDATENOTIFIER
370 export NOXSCREENSAVER
379 PERSISTENT="${ARGUMENT#persistent=}"
380 if [ -z "${PERSISTENT}" ]
388 PERSISTENT_PATH="${ARGUMENT#persistent-path=}"
389 export PERSISTENT_PATH
392 persistent-subtext=*)
393 root_persistence="${root_persistence}-${ARGUMENT#persistent-subtext=}"
394 home_persistence="${home_persistence}-${ARGUMENT#persistent-subtext=}"
395 root_snapshot_label="${root_snapshot_label}-${ARGUMENT#persistent-subtext=}"
396 home_snapshot_label="${home_snapshot_label}-${ARGUMENT#persistent-subtext=}"
405 QUICKUSBMODULES="Yes"
406 export QUICKUSBMODULES
409 preseed/file=*|file=*)
410 LOCATION="${ARGUMENT#*=}"
420 location="${ARGUMENT#url=}"
422 mount -o bind /sys /root/sys
423 mount -o bind /proc /root/proc
424 mount -o bind /dev /root/dev
426 mkdir -p /root/var/run/network
427 [ "${NETBOOT}" ] || chroot /root dhclient eth0
428 chroot /root wget -P /tmp "${location}"
429 [ "${NETBOOT}" ] || chroot /root ifconfig eth0 down
435 LOCATION="/tmp/$(basename "${location}")"
439 question="${ARGUMENT%%=*}"
440 value="${ARGUMENT#*=}"
441 PRESEEDS="${PRESEEDS}\"${question}=${value}\" "
461 TIMEZONE="${ARGUMENT#timezone=}"
471 TODISK="${ARGUMENT#todisk=}"
482 MODULETORAM="${ARGUMENT#toram=}"
483 export TORAM MODULETORAM
497 SKIP_UNION_MOUNTS="Yes"
498 export SKIP_UNION_MOUNTS
502 ROOT="${ARGUMENT#root=}"
507 UNIONTYPE="${ARGUMENT#union=}"
512 UTC="${ARGUMENT#utc=}"
522 XDRIVER="${ARGUMENT#xdriver=}"
527 XVIDEOMODE="${ARGUMENT#xvideomode=}"
533 # sort of compatibility with netboot.h from linux docs
534 if [ -z "${NETBOOT}" ]
536 if [ "${ROOT}" = "/dev/nfs" ]
540 elif [ "${ROOT}" = "/dev/cifs" ]
547 if [ -z "${MODULE}" ]
553 if [ -z "${UNIONTYPE}" ]
564 if [ -d "${DIRECTORY}"/"${LIVE_MEDIA_PATH}" ]
566 for FILESYSTEM in squashfs ext2 ext3 ext4 xfs dir jffs2
568 if [ "$(echo ${DIRECTORY}/${LIVE_MEDIA_PATH}/*.${FILESYSTEM})" != "${DIRECTORY}/${LIVE_MEDIA_PATH}/*.${FILESYSTEM}" ]
580 if [ "${IGNORE_UUID}" ] || [ ! -e /conf/uuid.conf ]
586 uuid="$(cat /conf/uuid.conf)"
588 for try_uuid_file in "${path}/.disk/live-uuid"*
590 [ -e "${try_uuid_file}" ] || continue
592 try_uuid="$(cat "${try_uuid_file}")"
594 if [ "${uuid}" = "${try_uuid}" ]
603 get_backing_device ()
606 *.squashfs|*.ext2|*.ext3|*.ext4|*.jffs2)
607 echo $(setup_loop "${1}" "loop" "/sys/block/loop*" '0' "${LIVE_MEDIA_ENCRYPTION}" "${2}")
615 panic "Unrecognized live filesystem: ${1}"
620 match_files_in_dir ()
622 # Does any files match pattern ${1} ?
625 if [ "$(echo ${pattern})" != "${pattern}" ]
633 mount_images_in_directory ()
640 if match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.squashfs" ||
641 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.ext2" ||
642 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.ext3" ||
643 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.ext4" ||
644 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.jffs2" ||
645 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.dir"
647 [ -n "${mac}" ] && adddirectory="${directory}/${LIVE_MEDIA_PATH}/${mac}"
648 setup_unionfs "${directory}/${LIVE_MEDIA_PATH}" "${rootmnt}" "${adddirectory}"
650 panic "No supported filesystem images found at /${LIVE_MEDIA_PATH}."
656 sysfs_path="${1#/sys}"
658 if /lib/udev/path_id "${sysfs_path}" | grep -E -q "ID_PATH=(usb|pci-|platform-mmc)"
661 elif echo "${sysfs_path}" | grep -q '^/block/vd[a-z]$'
673 copyto="${copyfrom}_swap"
675 if [ -z "${MODULETORAM}" ]
677 size=$(fs_size "" ${copyfrom}/${LIVE_MEDIA_PATH} "used")
679 MODULETORAMFILE="${copyfrom}/${LIVE_MEDIA_PATH}/${MODULETORAM}"
681 if [ -f "${MODULETORAMFILE}" ]
683 size=$( expr $(ls -la ${MODULETORAMFILE} | awk '{print $5}') / 1024 + 5000 )
685 log_warning_msg "Error: toram-module ${MODULETORAM} (${MODULETORAMFILE}) could not be read."
690 if [ "${copytodev}" = "ram" ]
693 freespace=$( expr $(awk '/MemFree/{print $2}' /proc/meminfo) + $( awk '/\<Cached/{print $2}' /proc/meminfo ) )
694 mount_options="-o size=${size}k"
699 # it should be a writable block device
700 if [ -b "${copytodev}" ]
704 fstype=$(get_fstype "${dev}")
705 freespace=$(fs_size "${dev}")
707 log_warning_msg "${copytodev} is not a block device."
712 if [ "${freespace}" -lt "${size}" ]
714 log_warning_msg "Not enough free ${free_string} (${freespace}k free, ${size}k needed) to copy live media in ${copytodev}."
718 # begin copying (or uncompressing)
720 log_begin_msg "mount -t ${fstype} ${mount_options} ${dev} ${copyto}"
721 mount -t "${fstype}" ${mount_options} "${dev}" "${copyto}"
723 if [ "${extension}" = "tgz" ]
726 tar zxf "${copyfrom}/${LIVE_MEDIA_PATH}/$(basename ${FETCH})"
727 rm -f "${copyfrom}/${LIVE_MEDIA_PATH}/$(basename ${FETCH})"
728 mount -r -o move "${copyto}" "${rootmnt}"
731 if [ -n "${MODULETORAMFILE}" ]
735 echo " * Copying $MODULETORAMFILE to RAM" 1>/dev/console
736 rsync -a --progress ${MODULETORAMFILE} ${copyto} 1>/dev/console # copy only the filesystem module
738 cp ${MODULETORAMFILE} ${copyto} # copy only the filesystem module
743 echo " * Copying whole medium to RAM" 1>/dev/console
744 rsync -a --progress ${copyfrom}/* ${copyto} 1>/dev/console # "cp -a" from busybox also copies hidden files
746 mkdir -p ${copyto}/${LIVE_MEDIA_PATH}
747 cp -a ${copyfrom}/${LIVE_MEDIA_PATH}/* ${copyto}/${LIVE_MEDIA_PATH} # "cp -a" from busybox also copies hidden files
752 mount -r -o move ${copyto} ${copyfrom}
763 modprobe -q af_packet # For DHCP
768 ipconfig ${DEVICE} | tee /netboot.config
770 # source relevant ipconfig output
771 OLDHOSTNAME=${HOSTNAME}
772 . /tmp/net-${DEVICE}.conf
773 [ -z ${HOSTNAME} ] && HOSTNAME=${OLDHOSTNAME}
776 # Check if we have a network device at all
777 if ! ls /sys/class/net/eth0 > /dev/null 2>&1 && \
778 ! ls /sys/class/net/wlan0 > /dev/null 2>&1 && \
779 ! ls /sys/class/net/ath0 > /dev/null 2>&1 && \
780 ! ls /sys/class/net/ra0 > /dev/null 2>&1
782 panic "No supported network device found, maybe a non-mainline driver is required."
785 if [ "${NFSROOT}" = "auto" ]
787 NFSROOT=${ROOTSERVER}:${ROOTPATH}
790 if ( [ -n "${FETCH}" ] || [ -n "${HTTPFS}" ] || [ -n "${FTPFS}" ] ) && do_httpmount
796 if [ "${NFSROOT#*:}" = "${NFSROOT}" ] && [ "$NETBOOT" != "cifs" ]
798 NFSROOT=${ROOTSERVER}:${NFSROOT}
801 log_begin_msg "Trying netboot from ${NFSROOT}"
803 if [ "${NETBOOT}" != "nfs" ] && do_cifsmount
820 dest="${mountpoint}/${LIVE_MEDIA_PATH}"
821 mount -t ramfs ram "${mountpoint}"
824 for webfile in HTTPFS FTPFS FETCH
826 url="$(eval echo \"\$\{${webfile}\}\")"
827 extension="$(echo "${url}" | sed 's/\(.*\)\.\(.*\)/\2/')"
831 case "${extension}" in
833 if [ "${webfile}" = "FETCH" ]
837 ip="$(dirname $url | sed -e 's|tftp://||g' -e 's|/.*$||g')"
838 rfile="$(echo $url | sed -e "s|tftp://$ip||g")"
839 lfile="$(basename $url)"
840 log_begin_msg "Trying tftp -g -b 10240 -r $rfile -l ${dest}/$lfile $ip"
841 tftp -g -b 10240 -r $rfile -l ${dest}/$lfile $ip
845 log_begin_msg "Trying wget ${url} -O ${dest}/$(basename ${url})"
846 wget "${url}" -O "${dest}/$(basename ${url})"
850 log_begin_msg "Trying to mount ${url} on ${dest}/$(basename ${url})"
851 if [ "${webfile}" = "FTPFS" ]
853 FUSE_MOUNT="curlftpfs"
854 url="$(dirname ${url})"
859 $FUSE_MOUNT "${url}" "${dest}"
861 [ ${?} -eq 0 ] && rc=0
862 [ "${extension}" = "tgz" ] && live_dest="ram"
867 log_begin_msg "Unrecognized archive extension for ${url}"
875 umount "${mountpoint}"
887 if [ -z "${NFSOPTS}" ]
892 log_begin_msg "Trying nfsmount -o nolock -o ro ${NFSOPTS} ${NFSROOT} ${mountpoint}"
894 # FIXME: This while loop is an ugly HACK round an nfs bug
896 while [ "$i" -lt 60 ]
898 nfsmount -o nolock -o ro ${NFSOPTS} "${NFSROOT}" "${mountpoint}" && rc=0 && break
910 if [ -x "/sbin/mount.cifs" ]
912 if [ -z "${NFSOPTS}" ]
914 CIFSOPTS="-ouser=root,password="
916 CIFSOPTS="${NFSOPTS}"
919 log_begin_msg "Trying mount.cifs ${NFSROOT} ${mountpoint} ${CIFSOPTS}"
922 if mount.cifs "${NFSROOT}" "${mountpoint}" "${CIFSOPTS}"
936 size=$(fs_size "${fromdev}" "" "used")
938 if [ -b "${fromdev}" ]
941 if [ -n "${HOMEMOUNTED}" -a "${snap_type}" = "HOME" ]
943 todev=$(awk -v pat="$(base_path ${todir})" '$2 == pat { print $1 }' /proc/mounts)
944 freespace=$(df -k | awk '/'${todev}'/{print $4}')
946 freespace=$( expr $(awk '/MemFree/{print $2}' /proc/meminfo) + $( awk '/\<Cached/{print $2}' /proc/meminfo))
949 tomount="/mnt/tmpsnap"
951 if [ ! -d "${tomount}" ]
953 mkdir -p "${tomount}"
956 fstype=$(get_fstype "${fromdev}")
958 if [ -n "${fstype}" ]
961 mount -o ro -t "${fstype}" "${fromdev}" "${tomount}" || log_warning_msg "Error in mount -t ${fstype} -o ro ${fromdev} ${tomount}"
962 cp -a "${tomount}"/* ${todir}
965 log_warning_msg "Unrecognized fstype: ${fstype} on ${fromdev}:${snap_type}"
970 if echo ${fromdev} | grep -qs loop
972 losetup -d "${fromdev}"
979 log_warning_msg "Unable to find the snapshot ${snap_type} medium"
985 # Look for ${snap_label}.* in block devices
988 if [ "${PERSISTENT}" != "nofiles" ]
990 # search for image files
991 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")
994 if [ -z "${snapdata}" ]
996 snapdata=$(find_cow_device "${snap_label}")
1003 # copy the contents of previously found snapshot to ${snap_mount}
1004 # and remember the device and filename for resync on exit in live-initramfs.init
1010 if [ -n "${snapdata}" ] && [ ! -b "${snapdata}" ]
1012 log_success_msg "found snapshot: ${snapdata}"
1013 snapdev="$(echo ${snapdata} | cut -f1 -d ' ')"
1014 snapback="$(echo ${snapdata} | cut -f2 -d ' ')"
1015 snapfile="$(echo ${snapdata} | cut -f3 -d ' ')"
1018 if ! try_mount "${snapdev}" "${snapback}" "ro"
1023 if echo "${snapfile}" | grep -qs '\(squashfs\|ext2\|ext3\|ext4\|jffs2\)'
1025 # squashfs, jffs2 or ext2/ext3/ext4 snapshot
1026 dev=$(get_backing_device "${snapback}/${snapfile}")
1028 do_snap_copy "${dev}" "${snap_mount}" "${snap_type}"
1033 zcat "${snapback}/${snapfile}" | /bin/cpio --extract --preserve-modification-time --no-absolute-filenames --sparse --unconditional --make-directories > /dev/null 2>&1
1035 if [ "${RES}" != "0" ]
1037 log_warning_msg "failure to \"zcat ${snapback}/${snapfile} | /bin/cpio --extract --preserve-modification-time --no-absolute-filenames --sparse --unconditional --make-directories\""
1042 umount "${snapback}" || log_warning_msg "failure to \"umount ${snapback}\""
1044 if [ "${RES}" != "0" ]
1046 log_warning_msg "Impossible to include the ${snapfile} Snapshot file"
1049 elif [ -b "${snapdata}" ]
1051 # Try to find if it could be a snapshot partition
1053 log_success_msg "found snapshot ${snap_type} device on ${dev}"
1054 if echo "${dev}" | grep -qs loop
1056 # strange things happens, user confused?
1057 snaploop=$( losetup ${dev} | awk '{print $3}' | tr -d '()' )
1058 snapfile=$(basename ${snaploop})
1059 snapdev=$(awk -v pat="$( dirname ${snaploop})" '$2 == pat { print $1 }' /proc/mounts)
1064 if ! do_snap_copy "${dev}" "${snap_mount}" "${snap_type}"
1066 log_warning_msg "Impossible to include the ${snap_type} Snapshot"
1069 if [ -n "${snapfile}" ]
1071 # it was a loop device, user confused
1076 log_warning_msg "Impossible to include the ${snap_type} Snapshot"
1080 echo "export ${snap_type}SNAP="${snap_mount}":${snapdev}:${snapfile}" >> /etc/live.conf # for resync on reboot/halt
1086 image_directory="${1}"
1088 addimage_directory="${3}"
1090 case ${UNIONTYPE} in
1092 modprobe -q -b ${UNIONTYPE}
1094 if ! cut -f2 /proc/filesystems | grep -q "^${UNIONTYPE}\$" && [ -x /bin/unionfs-fuse ]
1096 echo "${UNIONTYPE} not available, falling back to unionfs-fuse."
1097 echo "This might be really slow."
1099 UNIONTYPE="unionfs-fuse"
1104 if [ "${UNIONTYPE}" = unionfs-fuse ]
1109 # run-init can't deal with images in a subdir, but we're going to
1110 # move all of these away before it runs anyway. No, we're not,
1111 # put them in / since move-mounting them into / breaks mono and
1116 # Let's just mount the read-only file systems first
1120 if [ "${UNIONTYPE}" = "aufs" ]
1123 elif [ "${UNIONTYPE}" = "unionfs-fuse" ]
1130 if [ -z "${PLAIN_ROOT}" ]
1132 # Read image names from ${MODULE}.module if it exists
1133 if [ -e "${image_directory}/filesystem.${MODULE}.module" ]
1135 for IMAGE in $(cat ${image_directory}/filesystem.${MODULE}.module)
1137 image_string="${image_string} ${image_directory}/${IMAGE}"
1139 elif [ -e "${image_directory}/${MODULE}.module" ]
1141 for IMAGE in $(cat ${image_directory}/${MODULE}.module)
1143 image_string="${image_string} ${image_directory}/${IMAGE}"
1146 # ${MODULE}.module does not exist, create a list of images
1147 for FILESYSTEM in squashfs ext2 ext3 ext4 xfs jffs2 dir
1149 for IMAGE in "${image_directory}"/*."${FILESYSTEM}"
1151 if [ -e "${IMAGE}" ]
1153 image_string="${image_string} ${IMAGE}"
1158 if [ -n "${addimage_directory}" ] && [ -d "${addimage_directory}" ]
1160 for FILESYSTEM in squashfs ext2 ext3 ext4 xfs jffs2 dir
1162 for IMAGE in "${addimage_directory}"/*."${FILESYSTEM}"
1164 if [ -e "${IMAGE}" ]
1166 image_string="${image_string} ${IMAGE}"
1173 image_string="$(echo ${image_string} | sed -e 's/ /\n/g' | sort )"
1176 [ -n "${MODULETORAMFILE}" ] && image_string="${image_directory}/$(basename ${MODULETORAMFILE})"
1180 for image in ${image_string}
1182 imagename=$(basename "${image}")
1184 export image devname
1185 maybe_break live-realpremount
1186 log_begin_msg "Running /scripts/live-realpremount"
1187 run_scripts /scripts/live-realpremount
1190 if [ -d "${image}" ]
1192 # it is a plain directory: do nothing
1193 rofsstring="${image}=${roopt}:${rofsstring}"
1194 rofslist="${image} ${rofslist}"
1195 elif [ -f "${image}" ]
1197 if losetup --help 2>&1 | grep -q -- "-r\b"
1199 backdev=$(get_backing_device "${image}" "-r")
1201 backdev=$(get_backing_device "${image}")
1203 fstype=$(get_fstype "${backdev}")
1205 if [ "${fstype}" = "unknown" ]
1207 panic "Unknown file system type on ${backdev} (${image})"
1210 if [ -z "${fstype}" ]
1212 fstype="${imagename##*.}"
1213 log_warning_msg "Unknown file system type on ${backdev} (${image}), assuming ${fstype}."
1216 mkdir -p "${croot}/${imagename}"
1217 log_begin_msg "Mounting \"${image}\" on \"${croot}${imagename}\" via \"${backdev}\""
1218 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}"
1223 # we have a plain root system
1224 mkdir -p "${croot}/filesystem"
1225 log_begin_msg "Mounting \"${image_directory}\" on \"${croot}/filesystem\""
1226 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}"
1228 mount -o bind ${croot}/filesystem $mountpoint
1232 rofsstring=${rofsstring%:}
1236 # Looking for "${root_persistence}" device or file
1237 if [ -n "${PERSISTENT}" ] && [ -z "${NOPERSISTENT}" ]
1239 if [ -z "${QUICKUSBMODULES}" ]
1242 num_block=$(ls -l /sys/block | wc -l)
1243 for module in sd_mod uhci-hcd ehci-hcd ohci-hcd usb-storage
1245 modprobe -q -b ${module}
1251 # For some reason, udevsettle does not block in this scenario,
1252 # so we sleep for a little while.
1254 # See https://bugs.launchpad.net/ubuntu/+source/casper/+bug/84591
1255 for timeout in 5 4 3 2 1
1259 if [ $(ls -l /sys/block | wc -l) -gt ${num_block} ]
1266 # search for label and files (this could be hugely optimized)
1267 cowprobe=$(find_cow_device "${root_persistence}")
1268 if [ -b "${cowprobe}" ]
1270 # Blacklist /cow device, to avoid inconsistent setups for overlapping snapshots
1271 # makes sense to have both persistence for /cow and /home mounted, maybe also with
1272 # snapshots to be sure to really store some e.g key config files,
1273 # but not on the same media
1274 blacklistdev="${cowprobe}"
1275 PERSISTENCE_IS_ON="1"
1276 export PERSISTENCE_IS_ON
1278 # homecow just mount something on /home, this should be generalized some way
1279 homecow=$(find_cow_device "${home_persistence}" "${blacklistdev}")
1280 if [ -b "${homecow}" ]
1282 PERSISTENCE_IS_ON="1"
1283 export PERSISTENCE_IS_ON
1285 root_snapdata=$(find_snap "${root_snapshot_label}" "${blacklistdev}")
1286 # This second type should be removed when snapshot will get smarter,
1287 # hence when "/etc/live-snapshot*list" will be supported also by
1288 # ext2|ext3|ext4|jffs2 snapshot types.
1289 home_snapdata=$(find_snap "${home_snapshot_label}" "${blacklistdev}")
1291 if [ -b "${cowprobe}" ]
1293 cowdevice=${cowprobe}
1294 cow_fstype=$(get_fstype "${cowprobe}")
1295 cow_mountopt="rw,noatime"
1297 if [ "${FORCEPERSISTENTFSCK}" = "Yes" ]
1299 fsck -y ${cowdevice}
1302 log_warning_msg "Unable to find the persistent medium"
1305 cow_mountopt="rw,noatime,mode=755"
1307 elif [ -n "${NFS_COW}" ] && [ -z "${NOPERSISTENT}" ]
1309 # check if there are any nfs options
1310 if echo ${NFS_COW}|grep -q ','
1312 nfs_cow_opts="-o nolock,$(echo ${NFS_COW}|cut -d, -f2-)"
1313 nfs_cow=$(echo ${NFS_COW}|cut -d, -f1)
1315 nfs_cow_opts="-o nolock"
1321 cowdevice=$(echo ${nfs_cow}|sed "s/client_mac_address/${mac}/")
1324 panic "unable to determine mac address"
1329 cow_mountopt="rw,noatime,mode=755"
1332 if [ "${cow_fstype}" = "nfs" ]
1335 "Trying nfsmount ${nfs_cow_opts} ${cowdevice} /cow"
1336 nfsmount ${nfs_cow_opts} ${cowdevice} /cow || \
1337 panic "Can not mount ${cowdevice} (n: ${cow_fstype}) on /cow"
1339 mount -t ${cow_fstype} -o ${cow_mountopt} ${cowdevice} /cow || \
1340 panic "Can not mount ${cowdevice} (o: ${cow_fstype}) on /cow"
1343 rofscount=$(echo ${rofslist} |wc -w)
1345 if [ -n "${EXPOSED_ROOT}" ]
1347 if [ ${rofscount} -ne 1 ]
1349 panic "only one RO file system supported with exposedroot: ${rofslist}"
1351 exposedrootfs=${rofslist%% }
1353 mount --bind ${exposedrootfs} ${rootmnt} || \
1354 panic "bind mount of ${exposedrootfs} failed"
1356 if [ -z "${SKIP_UNION_MOUNTS}" ]
1358 cow_dirs='/var/tmp /var/lock /var/run /var/log /var/spool /home /var/lib/live'
1363 for dir in ${cow_dirs}; do
1366 case "${UNIONTYPE}" in
1368 (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}")
1372 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"
1377 case "${UNIONTYPE}" in
1379 (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}")
1383 mount -t ${UNIONTYPE} -o noatime,dirs=/cow=rw:${rofsstring} ${UNIONTYPE} "${rootmnt}" || panic "mount ${UNIONTYPE} on ${rootmnt} failed with option noatime,dirs=/cow=rw:${rofsstring}"
1388 # Correct the permissions of /:
1389 chmod 0755 "${rootmnt}"
1391 # tmpfs file systems
1393 mkdir -p "${rootmnt}/live"
1394 mount -t tmpfs tmpfs ${rootmnt}/live
1396 # Adding other custom mounts
1397 if [ -n "${PERSISTENT}" ] && [ -z "${NOPERSISTENT}" ]
1399 # directly mount /home
1400 # FIXME: add a custom mounts configurable system
1402 if [ -b "${homecow}" ]
1404 mount -t $(get_fstype "${homecow}") -o rw,noatime "${homecow}" "${rootmnt}/home"
1405 export HOMEMOUNTED=1 # used to proper calculate free space in do_snap_copy()
1407 log_warning_msg "Unable to find the persistent home medium"
1410 # Look for other snapshots to copy in
1411 try_snap "${root_snapdata}" "${rootmnt}" "ROOT"
1412 # This second type should be removed when snapshot grow smarter
1413 try_snap "${home_snapdata}" "${rootmnt}/home" "HOME"
1416 if [ -n "${SHOWMOUNTS}" ]
1418 for d in ${rofslist}
1420 mkdir -p "${rootmnt}/live/${d##*/}"
1424 # do nothing # mount -o bind "${d}" "${rootmnt}/live/${d##*/}"
1428 case "${UNIONTYPE}" in
1430 mount -o bind "${d}" "${rootmnt}/live/${d##*/}"
1434 mount -o move "${d}" "${rootmnt}/live/${d##*/}"
1442 # shows cow fs on /cow for use by live-snapshot
1443 mkdir -p "${rootmnt}/live/cow"
1444 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"
1451 skip_uuid_check="${3}"
1453 # support for fromiso=.../isofrom=....
1454 if [ -n "$FROMISO" ]
1457 ISO_DEVICE="$(echo $FROMISO | sed 's|\(/dev/[a-z]*[0-9]*\).*|\1|')"
1458 mount "$ISO_DEVICE" /isofrom
1459 ISO_NAME="$(echo $FROMISO | sed 's|/dev/[a-z]*[0-9]*/||')"
1460 loopdevname=$(setup_loop "/isofrom/${ISO_NAME}" "loop" "/sys/block/loop*" "" '')
1461 devname="${loopdevname}"
1464 if [ -z "${devname}" ]
1466 devname=$(sys2dev "${sysdev}")
1469 if [ -d "${devname}" ]
1471 mount -o bind "${devname}" $mountpoint || continue
1473 if is_live_path $mountpoint
1482 if [ -n "${LIVE_MEDIA_OFFSET}" ]
1484 loopdevname=$(setup_loop "${devname}" "loop" "/sys/block/loop*" "${LIVE_MEDIA_OFFSET}" '')
1485 devname="${loopdevname}"
1488 fstype=$(get_fstype "${devname}")
1490 if is_supported_fs ${fstype}
1492 mount -t ${fstype} -o ro,noatime "${devname}" ${mountpoint} || continue
1494 if is_live_path ${mountpoint} && \
1495 ([ "${skip_uuid_check}" ] || matches_uuid ${mountpoint})
1500 umount ${mountpoint}
1504 if [ -n "${LIVE_MEDIA_OFFSET}" ]
1506 losetup -d "${loopdevname}"
1516 # don't start autodetection before timeout has expired
1517 if [ -n "${LIVE_MEDIA_TIMEOUT}" ]
1519 if [ "${timeout}" -lt "${LIVE_MEDIA_TIMEOUT}" ]
1525 # first look at the one specified in the command line
1526 case "${LIVE_MEDIA}" in
1528 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -vE "/(loop|ram|dm-|fd)")
1530 if [ "$(cat ${sysblock}/removable)" = "1" ]
1532 if readlink ${sysblock} | grep -q usb ||
1533 readlink ${sysblock}/device | grep -q usb # linux < 2.6.29
1535 for dev in $(subdevices "${sysblock}")
1537 if check_dev "${dev}"
1549 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -vE "/(loop|ram|dm-|fd)")
1551 if [ "$(cat ${sysblock}/removable)" = "1" ]
1553 for dev in $(subdevices "${sysblock}")
1555 if check_dev "${dev}"
1566 if [ ! -z "${LIVE_MEDIA}" ]
1568 if check_dev "null" "${LIVE_MEDIA}" "skip_uuid_check"
1576 # or do the scan of block devices
1577 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -vE "/(loop|ram|dm-|fd)")
1579 devname=$(sys2dev "${sysblock}")
1580 fstype=$(get_fstype "${devname}")
1582 if /lib/udev/cdrom_id ${devname} > /dev/null
1584 if check_dev "null" "${devname}"
1588 elif is_nice_device "${sysblock}"
1590 for dev in $(subdevices "${sysblock}")
1592 if check_dev "${dev}"
1597 elif [ "${fstype}" = "squashfs" -o \
1598 "${fstype}" = "ext2" -o \
1599 "${fstype}" = "ext3" -o \
1600 "${fstype}" = "ext4" -o \
1601 "${fstype}" = "jffs2" ]
1603 # This is an ugly hack situation, the block device has
1604 # an image directly on it. It's hopefully
1605 # live-initramfs, so take it and run with it.
1606 ln -s "${devname}" "${devname}.${fstype}"
1607 echo "${devname}.${fstype}"
1615 set_usplash_timeout ()
1617 if [ -x /sbin/usplash_write ]
1619 /sbin/usplash_write "TIMEOUT 120"
1620 else if [ -x /sbin/splashy_update ] ; then
1621 /sbin/splashy_update "TIMEOUT 120"
1627 media_mountpoint="${1}"
1629 log_begin_msg "Checking media integrity"
1631 cd ${media_mountpoint}
1632 /bin/md5sum -c md5sum.txt < /dev/tty8 > /dev/tty8
1637 if [ "${RC}" -eq 0 ]
1639 log_success_msg "Everything ok, will reboot in 10 seconds."
1642 umount ${media_mountpoint}
1644 echo u > /proc/sysrq-trigger
1645 echo b > /proc/sysrq-trigger
1647 panic "Not ok, a media defect is likely, switch to VT8 for details."
1653 if [ -x /scripts/local-top/cryptroot ]; then
1654 /scripts/local-top/cryptroot
1661 tail -f live.log >&7 &
1664 # Ensure 'panic' function is overridden
1665 . /scripts/live-functions
1671 maybe_break live-premount
1672 log_begin_msg "Running /scripts/live-premount"
1673 run_scripts /scripts/live-premount
1676 # Needed here too because some things (*cough* udev *cough*)
1677 # changes the timeout
1681 if [ ! -z "${NETBOOT}" ] || [ ! -z "${FETCH}" ] || [ ! -z "${HTTPFS}" ] || [ ! -z "${FTPFS}" ]
1685 livefs_root="${mountpoint}"
1687 panic "Unable to find a live file system on the network"
1690 if [ -n "${PLAIN_ROOT}" ] && [ -n "${ROOT}" ]
1692 # Do a local boot from hd
1695 # Scan local devices for the image
1697 while [ "$i" -lt 60 ]
1699 livefs_root=$(find_livefs ${i})
1701 if [ -n "${livefs_root}" ]
1712 if [ -z "${livefs_root}" ]
1714 panic "Unable to find a medium containing a live file system"
1717 if [ "${INTEGRITY_CHECK}" ]
1719 integrity_check "${livefs_root}"
1725 elif [ "${TODISK}" ]
1727 live_dest="${TODISK}"
1730 if [ "${live_dest}" ]
1732 log_begin_msg "Copying live media to ${live_dest}"
1733 copy_live_to "${livefs_root}" "${live_dest}"
1737 # if we do not unmount the ISO we can't run "fsck /dev/ice" later on
1738 # because the mountpoint is left behind in /proc/mounts, so let's get
1739 # rid of it when running from RAM
1740 if [ -n "$FROMISO" ] && [ "${TORAM}" ]
1742 losetup -d /dev/loop0
1743 grep -q /isofrom /proc/mounts && umount /isofrom
1746 if [ -n "${MODULETORAMFILE}" ] || [ -n "${PLAIN_ROOT}" ]
1748 setup_unionfs "${livefs_root}" "${rootmnt}"
1751 mac="$(echo ${mac} | sed 's/-//g')"
1752 mount_images_in_directory "${livefs_root}" "${rootmnt}" "${mac}"
1757 # unionfs-fuse needs /dev to be bind-mounted for the duration of
1758 # live-bottom; udev's init script will take care of things after that
1759 if [ "${UNIONTYPE}" = unionfs-fuse ]
1761 mount -n -o bind /dev "${rootmnt}/dev"
1764 maybe_break live-bottom
1765 log_begin_msg "Running /scripts/live-bottom\n"
1767 run_scripts /scripts/live-bottom
1770 if [ "${UNIONFS}" = unionfs-fuse ]
1772 umount "${rootmnt}/dev"
1778 [ -w "${rootmnt}/var/log/" ] && cp live.log "${rootmnt}/var/log/" 2>/dev/null