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 NOSWAP="Yes" ;;
66 export NOAUTOLOGIN="Yes" ;;
68 export NOXAUTOLOGIN="Yes" ;;
70 export NOSUDO="Yes" ;;
72 export SHOWMOUNTS="Yes" ;;
74 export PERSISTENT="Yes" ;;
76 export PERSISTENT="" ;;
79 if [ "${STATICIP}" = "" ]; then
84 export LIVE_GETTY=1 ;;
85 bootfrom=*|live-media=*)
86 export LIVE_MEDIA=${x#*=} ;;
87 live-media-encryption=*|encryption=*)
88 export LIVE_MEDIA_ENCRYPTION=${x#*=} ;;
90 export LIVE_MEDIA_TIMEOUT=${x#live-media-timeout=} ;;
92 export LIVE_MEDIA_OFFSET=${x#live-media-offset=} ;;
93 locale=*|debian-installer/locale=*)
94 export LOCALE=${x#*=} ;;
95 keyb=*|kbd-chooser/method=*)
97 klayout=*|console-setup/layoutcode=*)
98 export KLAYOUT=${x#*=} ;;
100 export KOPTIONS=${x#koptions=} ;;
101 kvariant=*|console-setup/variantcode=*)
102 export KVARIANT=${x#*=} ;;
103 kmodel=*|console-setup/modelcode=*)
104 export KMODEL=${x#*=} ;;
106 export MODULE=${x#module=} ;;
107 preseed/file=*|file=*)
108 export LOCATION="${x#*=}" ;;
110 export UPGRADE="Yes" ;;
114 PRESEEDS="${PRESEEDS}\"${question}=${value}\" "
117 export DEFCONSOLE="${x#*=}" ;;
121 # sort of compatibility with netboot.h from linux docs
122 if [ -z "${NETBOOT}" ]; then
123 if [ "${ROOT}" = "/dev/nfs" ]; then
126 elif [ "${ROOT}" = "/dev/cifs" ]; then
132 if [ -z "${MODULE}" ]; then
139 if [ -d "$path/live" ]; then
140 if [ "$(echo $path/live/*.squashfs)" != "$path/live/*.squashfs" ] ||
141 [ "$(echo $path/live/*.ext2)" != "$path/live/*.ext2" ] ||
142 [ "$(echo $path/live/*.ext3)" != "$path/live/*.ext3" ] ||
143 [ "$(echo $path/live/*.dir)" != "$path/live/*.dir" ]; then
150 get_backing_device() {
152 *.squashfs|*.ext2|*.ext3)
153 echo $(setup_loop "$1" "loop" "/sys/block/loop*" '0' "${LIVE_MEDIA_ENCRYPTION}")
159 panic "Unrecognized live filesystem: $1"
164 match_files_in_dir() {
165 # Does any files match pattern $1 ?
168 if [ "$(echo $pattern)" != "$pattern" ]; then
174 mount_images_in_directory() {
177 if match_files_in_dir "$directory/live/*.squashfs" ||
178 match_files_in_dir "$directory/live/*.ext2" ||
179 match_files_in_dir "$directory/live/*.ext3" ||
180 match_files_in_dir "$directory/live/*.dir"; then
181 setup_unionfs "$directory/live" "$rootmnt"
188 sysfs_path="${1#/sys}"
189 if /lib/udev/path_id "${sysfs_path}" | grep -E -q "ID_PATH=(usb|pci-[^-]*-[ide|scsi|usb])"; then
196 # FIXME: do something better like the scan of supported filesystems
199 vfat|iso9660|udf|ext2|ext3|ntfs)
209 copyto="${copyfrom}_swap"
211 size=$(fs_size "" ${copyfrom} "used")
213 if [ "${copytodev}" = "ram" ]; then
215 freespace=$( expr $(awk '/MemFree/{print $2}' /proc/meminfo) + $( cat /proc/meminfo | grep Cached | head -n 1 | awk '/Cached/{print $2}' - ) )
216 mount_options="-o size=${size}k"
221 # it should be a writable block device
222 if [ -b "${copytodev}" ]; then
225 fstype=$(get_fstype "${dev}")
226 freespace=$(fs_size "${dev}")
228 [ "$quiet" != "y" ] && log_warning_msg "${copytodev} is not a block device."
232 if [ "${freespace}" -lt "${size}" ] ; then
233 [ "$quiet" != "y" ] && log_warning_msg "Not enough free ${free_string} (${freespace}k > ${size}k) to copy live media in ${copytodev}."
239 echo "mount -t ${fstype} ${mount_options} ${dev} ${copyto}"
240 mount -t "${fstype}" ${mount_options} "${dev}" "${copyto}"
241 cp -a ${copyfrom}/* ${copyto} # "cp -a" from busybox also copies hidden files
243 mount -r --move ${copyto} ${copyfrom}
251 modprobe "${MP_QUIET}" af_packet # For DHCP
256 ipconfig ${DEVICE} /tmp/net-${DEVICE}.conf | tee /netboot.config
258 if [ "${NFSROOT}" = "auto" ]; then
259 NFSROOT=${ROOTSERVER}:${ROOTPATH}
262 [ "$quiet" != "y" ] && log_begin_msg "Trying netboot from ${NFSROOT}"
264 if [ "${NETBOOT}" != "nfs" ] && do_cifsmount ; then
266 elif do_nfsmount ; then
272 [ "$quiet" != "y" ] && log_end_msg
278 modprobe "${MP_QUIET}" nfs
279 if [ -z "${NFSOPTS}" ]; then
283 [ "$quiet" != "y" ] && log_begin_msg "Trying nfsmount -o nolock -o ro ${NFSOPTS} ${NFSROOT} ${mountpoint}"
284 # FIXME: This for loop is an ugly HACK round an nfs bug
285 for i in 0 1 2 3 4 5 6 7 8 9 a b c d e f 10 11 12 13; do
286 nfsmount -o nolock -o ro ${NFSOPTS} "${NFSROOT}" "${mountpoint}" && rc=0 && break
294 if [ -x "/sbin/mount.cifs" ]; then
295 if [ -z "${NFSOPTS}" ]; then
296 CIFSOPTS="-ouser=root,password="
298 CIFSOPTS="${NFSOPTS}"
301 [ "$quiet" != "y" ] && log_begin_msg "Trying mount.cifs ${NFSROOT} ${mountpoint} ${CIFSOPTS}"
302 modprobe "${MP_QUIET}" cifs
304 if mount.cifs "${NFSROOT}" "${mountpoint}" "${CIFSOPTS}" ; then
317 size=$(fs_size "${fromdev}" "" "used")
319 if [ -b "${fromdev}" ]; then
321 if [ -n "${HOMEMOUNTED}" -a "${snap_type}" = "HOME" ]; then
322 todev=$(cat /proc/mounts | grep -s " $(base_path ${todir}) " | awk '{print $1}' )
323 freespace=$(df -k | grep -s ${todev} | awk '{print $4}')
325 freespace=$( expr $(awk '/MemFree/{print $2}' /proc/meminfo) + $( cat /proc/meminfo | grep Cached | head -n 1 | awk '/Cached/{print $2}' - ))
328 tomount="/mnt/tmpsnap"
329 if [ ! -d "${tomount}" ] ; then
330 mkdir -p "${tomount}"
333 fstype=$(get_fstype "${fromdev}")
334 if [ -n "${fstype}" ]; then
336 mount -t "${fstype}" -o ro "${fromdev}" "${tomount}"
337 cp -a "${tomount}"/* ${todir}
340 log_warning_msg "Unrecognized fstype: ${fstype} on ${fromdev}:${snap_type}"
344 if echo ${fromdev} | grep -qs loop; then
345 losetup -d "${fromdev}"
350 [ "$quiet" != "y" ] && log_warning_msg "Unable to find the snapshot ${snap_type} medium"
356 # Look for $snap_label.* in block devices and copy the contents to $snap_mount
357 # and remember the device and filename for resync on exit in live-initramfs.init
363 snapdata=$(find_files "${snap_label}.squashfs ${snap_label}.cpio.gz ${snap_label}.ext2 ${snap_label}.ext3")
364 if [ ! -z "${snapdata}" ]; then
365 snapdev="$(echo ${snapdata} | cut -f1 -d ' ')"
366 snapback="$(echo ${snapdata} | cut -f2 -d ' ')"
367 snapfile="$(echo ${snapdata} | cut -f3 -d ' ')"
368 if echo "${snapfile}" | grep -qs '\(squashfs\|ext2\|ext3\)'; then
369 # squashfs or ext2/ext3 snapshot
370 dev=$(get_backing_device "${snapback}/${snapfile}")
371 if ! do_snap_copy "${dev}" "${snap_mount}" "${snap_type}"; then
372 log_warning_msg "Impossible to include the ${snapfile} Snapshot"
377 if ! (cd "${snap_mount}" && zcat "${snapback}/${snapfile}" | cpio -i -u -d 2>/dev/null) ; then
378 log_warning_msg "Impossible to include the ${snapfile} Snapshot"
384 dev=$(find_cow_device "${snap_label}")
385 if [ -b ${dev} ]; then
386 if echo "${dev}" | grep -qs loop; then
387 # strange things happens, user confused?
388 snaploop=$( losetup ${dev} | awk '{print $3}' | tr -d '()' )
389 snapfile=$(basename ${snaploop})
390 snapdev=$(cat /proc/mounts | awk '{print $2,$1}' | grep -es "^$( dirname ${snaploop} )" | cut -f2 -d ' ')
394 if ! do_snap_copy "${dev}" "${snap_mount}" "${snap_type}" ; then
395 log_warning_msg "Impossible to include the ${snap_label} Snapshot"
398 if [ -n "${snapfile}" ]; then
399 # it was a loop device, user confused
404 log_warning_msg "Impossible to include the ${snap_label} Snapshot"
408 echo "export ${snap_type}SNAP="${snap_mount}":${snapdev}:${snapfile}" >> /etc/live.conf # for resync on reboot/halt
416 modprobe "${MP_QUIET}" -b unionfs
418 # run-init can't deal with images in a subdir, but we're going to
419 # move all of these away before it runs anyway. No, we're not,
420 # put them in / since move-mounting them into / breaks mono and
425 # Let's just mount the read-only file systems first
428 if [ "${NETBOOT}" = "nfs" ] ; then
429 roopt="nfsro" # go aroung a bug in nfs-unionfs locking
434 # Read image names from ${MODULE}.lst if it exists
435 if [ -e "${image_directory}/${MODULE}.lst" ]; then
436 for image in $(cat "${image_directory}/${MODULE}.lst"); do
437 image_string="${image_string} ${image_directory}/${image}";
440 # If ${MODULE}.lst does not exist, create a list of images
441 for image_type in "ext2" "ext3" "squashfs" "dir"; do
442 for image in "${image_directory}"/*."${image_type}"; do
443 if [ -e "${image}" ]; then
444 image_string="${image_string} ${image}";
449 image_string=$(echo ${image_string} | sed -e 's/ /\n/g' | sort )
453 for image in ${image_string}; do
454 imagename=$(basename "${image}")
455 if [ -d "${image}" ]; then
456 # it is a plain directory: do nothing
457 rofsstring="${image}=${roopt}:${rofsstring}"
458 rofslist="${image} ${rofslist}"
459 elif [ -f "${image}" ]; then
460 backdev=$(get_backing_device "$image")
461 fstype=$(get_fstype "${backdev}")
462 if [ "${fstype}" = "unknown" ]; then
463 panic "Unknown file system type on ${backdev} (${image})"
465 mkdir -p "${croot}/${imagename}"
466 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}"
469 rofsstring=${rofsstring%:}
475 # Looking for "${root_persistence}" device or file
476 if [ -n "${PERSISTENT}" ]; then
477 cowprobe=$(find_cow_device "${root_persistence}")
478 if [ -b "${cowprobe}" ]; then
479 cowdevice=${cowprobe}
480 cow_fstype=$(get_fstype "${cowprobe}")
482 [ "$quiet" != "y" ] && log_warning_msg "Unable to find the persistent medium"
486 mount ${cowdevice} -t ${cow_fstype} -o rw /cow || panic "Can not mount $cowdevice on /cow"
488 mount -t unionfs -o dirs=/cow=rw:$rofsstring unionfs "$rootmnt" || panic "Unionfs mount failed"
490 # Adding other custom mounts
491 if [ -n "${PERSISTENT}" ]; then
492 # directly mount /home
493 # FIXME: add a custom mounts configurable system
494 homecow=$(find_cow_device "${home_persistence}" )
495 if [ -b "${homecow}" ]; then
496 mount -t $(get_fstype "${homecow}") -o rw "${homecow}" "${rootmnt}/home"
497 export HOMEMOUNTED=1 # used to proper calculate free space in do_snap_copy()
499 [ "$quiet" != "y" ] && log_warning_msg "Unable to find the persistent home medium"
501 # Look for other snapshots to copy in
502 try_snap "${root_snapshot_label}" "${rootmnt}" "ROOT"
503 try_snap "${home_snapshot_label}" "${rootmnt}/home" "HOME"
506 if [ -n "${SHOWMOUNTS}" ]; then
507 for d in ${rofslist}; do
508 mkdir -p "${rootmnt}/live/${d##*/}"
510 *.dir) # do nothing # mount -o bind "${d}" "${rootmnt}/live/${d##*/}"
512 *) mount --move "${d}" "${rootmnt}/live/${d##*/}"
518 # shows cow fs on /cow for use by live-snapshot
519 mkdir -p "${rootmnt}/cow"
520 mount -o bind /cow "${rootmnt}/cow"
527 if [ -z "${devname}" ]; then
528 devname=$(sys2dev "${sysdev}")
531 if [ -n "${LIVE_MEDIA_OFFSET}" ]; then
532 loopdevname=$(setup_loop "${devname}" "loop" "/sys/block/loop*" "${LIVE_MEDIA_OFFSET}" '')
533 devname="${loopdevname}"
536 fstype=$(get_fstype "${devname}")
537 if is_supported_fs ${fstype}; then
538 mount -t ${fstype} -o ro "${devname}" $mountpoint || continue
539 if is_live_path $mountpoint; then
547 if [ -n "${LIVE_MEDIA_OFFSET}" ]; then
548 losetup -d "${loopdevname}"
555 # first look at the one specified in the command line
556 if [ ! -z "${LIVE_MEDIA}" ]; then
557 if check_dev "null" "${LIVE_MEDIA}"; then
561 # don't start autodetection before timeout has expired
562 if [ -n "${LIVE_MEDIA_TIMEOUT}" ]; then
563 if [ "${timeout}" -lt "${LIVE_MEDIA_TIMEOUT}" ]; then
567 # or do the scan of block devices
568 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -v loop | grep -v ram); do
569 devname=$(sys2dev "${sysblock}")
570 fstype=$(get_fstype "${devname}")
571 if /lib/udev/cdrom_id ${devname} > /dev/null; then
572 if check_dev "null" "${devname}" ; then
575 elif is_nice_device "${sysblock}" ; then
576 for dev in $(subdevices "${sysblock}"); do
577 if check_dev "${dev}" ; then
581 elif [ "${fstype}" = "squashfs" -o \
582 "${fstype}" = "ext2" -o \
583 "${fstype}" = "ext3" ]; then
584 # This is an ugly hack situation, the block device has
585 # an image directly on it. It's hopefully
586 # live-initramfs, so take it and run with it.
587 ln -s "${devname}" "${devname}.${fstype}"
588 echo "${devname}.${fstype}"
596 if [ -x /sbin/usplash_write ]; then
597 /sbin/usplash_write "PULSATE"
601 set_usplash_timeout() {
602 if [ -x /sbin/usplash_write ]; then
603 /sbin/usplash_write "TIMEOUT 120"
616 [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/live-premount"
618 run_scripts /scripts/live-premount
619 [ "$quiet" != "y" ] && log_end_msg
621 # Needed here too because some things (*cough* udev *cough*)
622 # changes the timeout
626 if [ ! -z "${NETBOOT}" ]; then
627 if do_netmount ; then
628 livefs_root="${mountpoint}"
630 panic "Unable to find a live file system on the network"
633 # Scan local devices for the image
634 for i in 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19; do
635 livefs_root=$(find_livefs $i)
636 if [ -n "${livefs_root}" ]; then
643 if [ -z "${livefs_root}" ]; then
644 panic "Unable to find a medium containing a live file system"
647 if [ "${TORAM}" ]; then
649 elif [ "${TODISK}" ]; then
650 live_dest="${TODISK}"
652 if [ "${live_dest}" ]; then
653 log_begin_msg "Copying live_media to ${live_dest}"
654 copy_live_to "${livefs_root}" "${live_dest}"
658 mount_images_in_directory "${livefs_root}" "${rootmnt}"
662 maybe_break live-bottom
663 [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/live-bottom"
666 run_scripts /scripts/live-bottom
667 [ "$quiet" != "y" ] && log_end_msg
671 cp live.log "${rootmnt}/var/log/"