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"
25 [ -f /etc/live.conf ] && . /etc/live.conf
26 export USERNAME USERFULLNAME HOSTNAME BUILD_SYSTEM
28 . /scripts/live-helpers
30 if [ ! -f /live.vars ]; then
38 # looking for live-initramfs specifics options as kernel parameters
40 for x in $(cat /proc/cmdline)
61 HOSTNAME=${x#hostname=}
63 export HOSTNAME LIVECONF
67 USERNAME=${x#username=}
69 export USERNAME LIVECONF
73 USERFULLNAME=${x#userfullname=}
75 export USERFULLNAME LIVECONF
81 if [ -z "${STATICIP}" ]
89 keyb=*|kbd-chooser/method=*)
94 klayout=*|console-setup/layoutcode=*)
99 kvariant=*|console-setup/variantcode=*)
104 kmodel=*|console-setup/modelcode=*)
110 KOPTIONS=${x#koptions=}
119 live-media=*|bootfrom=*)
124 live-media-encryption=*|encryption=*)
125 LIVE_MEDIA_ENCRYPTION=${x#*=}
126 export LIVE_MEDIA_ENCRYPTION
130 LIVE_MEDIA_OFFSET=${x#live-media-offset=}
131 export LIVE_MEDIA_OFFSET
135 LIVE_MEDIA_PATH="${x#live-media-path=}"
136 export LIVE_MEDIA_PATH
139 live-media-timeout=*)
140 LIVE_MEDIA_TIMEOUT=${x#live-media-timeout=}
141 export LIVE_MEDIA_TIMEOUT
144 locale=*|debian-installer/locale=*)
155 NETBOOT=${x#netboot=}
160 NFSOPTS=${x#nfsopts=}
199 preseed/file=*|file=*)
207 PRESEEDS="${PRESEEDS}\"${question}=${value}\" "
218 TIMEZONE="${x#timezone=}"
233 UNIONTYPE="${x#union=}"
248 XVIDEOMODE="${x#xvideomode=}"
254 # sort of compatibility with netboot.h from linux docs
255 if [ -z "${NETBOOT}" ]
257 if [ "${ROOT}" = "/dev/nfs" ]
261 elif [ "${ROOT}" = "/dev/cifs" ]
268 if [ -z "${MODULE}" ]
274 if [ -z "${UNIONTYPE}" ]
285 if [ -d "${DIRECTORY}"/"${LIVE_MEDIA_PATH}" ]
287 for FILESYSTEM in squashfs ext2 ext3 xfs dir
289 if [ "`echo ${DIRECTORY}/${LIVE_MEDIA_PATH}/*.${FILESYSTEM}`" != "${DIRECTORY}/${LIVE_MEDIA_PATH}/*.${FILESYSTEM}" ]
299 get_backing_device() {
301 *.squashfs|*.ext2|*.ext3)
302 echo $(setup_loop "$1" "loop" "/sys/block/loop*" '0' "${LIVE_MEDIA_ENCRYPTION}")
308 panic "Unrecognized live filesystem: $1"
313 match_files_in_dir() {
314 # Does any files match pattern $1 ?
317 if [ "$(echo $pattern)" != "$pattern" ]; then
323 mount_images_in_directory() {
326 if match_files_in_dir "$directory/${LIVE_MEDIA_PATH}/*.squashfs" ||
327 match_files_in_dir "$directory/${LIVE_MEDIA_PATH}/*.ext2" ||
328 match_files_in_dir "$directory/${LIVE_MEDIA_PATH}/*.ext3" ||
329 match_files_in_dir "$directory/${LIVE_MEDIA_PATH}/*.dir"; then
330 setup_unionfs "$directory/${LIVE_MEDIA_PATH}" "$rootmnt"
337 sysfs_path="${1#/sys}"
338 if /lib/udev/path_id "${sysfs_path}" | grep -E -q "ID_PATH=(usb|pci-[^-]*-[ide|scsi|usb])"; then
345 # FIXME: do something better like the scan of supported filesystems
348 vfat|iso9660|udf|ext2|ext3|ntfs)
358 copyto="${copyfrom}_swap"
360 size=$(fs_size "" ${copyfrom} "used")
362 if [ "${copytodev}" = "ram" ]; then
364 freespace=$( expr $(awk '/MemFree/{print $2}' /proc/meminfo) + $( cat /proc/meminfo | grep Cached | head -n 1 | awk '/Cached/{print $2}' - ) )
365 mount_options="-o size=${size}k"
370 # it should be a writable block device
371 if [ -b "${copytodev}" ]; then
374 fstype=$(get_fstype "${dev}")
375 freespace=$(fs_size "${dev}")
377 [ "$quiet" != "y" ] && log_warning_msg "${copytodev} is not a block device."
381 if [ "${freespace}" -lt "${size}" ] ; then
382 [ "$quiet" != "y" ] && log_warning_msg "Not enough free ${free_string} (${freespace}k > ${size}k) to copy live media in ${copytodev}."
388 echo "mount -t ${fstype} ${mount_options} ${dev} ${copyto}"
389 mount -t "${fstype}" ${mount_options} "${dev}" "${copyto}"
390 cp -a ${copyfrom}/* ${copyto} # "cp -a" from busybox also copies hidden files
392 mount -r --move ${copyto} ${copyfrom}
400 modprobe "${MP_QUIET}" af_packet # For DHCP
405 ipconfig ${DEVICE} /tmp/net-${DEVICE}.conf | tee /netboot.config
407 if [ "${NFSROOT}" = "auto" ]; then
408 NFSROOT=${ROOTSERVER}:${ROOTPATH}
411 # source relevant ipconfig output
412 . /tmp/net-${DEVICE}.conf
415 if [ "${NFSROOT#*:}" = "$NFSROOT" ] && [ "$NETBOOT" != "cifs" ]; then
416 NFSROOT=${ROOTSERVER}:${NFSROOT}
419 [ "$quiet" != "y" ] && log_begin_msg "Trying netboot from ${NFSROOT}"
421 if [ "${NETBOOT}" != "nfs" ] && do_cifsmount ; then
423 elif do_nfsmount ; then
429 [ "$quiet" != "y" ] && log_end_msg
435 modprobe "${MP_QUIET}" nfs
436 if [ -z "${NFSOPTS}" ]; then
440 [ "$quiet" != "y" ] && log_begin_msg "Trying nfsmount -o nolock -o ro ${NFSOPTS} ${NFSROOT} ${mountpoint}"
441 # FIXME: This for loop is an ugly HACK round an nfs bug
442 for i in 0 1 2 3 4 5 6 7 8 9 a b c d e f 10 11 12 13; do
443 nfsmount -o nolock -o ro ${NFSOPTS} "${NFSROOT}" "${mountpoint}" && rc=0 && break
451 if [ -x "/sbin/mount.cifs" ]; then
452 if [ -z "${NFSOPTS}" ]; then
453 CIFSOPTS="-ouser=root,password="
455 CIFSOPTS="${NFSOPTS}"
458 [ "$quiet" != "y" ] && log_begin_msg "Trying mount.cifs ${NFSROOT} ${mountpoint} ${CIFSOPTS}"
459 modprobe "${MP_QUIET}" cifs
461 if mount.cifs "${NFSROOT}" "${mountpoint}" "${CIFSOPTS}" ; then
474 size=$(fs_size "${fromdev}" "" "used")
476 if [ -b "${fromdev}" ]; then
478 if [ -n "${HOMEMOUNTED}" -a "${snap_type}" = "HOME" ]; then
479 todev=$(cat /proc/mounts | grep -s " $(base_path ${todir}) " | awk '{print $1}' )
480 freespace=$(df -k | grep -s ${todev} | awk '{print $4}')
482 freespace=$( expr $(awk '/MemFree/{print $2}' /proc/meminfo) + $( cat /proc/meminfo | grep Cached | head -n 1 | awk '/Cached/{print $2}' - ))
485 tomount="/mnt/tmpsnap"
486 if [ ! -d "${tomount}" ] ; then
487 mkdir -p "${tomount}"
490 fstype=$(get_fstype "${fromdev}")
491 if [ -n "${fstype}" ]; then
493 mount -t "${fstype}" -o ro "${fromdev}" "${tomount}"
494 cp -a "${tomount}"/* ${todir}
497 log_warning_msg "Unrecognized fstype: ${fstype} on ${fromdev}:${snap_type}"
501 if echo ${fromdev} | grep -qs loop; then
502 losetup -d "${fromdev}"
507 [ "$quiet" != "y" ] && log_warning_msg "Unable to find the snapshot ${snap_type} medium"
513 # Look for $snap_label.* in block devices and copy the contents to $snap_mount
514 # and remember the device and filename for resync on exit in live-initramfs.init
520 snapdata=$(find_files "${snap_label}.squashfs ${snap_label}.cpio.gz ${snap_label}.ext2 ${snap_label}.ext3")
521 if [ ! -z "${snapdata}" ]; then
522 snapdev="$(echo ${snapdata} | cut -f1 -d ' ')"
523 snapback="$(echo ${snapdata} | cut -f2 -d ' ')"
524 snapfile="$(echo ${snapdata} | cut -f3 -d ' ')"
525 if echo "${snapfile}" | grep -qs '\(squashfs\|ext2\|ext3\)'; then
526 # squashfs or ext2/ext3 snapshot
527 dev=$(get_backing_device "${snapback}/${snapfile}")
528 if ! do_snap_copy "${dev}" "${snap_mount}" "${snap_type}"; then
529 log_warning_msg "Impossible to include the ${snapfile} Snapshot"
534 if ! (cd "${snap_mount}" && zcat "${snapback}/${snapfile}" | cpio -i -u -d 2>/dev/null) ; then
535 log_warning_msg "Impossible to include the ${snapfile} Snapshot"
541 dev=$(find_cow_device "${snap_label}")
542 if [ -b ${dev} ]; then
543 if echo "${dev}" | grep -qs loop; then
544 # strange things happens, user confused?
545 snaploop=$( losetup ${dev} | awk '{print $3}' | tr -d '()' )
546 snapfile=$(basename ${snaploop})
547 snapdev=$(cat /proc/mounts | awk '{print $2,$1}' | grep -es "^$( dirname ${snaploop} )" | cut -f2 -d ' ')
551 if ! do_snap_copy "${dev}" "${snap_mount}" "${snap_type}" ; then
552 log_warning_msg "Impossible to include the ${snap_label} Snapshot"
555 if [ -n "${snapfile}" ]; then
556 # it was a loop device, user confused
561 log_warning_msg "Impossible to include the ${snap_label} Snapshot"
565 echo "export ${snap_type}SNAP="${snap_mount}":${snapdev}:${snapfile}" >> /etc/live.conf # for resync on reboot/halt
573 modprobe "${MP_QUIET}" -b ${UNIONTYPE}
575 # run-init can't deal with images in a subdir, but we're going to
576 # move all of these away before it runs anyway. No, we're not,
577 # put them in / since move-mounting them into / breaks mono and
582 # Let's just mount the read-only file systems first
585 if [ "${NETBOOT}" = "nfs" ] ; then
586 roopt="nfsro" # go aroung a bug in nfs-unionfs locking
591 # Read image names from ${MODULE}.module if it exists
592 if [ -e "${image_directory}/filesystem.${MODULE}.module" ]
594 for IMAGE in `cat ${image_directory}/filesystem.${MODULE}.module`
596 image_string="${image_string} ${image_directory}/${image}"
598 elif [ -e "${image_directory}/${MODULE}.module" ]
600 for IMAGE in `cat ${image_directory}/${MODULE}.module`
602 image_string="${image_string} ${image_directory}/${image}"
605 # ${MODULE}.module does not exist, create a list of images
606 for FILESYSTEM in squashfs ext2 ext3 xfs dir
608 for IMAGE in "${image_directory}"/*."${FILESYSTEM}"
612 image_string="${image_string} ${IMAGE}"
618 image_string="`echo ${image_string} | sed -e 's/ /\n/g' | sort `"
622 for image in ${image_string}; do
623 imagename=$(basename "${image}")
624 if [ -d "${image}" ]; then
625 # it is a plain directory: do nothing
626 rofsstring="${image}=${roopt}:${rofsstring}"
627 rofslist="${image} ${rofslist}"
628 elif [ -f "${image}" ]; then
629 backdev=$(get_backing_device "$image")
630 fstype=$(get_fstype "${backdev}")
631 if [ "${fstype}" = "unknown" ]; then
632 panic "Unknown file system type on ${backdev} (${image})"
634 mkdir -p "${croot}/${imagename}"
635 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}"
638 rofsstring=${rofsstring%:}
644 # Looking for "${root_persistence}" device or file
645 if [ -n "${PERSISTENT}" ]; then
646 cowprobe=$(find_cow_device "${root_persistence}")
647 if [ -b "${cowprobe}" ]; then
648 cowdevice=${cowprobe}
649 cow_fstype=$(get_fstype "${cowprobe}")
651 [ "$quiet" != "y" ] && log_warning_msg "Unable to find the persistent medium"
655 mount ${cowdevice} -t ${cow_fstype} -o rw /cow || panic "Can not mount $cowdevice on /cow"
657 mount -t ${UNIONTYPE} -o dirs=/cow=rw:$rofsstring ${UNIONTYPE} "$rootmnt" || panic "${UNIONTYPE} mount failed"
659 # Adding other custom mounts
660 if [ -n "${PERSISTENT}" ]; then
661 # directly mount /home
662 # FIXME: add a custom mounts configurable system
663 homecow=$(find_cow_device "${home_persistence}" )
664 if [ -b "${homecow}" ]; then
665 mount -t $(get_fstype "${homecow}") -o rw "${homecow}" "${rootmnt}/home"
666 export HOMEMOUNTED=1 # used to proper calculate free space in do_snap_copy()
668 [ "$quiet" != "y" ] && log_warning_msg "Unable to find the persistent home medium"
670 # Look for other snapshots to copy in
671 try_snap "${root_snapshot_label}" "${rootmnt}" "ROOT"
672 try_snap "${home_snapshot_label}" "${rootmnt}/home" "HOME"
675 if [ -n "${SHOWMOUNTS}" ]; then
676 for d in ${rofslist}; do
677 mkdir -p "${rootmnt}/live/${d##*/}"
679 *.dir) # do nothing # mount -o bind "${d}" "${rootmnt}/live/${d##*/}"
681 *) mount --move "${d}" "${rootmnt}/live/${d##*/}"
687 # shows cow fs on /cow for use by live-snapshot
688 mkdir -p "${rootmnt}/live/cow"
689 mount -o bind /cow "${rootmnt}/live/cow"
696 if [ -z "${devname}" ]; then
697 devname=$(sys2dev "${sysdev}")
700 if [ -n "${LIVE_MEDIA_OFFSET}" ]; then
701 loopdevname=$(setup_loop "${devname}" "loop" "/sys/block/loop*" "${LIVE_MEDIA_OFFSET}" '')
702 devname="${loopdevname}"
705 fstype=$(get_fstype "${devname}")
706 if is_supported_fs ${fstype}; then
707 mount -t ${fstype} -o ro "${devname}" $mountpoint || continue
708 if is_live_path $mountpoint; then
716 if [ -n "${LIVE_MEDIA_OFFSET}" ]; then
717 losetup -d "${loopdevname}"
724 # first look at the one specified in the command line
725 if [ ! -z "${LIVE_MEDIA}" ]; then
726 if check_dev "null" "${LIVE_MEDIA}"; then
730 # don't start autodetection before timeout has expired
731 if [ -n "${LIVE_MEDIA_TIMEOUT}" ]; then
732 if [ "${timeout}" -lt "${LIVE_MEDIA_TIMEOUT}" ]; then
736 # or do the scan of block devices
737 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -v loop | grep -v ram); do
738 devname=$(sys2dev "${sysblock}")
739 fstype=$(get_fstype "${devname}")
740 if /lib/udev/cdrom_id ${devname} > /dev/null; then
741 if check_dev "null" "${devname}" ; then
744 elif is_nice_device "${sysblock}" ; then
745 for dev in $(subdevices "${sysblock}"); do
746 if check_dev "${dev}" ; then
750 elif [ "${fstype}" = "squashfs" -o \
751 "${fstype}" = "ext2" -o \
752 "${fstype}" = "ext3" ]; then
753 # This is an ugly hack situation, the block device has
754 # an image directly on it. It's hopefully
755 # live-initramfs, so take it and run with it.
756 ln -s "${devname}" "${devname}.${fstype}"
757 echo "${devname}.${fstype}"
765 if [ -x /sbin/usplash_write ]; then
766 /sbin/usplash_write "PULSATE"
770 set_usplash_timeout() {
771 if [ -x /sbin/usplash_write ]; then
772 /sbin/usplash_write "TIMEOUT 120"
785 [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/live-premount"
787 run_scripts /scripts/live-premount
788 [ "$quiet" != "y" ] && log_end_msg
790 # Needed here too because some things (*cough* udev *cough*)
791 # changes the timeout
795 if [ ! -z "${NETBOOT}" ]; then
796 if do_netmount ; then
797 livefs_root="${mountpoint}"
799 panic "Unable to find a live file system on the network"
802 # Scan local devices for the image
803 for i in 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19; do
804 livefs_root=$(find_livefs $i)
805 if [ -n "${livefs_root}" ]; then
812 if [ -z "${livefs_root}" ]; then
813 panic "Unable to find a medium containing a live file system"
816 if [ "${TORAM}" ]; then
818 elif [ "${TODISK}" ]; then
819 live_dest="${TODISK}"
821 if [ "${live_dest}" ]; then
822 log_begin_msg "Copying live media to ${live_dest}"
823 copy_live_to "${livefs_root}" "${live_dest}"
827 mount_images_in_directory "${livefs_root}" "${rootmnt}"
831 maybe_break live-bottom
832 [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/live-bottom"
835 run_scripts /scripts/live-bottom
836 [ "$quiet" != "y" ] && log_end_msg
840 cp live.log "${rootmnt}/var/log/"