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#*=}" ;;
112 PRESEEDS="${PRESEEDS}\"${question}=${value}\" "
115 export DEFCONSOLE="${x#*=}" ;;
119 # sort of compatibility with netboot.h from linux docs
120 if [ -z "${NETBOOT}" ]; then
121 if [ "${ROOT}" == "/dev/nfs" ]; then
124 elif [ "${ROOT}" == "/dev/cifs" ]; then
130 if [ -z "${MODULE}" ]; then
137 if [ -d "$path/live" ]; then
138 if [ "$(echo $path/live/*.squashfs)" != "$path/live/*.squashfs" ] ||
139 [ "$(echo $path/live/*.ext2)" != "$path/live/*.ext2" ] ||
140 [ "$(echo $path/live/*.ext3)" != "$path/live/*.ext3" ] ||
141 [ "$(echo $path/live/*.dir)" != "$path/live/*.dir" ]; then
148 get_backing_device() {
150 *.squashfs|*.ext2|*.ext3)
151 echo $(setup_loop "$1" "loop" "/sys/block/loop*" '0' "${LIVE_MEDIA_ENCRYPTION}")
157 panic "Unrecognized live filesystem: $1"
162 match_files_in_dir() {
163 # Does any files match pattern $1 ?
166 if [ "$(echo $pattern)" != "$pattern" ]; then
172 mount_images_in_directory() {
175 if match_files_in_dir "$directory/live/*.squashfs" ||
176 match_files_in_dir "$directory/live/*.ext2" ||
177 match_files_in_dir "$directory/live/*.ext3" ||
178 match_files_in_dir "$directory/live/*.dir"; then
179 setup_unionfs "$directory/live" "$rootmnt"
186 sysfs_path="${1#/sys}"
187 if /lib/udev/path_id "${sysfs_path}" | grep -E -q "ID_PATH=(usb|pci-[^-]*-[ide|scsi|usb])"; then
194 # FIXME: do something better like the scan of supported filesystems
197 vfat|iso9660|udf|ext2|ext3|ntfs)
207 copyto="${copyfrom}_swap"
209 size=$(fs_size "" ${copyfrom} "used")
211 if [ "${copytodev}" = "ram" ]; then
213 freespace=$( expr $(awk '/MemFree/{print $2}' /proc/meminfo) + $( cat /proc/meminfo | grep Cached | head -n 1 | awk '/Cached/{print $2}' - ) )
214 mount_options="-o size=${size}k"
219 # it should be a writable block device
220 if [ -b "${copytodev}" ]; then
223 fstype=$(get_fstype "${dev}")
224 freespace=$(fs_size "${dev}")
226 [ "$quiet" != "y" ] && log_warning_msg "${copytodev} is not a block device."
230 if [ "${freespace}" -lt "${size}" ] ; then
231 [ "$quiet" != "y" ] && log_warning_msg "Not enough free ${free_string} (${freespace}k > ${size}k) to copy live media in ${copytodev}."
237 echo "mount -t ${fstype} ${mount_options} ${dev} ${copyto}"
238 mount -t "${fstype}" ${mount_options} "${dev}" "${copyto}"
239 cp -a ${copyfrom}/* ${copyto} # "cp -a" from busybox also copies hidden files
241 mount -r --move ${copyto} ${copyfrom}
249 modprobe "${MP_QUIET}" af_packet # For DHCP
254 ipconfig ${DEVICE} /tmp/net-${DEVICE}.conf | tee /netboot.config
256 if [ "${NFSROOT}" = "auto" ]; then
257 NFSROOT=${ROOTSERVER}:${ROOTPATH}
260 [ "$quiet" != "y" ] && log_begin_msg "Trying netboot from ${NFSROOT}"
262 if [ "${NETBOOT}" != "nfs" ] && do_cifsmount ; then
264 elif do_nfsmount ; then
270 [ "$quiet" != "y" ] && log_end_msg
276 modprobe "${MP_QUIET}" nfs
277 if [ -z "${NFSOPTS}" ]; then
281 [ "$quiet" != "y" ] && log_begin_msg "Trying nfsmount -o nolock -o ro ${NFSOPTS} ${NFSROOT} ${mountpoint}"
282 # FIXME: This for loop is an ugly HACK round an nfs bug
283 for i in 0 1 2 3 4 5 6 7 8 9 a b c d e f 10 11 12 13; do
284 nfsmount -o nolock -o ro ${NFSOPTS} "${NFSROOT}" "${mountpoint}" && rc=0 && break
292 if [ -x "/sbin/mount.cifs" ]; then
293 if [ -z "${NFSOPTS}" ]; then
294 CIFSOPTS="-ouser=root,password="
296 CIFSOPTS="${NFSOPTS}"
299 [ "$quiet" != "y" ] && log_begin_msg "Trying mount.cifs ${NFSROOT} ${mountpoint} ${CIFSOPTS}"
300 modprobe "${MP_QUIET}" cifs
302 if mount.cifs "${NFSROOT}" "${mountpoint}" "${CIFSOPTS}" ; then
315 size=$(fs_size "${fromdev}" "" "used")
317 if [ -b "${fromdev}" ]; then
319 if [ -n "${HOMEMOUNTED}" -a "${snap_type}" = "HOME" ]; then
320 todev=$(cat /proc/mounts | grep -s " $(base_path ${todir}) " | awk '{print $1}' )
321 freespace=$(df -k | grep -s ${todev} | awk '{print $4}')
323 freespace=$( expr $(awk '/MemFree/{print $2}' /proc/meminfo) + $( cat /proc/meminfo | grep Cached | head -n 1 | awk '/Cached/{print $2}' - ))
326 tomount="/mnt/tmpsnap"
327 if [ ! -d "${tomount}" ] ; then
328 mkdir -p "${tomount}"
331 fstype=$(get_fstype "${fromdev}")
332 if [ -n "${fstype}" ]; then
334 mount -t "${fstype}" -o ro "${fromdev}" "${tomount}"
335 cp -a "${tomount}"/* ${todir}
338 log_warning_msg "Unrecognized fstype: ${fstype} on ${fromdev}:${snap_type}"
342 if echo ${fromdev} | grep -qs loop; then
343 losetup -d "${fromdev}"
348 [ "$quiet" != "y" ] && log_warning_msg "Unable to find the snapshot ${snap_type} medium"
354 # Look for $snap_label.* in block devices and copy the contents to $snap_mount
355 # and remember the device and filename for resync on exit in live-initramfs.init
361 snapdata=$(find_files "${snap_label}.squashfs ${snap_label}.cpio.gz ${snap_label}.ext2 ${snap_label}.ext3")
362 if [ ! -z "${snapdata}" ]; then
363 snapdev="$(echo ${snapdata} | cut -f1 -d ' ')"
364 snapback="$(echo ${snapdata} | cut -f2 -d ' ')"
365 snapfile="$(echo ${snapdata} | cut -f3 -d ' ')"
366 if echo "${snapfile}" | grep -qs '\(squashfs\|ext2\|ext3\)'; then
367 # squashfs or ext2/ext3 snapshot
368 dev=$(get_backing_device "${snapback}/${snapfile}")
369 if ! do_snap_copy "${dev}" "${snap_mount}" "${snap_type}"; then
370 log_warning_msg "Impossible to include the ${snapfile} Snapshot"
375 if ! (cd "${snap_mount}" && zcat "${snapback}/${snapfile}" | cpio -i -u -d 2>/dev/null) ; then
376 log_warning_msg "Impossible to include the ${snapfile} Snapshot"
382 dev=$(find_cow_device "${snap_label}")
383 if [ -b ${dev} ]; then
384 if echo "${dev}" | grep -qs loop; then
385 # strange things happens, user confused?
386 snaploop=$( losetup ${dev} | awk '{print $3}' | tr -d '()' )
387 snapfile=$(basename ${snaploop})
388 snapdev=$(cat /proc/mounts | awk '{print $2,$1}' | grep -es "^$( dirname ${snaploop} )" | cut -f2 -d ' ')
392 if ! do_snap_copy "${dev}" "${snap_mount}" "${snap_type}" ; then
393 log_warning_msg "Impossible to include the ${snap_label} Snapshot"
396 if [ -n "${snapfile}" ]; then
397 # it was a loop device, user confused
402 log_warning_msg "Impossible to include the ${snap_label} Snapshot"
406 echo "export ${snap_type}SNAP="${snap_mount}":${snapdev}:${snapfile}" >> /etc/live.conf # for resync on reboot/halt
414 modprobe "${MP_QUIET}" -b unionfs
416 # run-init can't deal with images in a subdir, but we're going to
417 # move all of these away before it runs anyway. No, we're not,
418 # put them in / since move-mounting them into / breaks mono and
423 # Let's just mount the read-only file systems first
426 if [ "${NETBOOT}" = "nfs" ] ; then
427 roopt="nfsro" # go aroung a bug in nfs-unionfs locking
432 # Read image names from ${MODULE}.lst if it exists
433 if [ -e "${image_directory}/${MODULE}.lst" ]; then
434 for image in $(cat "${image_directory}/${MODULE}.lst"); do
435 image_string="${image_string} ${image_directory}/${image}";
438 # If ${MODULE}.lst does not exist, create a list of images
439 for image_type in "ext2" "ext3" "squashfs" "dir"; do
440 for image in "${image_directory}"/*."${image_type}"; do
441 if [ -e "${image}" ]; then
442 image_string="${image_string} ${image}";
447 image_string=$(echo ${image_string} | sed -e 's/ /\n/g' | sort )
451 for image in ${image_string}; do
452 imagename=$(basename "${image}")
453 if [ -d "${image}" ]; then
454 # it is a plain directory: do nothing
455 rofsstring="${image}=${roopt}:${rofsstring}"
456 rofslist="${image} ${rofslist}"
457 elif [ -f "${image}" ]; then
458 backdev=$(get_backing_device "$image")
459 fstype=$(get_fstype "${backdev}")
460 if [ "${fstype}" = "unknown" ]; then
461 panic "Unknown file system type on ${backdev} (${image})"
463 mkdir -p "${croot}/${imagename}"
464 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}"
467 rofsstring=${rofsstring%:}
473 # Looking for "${root_persistence}" device or file
474 if [ -n "${PERSISTENT}" ]; then
475 cowprobe=$(find_cow_device "${root_persistence}")
476 if [ -b "${cowprobe}" ]; then
477 cowdevice=${cowprobe}
478 cow_fstype=$(get_fstype "${cowprobe}")
480 [ "$quiet" != "y" ] && log_warning_msg "Unable to find the persistent medium"
484 mount ${cowdevice} -t ${cow_fstype} -o rw /cow || panic "Can not mount $cowdevice on /cow"
486 mount -t unionfs -o dirs=/cow=rw:$rofsstring unionfs "$rootmnt" || panic "Unionfs mount failed"
488 # Adding other custom mounts
489 if [ -n "${PERSISTENT}" ]; then
490 # directly mount /home
491 # FIXME: add a custom mounts configurable system
492 homecow=$(find_cow_device "${home_persistence}" )
493 if [ -b "${homecow}" ]; then
494 mount -t $(get_fstype "${homecow}") -o rw "${homecow}" "${rootmnt}/home"
495 export HOMEMOUNTED=1 # used to proper calculate free space in do_snap_copy()
497 [ "$quiet" != "y" ] && log_warning_msg "Unable to find the persistent home medium"
499 # Look for other snapshots to copy in
500 try_snap "${root_snapshot_label}" "${rootmnt}" "ROOT"
501 try_snap "${home_snapshot_label}" "${rootmnt}/home" "HOME"
504 if [ -n "${SHOWMOUNTS}" ]; then
505 for d in ${rofslist}; do
506 mkdir -p "${rootmnt}/live/${d##*/}"
508 *.dir) # do nothing # mount -o bind "${d}" "${rootmnt}/live/${d##*/}"
510 *) mount --move "${d}" "${rootmnt}/live/${d##*/}"
516 # shows cow fs on /cow for use by live-snapshot
517 mkdir -p "${rootmnt}/cow"
518 mount -o bind /cow "${rootmnt}/cow"
525 if [ -z "${devname}" ]; then
526 devname=$(sys2dev "${sysdev}")
529 if [ -n "${LIVE_MEDIA_OFFSET}" ]; then
530 loopdevname=$(setup_loop "${devname}" "loop" "/sys/block/loop*" "${LIVE_MEDIA_OFFSET}" '')
531 devname="${loopdevname}"
534 fstype=$(get_fstype "${devname}")
535 if is_supported_fs ${fstype}; then
536 mount -t ${fstype} -o ro "${devname}" $mountpoint || continue
537 if is_live_path $mountpoint; then
545 if [ -n "${LIVE_MEDIA_OFFSET}" ]; then
546 losetup -d "${loopdevname}"
553 # first look at the one specified in the command line
554 if [ ! -z "${LIVE_MEDIA}" ]; then
555 if check_dev "null" "${LIVE_MEDIA}"; then
559 # don't start autodetection before timeout has expired
560 if [ -n "${LIVE_MEDIA_TIMEOUT}" ]; then
561 if [ "${timeout}" -lt "${LIVE_MEDIA_TIMEOUT}" ]; then
565 # or do the scan of block devices
566 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -v loop | grep -v ram); do
567 devname=$(sys2dev "${sysblock}")
568 fstype=$(get_fstype "${devname}")
569 if /lib/udev/cdrom_id ${devname} > /dev/null; then
570 if check_dev "null" "${devname}" ; then
573 elif is_nice_device "${sysblock}" ; then
574 for dev in $(subdevices "${sysblock}"); do
575 if check_dev "${dev}" ; then
579 elif [ "${fstype}" = "squashfs" -o \
580 "${fstype}" = "ext2" -o \
581 "${fstype}" = "ext3" ]; then
582 # This is an ugly hack situation, the block device has
583 # an image directly on it. It's hopefully
584 # live-initramfs, so take it and run with it.
585 ln -s "${devname}" "${devname}.${fstype}"
586 echo "${devname}.${fstype}"
594 if [ -x /sbin/usplash_write ]; then
595 /sbin/usplash_write "PULSATE"
599 set_usplash_timeout() {
600 if [ -x /sbin/usplash_write ]; then
601 /sbin/usplash_write "TIMEOUT 120"
614 [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/live-premount"
616 run_scripts /scripts/live-premount
617 [ "$quiet" != "y" ] && log_end_msg
619 # Needed here too because some things (*cough* udev *cough*)
620 # changes the timeout
624 if [ ! -z "${NETBOOT}" ]; then
625 if do_netmount ; then
626 livefs_root="${mountpoint}"
628 panic "Unable to find a live file system on the network"
631 # Scan local devices for the image
632 for i in 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19; do
633 livefs_root=$(find_livefs $i)
634 if [ -n "${livefs_root}" ]; then
641 if [ -z "${livefs_root}" ]; then
642 panic "Unable to find a medium containing a live file system"
645 if [ "${TORAM}" ]; then
647 elif [ "${TODISK}" ]; then
648 live_dest="${TODISK}"
650 if [ "${live_dest}" ]; then
651 log_begin_msg "Copying live_media to ${live_dest}"
652 copy_live_to "${livefs_root}" "${live_dest}"
656 mount_images_in_directory "${livefs_root}" "${rootmnt}"
660 maybe_break live-bottom
661 [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/live-bottom"
664 run_scripts /scripts/live-bottom
665 [ "$quiet" != "y" ] && log_end_msg
669 cp live.log "${rootmnt}/var/log/"