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
37 # looking for live-initramfs specifics options as kernel parameters
39 for x in $(cat /proc/cmdline)
53 HOSTNAME=${x#hostname=}
55 export HOSTNAME LIVECONF
59 USERNAME=${x#username=}
61 export USERNAME LIVECONF
65 USERFULLNAME=${x#userfullname=}
67 export USERFULLNAME LIVECONF
73 if [ -z "${STATICIP}" ]
81 keyb=*|kbd-chooser/method=*)
86 klayout=*|console-setup/layoutcode=*)
91 kvariant=*|console-setup/variantcode=*)
96 kmodel=*|console-setup/modelcode=*)
102 KOPTIONS=${x#koptions=}
111 live-media=*|bootfrom=*)
116 live-media-encryption=*|encryption=*)
117 LIVE_MEDIA_ENCRYPTION=${x#*=}
118 export LIVE_MEDIA_ENCRYPTION
122 LIVE_MEDIA_OFFSET=${x#live-media-offset=}
123 export LIVE_MEDIA_OFFSET
126 live-media-timeout=*)
127 LIVE_MEDIA_TIMEOUT=${x#live-media-timeout=}
128 export LIVE_MEDIA_TIMEOUT
131 locale=*|debian-installer/locale=*)
142 NETBOOT=${x#netboot=}
147 NFSOPTS=${x#nfsopts=}
186 preseed/file=*|file=*)
194 PRESEEDS="${PRESEEDS}\"${question}=${value}\" "
205 TIMEZONE="${x#timezone=}"
220 UNIONTYPE="${x#union=}"
230 XVIDEOMODE="${x#xvideomode=}"
236 # sort of compatibility with netboot.h from linux docs
237 if [ -z "${NETBOOT}" ]
239 if [ "${ROOT}" = "/dev/nfs" ]
243 elif [ "${ROOT}" = "/dev/cifs" ]
250 if [ -z "${MODULE}" ]
256 if [ -z "${UNIONTYPE}" ]
267 if [ -d "${DIRECTORY}"/live ]
269 for FILESYSTEM in squashfs ext2 ext3 xfs dir
271 if [ "`echo ${DIRECTORY}/live/*.${FILESYSTEM}`" != "${DIRECTORY}/live/*.${FILESYSTEM}" ]
281 get_backing_device() {
283 *.squashfs|*.ext2|*.ext3)
284 echo $(setup_loop "$1" "loop" "/sys/block/loop*" '0' "${LIVE_MEDIA_ENCRYPTION}")
290 panic "Unrecognized live filesystem: $1"
295 match_files_in_dir() {
296 # Does any files match pattern $1 ?
299 if [ "$(echo $pattern)" != "$pattern" ]; then
305 mount_images_in_directory() {
308 if match_files_in_dir "$directory/live/*.squashfs" ||
309 match_files_in_dir "$directory/live/*.ext2" ||
310 match_files_in_dir "$directory/live/*.ext3" ||
311 match_files_in_dir "$directory/live/*.dir"; then
312 setup_unionfs "$directory/live" "$rootmnt"
319 sysfs_path="${1#/sys}"
320 if /lib/udev/path_id "${sysfs_path}" | grep -E -q "ID_PATH=(usb|pci-[^-]*-[ide|scsi|usb])"; then
327 # FIXME: do something better like the scan of supported filesystems
330 vfat|iso9660|udf|ext2|ext3|ntfs)
340 copyto="${copyfrom}_swap"
342 size=$(fs_size "" ${copyfrom} "used")
344 if [ "${copytodev}" = "ram" ]; then
346 freespace=$( expr $(awk '/MemFree/{print $2}' /proc/meminfo) + $( cat /proc/meminfo | grep Cached | head -n 1 | awk '/Cached/{print $2}' - ) )
347 mount_options="-o size=${size}k"
352 # it should be a writable block device
353 if [ -b "${copytodev}" ]; then
356 fstype=$(get_fstype "${dev}")
357 freespace=$(fs_size "${dev}")
359 [ "$quiet" != "y" ] && log_warning_msg "${copytodev} is not a block device."
363 if [ "${freespace}" -lt "${size}" ] ; then
364 [ "$quiet" != "y" ] && log_warning_msg "Not enough free ${free_string} (${freespace}k > ${size}k) to copy live media in ${copytodev}."
370 echo "mount -t ${fstype} ${mount_options} ${dev} ${copyto}"
371 mount -t "${fstype}" ${mount_options} "${dev}" "${copyto}"
372 cp -a ${copyfrom}/* ${copyto} # "cp -a" from busybox also copies hidden files
374 mount -r --move ${copyto} ${copyfrom}
382 modprobe "${MP_QUIET}" af_packet # For DHCP
387 ipconfig ${DEVICE} /tmp/net-${DEVICE}.conf | tee /netboot.config
389 if [ "${NFSROOT}" = "auto" ]; then
390 NFSROOT=${ROOTSERVER}:${ROOTPATH}
393 [ "$quiet" != "y" ] && log_begin_msg "Trying netboot from ${NFSROOT}"
395 if [ "${NETBOOT}" != "nfs" ] && do_cifsmount ; then
397 elif do_nfsmount ; then
403 [ "$quiet" != "y" ] && log_end_msg
409 modprobe "${MP_QUIET}" nfs
410 if [ -z "${NFSOPTS}" ]; then
414 [ "$quiet" != "y" ] && log_begin_msg "Trying nfsmount -o nolock -o ro ${NFSOPTS} ${NFSROOT} ${mountpoint}"
415 # FIXME: This for loop is an ugly HACK round an nfs bug
416 for i in 0 1 2 3 4 5 6 7 8 9 a b c d e f 10 11 12 13; do
417 nfsmount -o nolock -o ro ${NFSOPTS} "${NFSROOT}" "${mountpoint}" && rc=0 && break
425 if [ -x "/sbin/mount.cifs" ]; then
426 if [ -z "${NFSOPTS}" ]; then
427 CIFSOPTS="-ouser=root,password="
429 CIFSOPTS="${NFSOPTS}"
432 [ "$quiet" != "y" ] && log_begin_msg "Trying mount.cifs ${NFSROOT} ${mountpoint} ${CIFSOPTS}"
433 modprobe "${MP_QUIET}" cifs
435 if mount.cifs "${NFSROOT}" "${mountpoint}" "${CIFSOPTS}" ; then
448 size=$(fs_size "${fromdev}" "" "used")
450 if [ -b "${fromdev}" ]; then
452 if [ -n "${HOMEMOUNTED}" -a "${snap_type}" = "HOME" ]; then
453 todev=$(cat /proc/mounts | grep -s " $(base_path ${todir}) " | awk '{print $1}' )
454 freespace=$(df -k | grep -s ${todev} | awk '{print $4}')
456 freespace=$( expr $(awk '/MemFree/{print $2}' /proc/meminfo) + $( cat /proc/meminfo | grep Cached | head -n 1 | awk '/Cached/{print $2}' - ))
459 tomount="/mnt/tmpsnap"
460 if [ ! -d "${tomount}" ] ; then
461 mkdir -p "${tomount}"
464 fstype=$(get_fstype "${fromdev}")
465 if [ -n "${fstype}" ]; then
467 mount -t "${fstype}" -o ro "${fromdev}" "${tomount}"
468 cp -a "${tomount}"/* ${todir}
471 log_warning_msg "Unrecognized fstype: ${fstype} on ${fromdev}:${snap_type}"
475 if echo ${fromdev} | grep -qs loop; then
476 losetup -d "${fromdev}"
481 [ "$quiet" != "y" ] && log_warning_msg "Unable to find the snapshot ${snap_type} medium"
487 # Look for $snap_label.* in block devices and copy the contents to $snap_mount
488 # and remember the device and filename for resync on exit in live-initramfs.init
494 snapdata=$(find_files "${snap_label}.squashfs ${snap_label}.cpio.gz ${snap_label}.ext2 ${snap_label}.ext3")
495 if [ ! -z "${snapdata}" ]; then
496 snapdev="$(echo ${snapdata} | cut -f1 -d ' ')"
497 snapback="$(echo ${snapdata} | cut -f2 -d ' ')"
498 snapfile="$(echo ${snapdata} | cut -f3 -d ' ')"
499 if echo "${snapfile}" | grep -qs '\(squashfs\|ext2\|ext3\)'; then
500 # squashfs or ext2/ext3 snapshot
501 dev=$(get_backing_device "${snapback}/${snapfile}")
502 if ! do_snap_copy "${dev}" "${snap_mount}" "${snap_type}"; then
503 log_warning_msg "Impossible to include the ${snapfile} Snapshot"
508 if ! (cd "${snap_mount}" && zcat "${snapback}/${snapfile}" | cpio -i -u -d 2>/dev/null) ; then
509 log_warning_msg "Impossible to include the ${snapfile} Snapshot"
515 dev=$(find_cow_device "${snap_label}")
516 if [ -b ${dev} ]; then
517 if echo "${dev}" | grep -qs loop; then
518 # strange things happens, user confused?
519 snaploop=$( losetup ${dev} | awk '{print $3}' | tr -d '()' )
520 snapfile=$(basename ${snaploop})
521 snapdev=$(cat /proc/mounts | awk '{print $2,$1}' | grep -es "^$( dirname ${snaploop} )" | cut -f2 -d ' ')
525 if ! do_snap_copy "${dev}" "${snap_mount}" "${snap_type}" ; then
526 log_warning_msg "Impossible to include the ${snap_label} Snapshot"
529 if [ -n "${snapfile}" ]; then
530 # it was a loop device, user confused
535 log_warning_msg "Impossible to include the ${snap_label} Snapshot"
539 echo "export ${snap_type}SNAP="${snap_mount}":${snapdev}:${snapfile}" >> /etc/live.conf # for resync on reboot/halt
547 modprobe "${MP_QUIET}" -b ${UNIONTYPE}
549 # run-init can't deal with images in a subdir, but we're going to
550 # move all of these away before it runs anyway. No, we're not,
551 # put them in / since move-mounting them into / breaks mono and
556 # Let's just mount the read-only file systems first
559 if [ "${NETBOOT}" = "nfs" ] ; then
560 roopt="nfsro" # go aroung a bug in nfs-unionfs locking
565 # Read image names from ${MODULE}.module if it exists
566 if [ -e "${image_directory}/filesystem.${MODULE}.module" ]
568 for IMAGE in `cat ${image_directory}/filesystem.${MODULE}.module`
570 image_string="${image_string} ${image_directory}/${image}"
572 elif [ -e "${image_directory}/${MODULE}.module" ]
574 for IMAGE in `cat ${image_directory}/${MODULE}.module`
576 image_string="${image_string} ${image_directory}/${image}"
579 # ${MODULE}.module does not exist, create a list of images
580 for FILESYSTEM in squashfs ext2 ext3 xfs dir
582 for IMAGE in "${image_directory}"/*."${FILESYSTEM}"
586 image_string="${image_string} ${IMAGE}"
592 image_string="`echo ${image_string} | sed -e 's/ /\n/g' | sort `"
596 for image in ${image_string}; do
597 imagename=$(basename "${image}")
598 if [ -d "${image}" ]; then
599 # it is a plain directory: do nothing
600 rofsstring="${image}=${roopt}:${rofsstring}"
601 rofslist="${image} ${rofslist}"
602 elif [ -f "${image}" ]; then
603 backdev=$(get_backing_device "$image")
604 fstype=$(get_fstype "${backdev}")
605 if [ "${fstype}" = "unknown" ]; then
606 panic "Unknown file system type on ${backdev} (${image})"
608 mkdir -p "${croot}/${imagename}"
609 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}"
612 rofsstring=${rofsstring%:}
618 # Looking for "${root_persistence}" device or file
619 if [ -n "${PERSISTENT}" ]; then
620 cowprobe=$(find_cow_device "${root_persistence}")
621 if [ -b "${cowprobe}" ]; then
622 cowdevice=${cowprobe}
623 cow_fstype=$(get_fstype "${cowprobe}")
625 [ "$quiet" != "y" ] && log_warning_msg "Unable to find the persistent medium"
629 mount ${cowdevice} -t ${cow_fstype} -o rw /cow || panic "Can not mount $cowdevice on /cow"
631 mount -t ${UNIONTYPE} -o dirs=/cow=rw:$rofsstring ${UNIONTYPE} "$rootmnt" || panic "${UNIONTYPE} mount failed"
633 # Adding other custom mounts
634 if [ -n "${PERSISTENT}" ]; then
635 # directly mount /home
636 # FIXME: add a custom mounts configurable system
637 homecow=$(find_cow_device "${home_persistence}" )
638 if [ -b "${homecow}" ]; then
639 mount -t $(get_fstype "${homecow}") -o rw "${homecow}" "${rootmnt}/home"
640 export HOMEMOUNTED=1 # used to proper calculate free space in do_snap_copy()
642 [ "$quiet" != "y" ] && log_warning_msg "Unable to find the persistent home medium"
644 # Look for other snapshots to copy in
645 try_snap "${root_snapshot_label}" "${rootmnt}" "ROOT"
646 try_snap "${home_snapshot_label}" "${rootmnt}/home" "HOME"
649 if [ -n "${SHOWMOUNTS}" ]; then
650 for d in ${rofslist}; do
651 mkdir -p "${rootmnt}/live/${d##*/}"
653 *.dir) # do nothing # mount -o bind "${d}" "${rootmnt}/live/${d##*/}"
655 *) mount --move "${d}" "${rootmnt}/live/${d##*/}"
661 # shows cow fs on /cow for use by live-snapshot
662 mkdir -p "${rootmnt}/cow"
663 mount -o bind /cow "${rootmnt}/cow"
670 if [ -z "${devname}" ]; then
671 devname=$(sys2dev "${sysdev}")
674 if [ -n "${LIVE_MEDIA_OFFSET}" ]; then
675 loopdevname=$(setup_loop "${devname}" "loop" "/sys/block/loop*" "${LIVE_MEDIA_OFFSET}" '')
676 devname="${loopdevname}"
679 fstype=$(get_fstype "${devname}")
680 if is_supported_fs ${fstype}; then
681 mount -t ${fstype} -o ro "${devname}" $mountpoint || continue
682 if is_live_path $mountpoint; then
690 if [ -n "${LIVE_MEDIA_OFFSET}" ]; then
691 losetup -d "${loopdevname}"
698 # first look at the one specified in the command line
699 if [ ! -z "${LIVE_MEDIA}" ]; then
700 if check_dev "null" "${LIVE_MEDIA}"; then
704 # don't start autodetection before timeout has expired
705 if [ -n "${LIVE_MEDIA_TIMEOUT}" ]; then
706 if [ "${timeout}" -lt "${LIVE_MEDIA_TIMEOUT}" ]; then
710 # or do the scan of block devices
711 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -v loop | grep -v ram); do
712 devname=$(sys2dev "${sysblock}")
713 fstype=$(get_fstype "${devname}")
714 if /lib/udev/cdrom_id ${devname} > /dev/null; then
715 if check_dev "null" "${devname}" ; then
718 elif is_nice_device "${sysblock}" ; then
719 for dev in $(subdevices "${sysblock}"); do
720 if check_dev "${dev}" ; then
724 elif [ "${fstype}" = "squashfs" -o \
725 "${fstype}" = "ext2" -o \
726 "${fstype}" = "ext3" ]; then
727 # This is an ugly hack situation, the block device has
728 # an image directly on it. It's hopefully
729 # live-initramfs, so take it and run with it.
730 ln -s "${devname}" "${devname}.${fstype}"
731 echo "${devname}.${fstype}"
739 if [ -x /sbin/usplash_write ]; then
740 /sbin/usplash_write "PULSATE"
744 set_usplash_timeout() {
745 if [ -x /sbin/usplash_write ]; then
746 /sbin/usplash_write "TIMEOUT 120"
759 [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/live-premount"
761 run_scripts /scripts/live-premount
762 [ "$quiet" != "y" ] && log_end_msg
764 # Needed here too because some things (*cough* udev *cough*)
765 # changes the timeout
769 if [ ! -z "${NETBOOT}" ]; then
770 if do_netmount ; then
771 livefs_root="${mountpoint}"
773 panic "Unable to find a live file system on the network"
776 # Scan local devices for the image
777 for i in 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19; do
778 livefs_root=$(find_livefs $i)
779 if [ -n "${livefs_root}" ]; then
786 if [ -z "${livefs_root}" ]; then
787 panic "Unable to find a medium containing a live file system"
790 if [ "${TORAM}" ]; then
792 elif [ "${TODISK}" ]; then
793 live_dest="${TODISK}"
795 if [ "${live_dest}" ]; then
796 log_begin_msg "Copying live_media to ${live_dest}"
797 copy_live_to "${livefs_root}" "${live_dest}"
801 mount_images_in_directory "${livefs_root}" "${rootmnt}"
805 maybe_break live-bottom
806 [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/live-bottom"
809 run_scripts /scripts/live-bottom
810 [ "$quiet" != "y" ] && log_end_msg
814 cp live.log "${rootmnt}/var/log/"