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_media
12 root_persistence="live-rw"
13 home_persistence="home-rw"
14 root_snapshot_label="live-sn"
15 home_snapshot_label="home-sn"
18 USERFULLNAME="Live user"
24 [ -f /etc/live.conf ] && . /etc/live.conf
25 export USERNAME USERFULLNAME HOSTNAME BUILD_SYSTEM
27 . /scripts/live-helpers
29 if [ ! -f /live.vars ]; then
36 # looking for live-initramfs specifics options as kernel parameters
37 for x in $(cat /proc/cmdline); do
40 export USERFULLNAME=${x#userfullname=}
41 export LIVECONF="changed"
44 export HOSTNAME=${x#hostname=}
45 export LIVECONF="changed"
48 export USERNAME=${x#username=}
49 export LIVECONF="changed"
52 export NETBOOT=${x#netboot=} ;;
54 export ACCESS=${x#access=} ;;
56 export XDEBCONF="Yes" ;;
58 export XVIDEOMODE="${x#xvideomode=}" ;;
62 export TODISK=${x#todisk=} ;;
64 export SWAPOFF="Yes" ;;
66 export SHOWMOUNTS="Yes" ;;
68 export PERSISTENT="Yes" ;;
70 export PERSISTENT="" ;;
73 if [ "${STATICIP}" == "" ]; then
78 export LIVE_GETTY=1 ;;
79 bootfrom=*|live-media=*)
80 export LIVE_MEDIA=${x#*=} ;;
81 live-media-encryption=*|encryption=*)
82 export LIVE_MEDIA_ENCRYPTION=${x#*=} ;;
84 export LIVE_MEDIA_TIMEOUT=${x#live-media-timeout=} ;;
86 export LIVE_MEDIA_OFFSET=${x#live-media-offset=} ;;
87 locale=*|debian-installer/locale=*)
88 export LOCALE=${x#*=} ;;
89 keyb=*|kbd-chooser/method=*)
91 klayout=*|console-setup/layoutcode=*)
92 export KLAYOUT=${x#*=} ;;
94 export KOPTIONS=${x#koptions=} ;;
95 kvariant=*|console-setup/variantcode=*)
96 export KVARIANT=${x#*=} ;;
97 kmodel=*|console-setup/modelcode=*)
98 export KMODEL=${x#*=} ;;
100 export MODULE=${x#module=} ;;
101 preseed/file=*|file=*)
102 export LOCATION="${x#*=}" ;;
106 PRESEEDS="${PRESEEDS}\"${question}=${value}\" "
109 export DEFCONSOLE="${x#*=}" ;;
113 # sort of compatibility with netboot.h from linux docs
114 if [ -z "${NETBOOT}" ]; then
115 if [ "${ROOT}" == "/dev/nfs" ]; then
118 elif [ "${ROOT}" == "/dev/cifs" ]; then
124 if [ -z "${MODULE}" ]; then
131 if [ -d "$path/live" ]; then
132 if [ "$(echo $path/live/*.squashfs)" != "$path/live/*.squashfs" ] ||
133 [ "$(echo $path/live/*.ext2)" != "$path/live/*.ext2" ] ||
134 [ "$(echo $path/live/*.dir)" != "$path/live/*.dir" ]; then
141 get_backing_device() {
144 echo $(setup_loop "$1" "loop" "/sys/block/loop*" '0' "${LIVE_MEDIA_ENCRYPTION}")
150 panic "Unrecognized live filesystem: $1"
155 match_files_in_dir() {
156 # Does any files match pattern $1 ?
159 if [ "$(echo $pattern)" != "$pattern" ]; then
165 mount_images_in_directory() {
168 if match_files_in_dir "$directory/live/*.squashfs" ||
169 match_files_in_dir "$directory/live/*.ext2" ||
170 match_files_in_dir "$directory/live/*.dir"; then
171 setup_unionfs "$directory/live" "$rootmnt"
178 sysfs_path="${1#/sys}"
179 if /lib/udev/path_id "${sysfs_path}" | grep -E -q "ID_PATH=(usb|pci-[^-]*-[ide|scsi|usb])"; then
186 # FIXME: do something better like the scan of supported filesystems
189 vfat|iso9660|udf|ext2|ext3|ntfs)
199 copyto="${copyfrom}_swap"
201 size=$(fs_size "" ${copyfrom} "used")
203 if [ "${copytodev}" = "ram" ]; then
205 freespace=$( expr $(awk '/MemFree/{print $2}' /proc/meminfo) + $( cat /proc/meminfo | grep Cached | head -n 1 | awk '/Cached/{print $2}' - ) )
206 mount_options="-o size=${size}k"
211 # it should be a writable block device
212 if [ -b "${copytodev}" ]; then
215 fstype=$(get_fstype "${dev}")
216 freespace=$(fs_size "${dev}")
218 [ "$quiet" != "y" ] && log_warning_msg "${copytodev} is not a block device."
222 if [ "${freespace}" -lt "${size}" ] ; then
223 [ "$quiet" != "y" ] && log_warning_msg "Not enough free ${free_string} (${freespace}k > ${size}k) to copy live media in ${copytodev}."
229 echo "mount -t ${fstype} ${mount_options} ${dev} ${copyto}"
230 mount -t "${fstype}" ${mount_options} "${dev}" "${copyto}"
231 cp -a ${copyfrom}/* ${copyto} # "cp -a" from busybox also copies hidden files
233 mount -r -o move ${copyto} ${copyfrom}
241 modprobe "${MP_QUIET}" af_packet # For DHCP
246 ipconfig ${DEVICE} /tmp/net-${DEVICE}.conf | tee /netboot.config
248 if [ "${NFSROOT}" = "auto" ]; then
249 NFSROOT=${ROOTSERVER}:${ROOTPATH}
252 [ "$quiet" != "y" ] && log_begin_msg "Trying netboot from ${NFSROOT}"
254 if [ "${NETBOOT}" != "nfs" ] && do_cifsmount ; then
256 elif do_nfsmount ; then
262 [ "$quiet" != "y" ] && log_end_msg
268 modprobe "${MP_QUIET}" nfs
269 if [ -z "${NFSOPTS}" ]; then
273 [ "$quiet" != "y" ] && log_begin_msg "Trying nfsmount -o nolock -o ro ${NFSOPTS} ${NFSROOT} ${mountpoint}"
274 # FIXME: This for loop is an ugly HACK round an nfs bug
275 for i in 0 1 2 3 4 5 6 7 8 9 a b c d e f 10 11 12 13; do
276 nfsmount -o nolock -o ro ${NFSOPTS} "${NFSROOT}" "${mountpoint}" && rc=0 && break
284 if [ -x "/sbin/mount.cifs" ]; then
285 if [ -z "${NFSOPTS}" ]; then
286 CIFSOPTS="-ouser=root,password="
288 CIFSOPTS="${NFSOPTS}"
291 [ "$quiet" != "y" ] && log_begin_msg "Trying mount.cifs ${NFSROOT} ${mountpoint} ${CIFSOPTS}"
292 modprobe "${MP_QUIET}" cifs
294 if mount.cifs "${NFSROOT}" "${mountpoint}" "${CIFSOPTS}" ; then
307 size=$(fs_size "${fromdev}" "" "used")
309 if [ -b "${fromdev}" ]; then
311 if [ -n "${HOMEMOUNTED}" -a "${snap_type}" = "HOME" ]; then
312 todev=$(cat /proc/mounts | grep -s " $(base_path ${todir}) " | awk '{print $1}' )
313 freespace=$(df -k | grep -s ${todev} | awk '{print $4}')
315 freespace=$( expr $(awk '/MemFree/{print $2}' /proc/meminfo) + $( cat /proc/meminfo | grep Cached | head -n 1 | awk '/Cached/{print $2}' - ))
318 tomount="/mnt/tmpsnap"
319 if [ ! -d "${tomount}" ] ; then
320 mkdir -p "${tomount}"
323 fstype=$(get_fstype "${fromdev}")
324 if [ -n "${fstype}" ]; then
326 mount -t "${fstype}" -o ro "${fromdev}" "${tomount}"
327 cp -a "${tomount}"/* ${todir}
330 log_warning_msg "Unrecognized fstype: ${fstype} on ${fromdev}:${snap_type}"
334 if echo ${fromdev} | grep -qs loop; then
335 losetup -d "${fromdev}"
340 [ "$quiet" != "y" ] && log_warning_msg "Unable to find the snapshot ${snap_type} medium"
346 # Look for $snap_label.* in block devices and copy the contents to $snap_mount
347 # and remember the device and filename for resync on exit in live-initramfs.init
353 snapdata=$(find_files "${snap_label}.squashfs ${snap_label}.cpio.gz ${snap_label}.ext2")
354 if [ ! -z "${snapdata}" ]; then
355 snapdev="$(echo ${snapdata} | cut -f1 -d ' ')"
356 snapback="$(echo ${snapdata} | cut -f2 -d ' ')"
357 snapfile="$(echo ${snapdata} | cut -f3 -d ' ')"
358 if echo "${snapfile}" | grep -qs '\(squashfs\|ext2\)'; then
359 # squashfs or ext2 snapshot
360 dev=$(get_backing_device "${snapback}/${snapfile}")
361 if ! do_snap_copy "${dev}" "${snap_mount}" "${snap_type}"; then
362 log_warning_msg "Impossible to include the ${snapfile} Snapshot"
367 if ! (cd "${snap_mount}" && zcat "${snapback}/${snapfile}" | cpio -i -u -d 2>/dev/null) ; then
368 log_warning_msg "Impossible to include the ${snapfile} Snapshot"
374 dev=$(find_cow_device "${snap_label}")
375 if [ -b ${dev} ]; then
376 if echo "${dev}" | grep -qs loop; then
377 # strange things happens, user confused?
378 snaploop=$( losetup ${dev} | awk '{print $3}' | tr -d '()' )
379 snapfile=$(basename ${snaploop})
380 snapdev=$(cat /proc/mounts | awk '{print $2,$1}' | grep -es "^$( dirname ${snaploop} )" | cut -f2 -d ' ')
384 if ! do_snap_copy "${dev}" "${snap_mount}" "${snap_type}" ; then
385 log_warning_msg "Impossible to include the ${snap_label} Snapshot"
388 if [ -n "${snapfile}" ]; then
389 # it was a loop device, user confused
394 log_warning_msg "Impossible to include the ${snap_label} Snapshot"
398 echo "export ${snap_type}SNAP="${snap_mount}":${snapdev}:${snapfile}" >> /etc/live.conf # for resync on reboot/halt
406 modprobe "${MP_QUIET}" -b unionfs
408 # run-init can't deal with images in a subdir, but we're going to
409 # move all of these away before it runs anyway. No, we're not,
410 # put them in / since move-mounting them into / breaks mono and
415 # Let's just mount the read-only file systems first
418 if [ "${NETBOOT}" = "nfs" ] ; then
419 roopt="nfsro" # go aroung a bug in nfs-unionfs locking
424 # Read image names from ${MODULE}.lst if it exists
425 if [ -e "${image_directory}/${MODULE}.lst" ]; then
426 for image in $(cat "${image_directory}/${MODULE}.lst"); do
427 image_string="${image_string} ${image_directory}/${image}";
430 # If ${MODULE}.lst does not exist, create a list of images
431 for image_type in "ext2" "squashfs" "dir"; do
432 for image in "${image_directory}"/*."${image_type}"; do
433 if [ -e "${image}" ]; then
434 image_string="${image_string} ${image}";
439 image_string=$(echo ${image_string} | sed -e 's/ /\n/g' | sort )
443 for image in ${image_string}; do
444 imagename=$(basename "${image}")
445 if [ -d "${image}" ]; then
446 # it is a plain directory: do nothing
447 rofsstring="${image}=${roopt}:${rofsstring}"
448 rofslist="${image} ${rofslist}"
449 elif [ -f "${image}" ]; then
450 backdev=$(get_backing_device "$image")
451 fstype=$(get_fstype "${backdev}")
452 if [ "${fstype}" = "unknown" ]; then
453 panic "Unknown file system type on ${backdev} (${image})"
455 mkdir -p "${croot}/${imagename}"
456 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}"
459 rofsstring=${rofsstring%:}
465 # Looking for "${root_persistence}" device or file
466 if [ -n "${PERSISTENT}" ]; then
467 cowprobe=$(find_cow_device "${root_persistence}")
468 if [ -b "${cowprobe}" ]; then
469 cowdevice=${cowprobe}
470 cow_fstype=$(get_fstype "${cowprobe}")
472 [ "$quiet" != "y" ] && log_warning_msg "Unable to find the persistent medium"
476 mount ${cowdevice} -t ${cow_fstype} -o rw /cow || panic "Can not mount $cowdevice on /cow"
478 mount -t unionfs -o dirs=/cow=rw:$rofsstring unionfs "$rootmnt" || panic "Unionfs mount failed"
480 # Adding other custom mounts
481 if [ -n "${PERSISTENT}" ]; then
482 # directly mount /home
483 # FIXME: add a custom mounts configurable system
484 homecow=$(find_cow_device "${home_persistence}" )
485 if [ -b "${homecow}" ]; then
486 mount -t $(get_fstype "${homecow}") -o rw "${homecow}" "${rootmnt}/home"
487 export HOMEMOUNTED=1 # used to proper calculate free space in do_snap_copy()
489 [ "$quiet" != "y" ] && log_warning_msg "Unable to find the persistent home medium"
491 # Look for other snapshots to copy in
492 try_snap "${root_snapshot_label}" "${rootmnt}" "ROOT"
493 try_snap "${home_snapshot_label}" "${rootmnt}/home" "HOME"
496 if [ -n "${SHOWMOUNTS}" ]; then
497 for d in ${rofslist}; do
498 mkdir -p "${rootmnt}/live/${d##*/}"
500 *.dir) # do nothing # mount -o bind "${d}" "${rootmnt}/live/${d##*/}"
502 *) mount -o move "${d}" "${rootmnt}/live/${d##*/}"
508 # shows cow fs on /cow for use by live-snapshot
509 mkdir -p "${rootmnt}/cow"
510 mount -o bind /cow "${rootmnt}/cow"
517 if [ -z "${devname}" ]; then
518 devname=$(sys2dev "${sysdev}")
521 if [ -n "${LIVE_MEDIA_OFFSET}" ]; then
522 loopdevname=$(setup_loop "${devname}" "loop" "/sys/block/loop*" "${LIVE_MEDIA_OFFSET}" '')
523 devname="${loopdevname}"
526 fstype=$(get_fstype "${devname}")
527 if is_supported_fs ${fstype}; then
528 mount -t ${fstype} -o ro "${devname}" $mountpoint || continue
529 if is_live_path $mountpoint; then
537 if [ -n "${LIVE_MEDIA_OFFSET}" ]; then
538 losetup -d "${loopdevname}"
545 # first look at the one specified in the command line
546 if [ ! -z "${LIVE_MEDIA}" ]; then
547 if check_dev "null" "${LIVE_MEDIA}"; then
551 # don't start autodetection before timeout has expired
552 if [ -n "${LIVE_MEDIA_TIMEOUT}" ]; then
553 if [ "${timeout}" -lt "${LIVE_MEDIA_TIMEOUT}" ]; then
557 # or do the scan of block devices
558 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -v loop | grep -v ram); do
559 devname=$(sys2dev "${sysblock}")
560 fstype=$(get_fstype "${devname}")
561 if /lib/udev/cdrom_id ${devname} > /dev/null; then
562 if check_dev "null" "${devname}" ; then
565 elif is_nice_device "${sysblock}" ; then
566 for dev in $(subdevices "${sysblock}"); do
567 if check_dev "${dev}" ; then
571 elif [ "${fstype}" = "squashfs" -o \
572 "${fstype}" = "ext3" -o \
573 "${fstype}" = "ext2" ]; then
574 # This is an ugly hack situation, the block device has
575 # an image directly on it. It's hopefully
576 # live-initramfs, so take it and run with it.
577 ln -s "${devname}" "${devname}.${fstype}"
578 echo "${devname}.${fstype}"
586 if [ -x /sbin/usplash_write ]; then
587 /sbin/usplash_write "PULSATE"
591 set_usplash_timeout() {
592 if [ -x /sbin/usplash_write ]; then
593 /sbin/usplash_write "TIMEOUT 120"
606 [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/live-premount"
608 run_scripts /scripts/live-premount
609 [ "$quiet" != "y" ] && log_end_msg
611 # Needed here too because some things (*cough* udev *cough*)
612 # changes the timeout
616 if [ ! -z "${NETBOOT}" ]; then
617 if do_netmount ; then
618 livefs_root="${mountpoint}"
620 panic "Unable to find a live file system on the network"
623 # Scan local devices for the image
624 for i in 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19; do
625 livefs_root=$(find_livefs $i)
626 if [ -n "${livefs_root}" ]; then
633 if [ -z "${livefs_root}" ]; then
634 panic "Unable to find a medium containing a live file system"
637 if [ "${TORAM}" ]; then
639 elif [ "${TODISK}" ]; then
640 live_dest="${TODISK}"
642 if [ "${live_dest}" ]; then
643 log_begin_msg "Copying live_media to ${live_dest}"
644 copy_live_to "${livefs_root}" "${live_dest}"
648 mount_images_in_directory "${livefs_root}" "${rootmnt}"
652 maybe_break live-bottom
653 [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/live-bottom"
656 run_scripts /scripts/live-bottom
657 [ "$quiet" != "y" ] && log_end_msg
661 cp live.log "${rootmnt}/var/log/"