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"
23 mkdir -p "${mountpoint}"
25 [ -f /etc/live.conf ] && . /etc/live.conf
26 export USERNAME USERFULLNAME HOSTNAME BUILD_SYSTEM
28 . /scripts/live-helpers
30 if [ ! -f /live.vars ]
39 for ARGUMENT in $(cat /proc/cmdline)
43 ACCESS="${ARGUMENT#access=}"
48 DEFCONSOLE="${ARGUMENT#*=}"
60 FETCH="${ARGUMENT#fetch=}"
65 HOSTNAME="${ARGUMENT#hostname=}"
67 export HOSTNAME LIVECONF
71 USERNAME="${ARGUMENT#username=}"
73 export USERNAME LIVECONF
77 USERFULLNAME="${ARGUMENT#userfullname=}"
79 export USERFULLNAME LIVECONF
83 STATICIP="${ARGUMENT#ip=}"
85 if [ -z "${STATICIP}" ]
93 keyb=*|kbd-chooser/method=*)
98 klayout=*|console-setup/layoutcode=*)
99 KLAYOUT="${ARGUMENT#*=}"
103 kvariant=*|console-setup/variantcode=*)
104 KVARIANT="${ARGUMENT#*=}"
108 kmodel=*|console-setup/modelcode=*)
109 KMODEL="${ARGUMENT#*=}"
114 KOPTIONS="${ARGUMENT#koptions=}"
123 live-media=*|bootfrom=*)
124 LIVE_MEDIA="${ARGUMENT#*=}"
128 live-media-encryption=*|encryption=*)
129 LIVE_MEDIA_ENCRYPTION="${ARGUMENT#*=}"
130 export LIVE_MEDIA_ENCRYPTION
134 LIVE_MEDIA_OFFSET="${ARGUMENT#live-media-offset=}"
135 export LIVE_MEDIA_OFFSET
139 LIVE_MEDIA_PATH="${ARGUMENT#live-media-path=}"
140 export LIVE_MEDIA_PATH
143 live-media-timeout=*)
144 LIVE_MEDIA_TIMEOUT="${ARGUMENT#live-media-timeout=}"
145 export LIVE_MEDIA_TIMEOUT
148 locale=*|debian-installer/locale=*)
149 LOCALE="${ARGUMENT#*=}"
154 MODULE="${ARGUMENT#module=}"
159 NETBOOT="${ARGUMENT#netboot=}"
164 NFSOPTS="${ARGUMENT#nfsopts=}"
169 NOACCESSIBILITY="Yes"
170 export NOACCESSIBILITY
194 NOCONSOLEKEYBOARD="Yes"
195 export NOCONSOLEKEYBOARD
219 NOKPERSONALIZER="Yes"
220 export NOKPERSONALIZER
229 NOLANGUAGESELECTOR="Yes"
230 export NOLANGUAGESELECTOR
244 NOPOWERMANAGEMENT="Yes"
245 export NOPOWERMANAGEMENT
249 NOPROGRAMCRASHES="Yes"
250 export NOPROGRAMCRASHES
254 NORESTRICTEDMANAGER="Yes"
255 export NORESTRICTEDMANAGER
269 NOUPDATENOTIFIER="Yes"
270 export NOUPDATENOTIFIER
285 export NOXSCREENSAVER
298 preseed/file=*|file=*)
299 LOCATION="${ARGUMENT#*=}"
309 location="${ARGUMENT#url=}"
311 mount -n -o bind /sys /root/sys
312 mount -n -o bind /proc /root/proc
313 mount -n -o bind /dev /root/dev
315 mkdir -p /root/var/run/network
317 chroot /root wget -P /tmp "${location}"
318 chroot /root ifdown -a
324 LOCATION="/tmp/$(basename "${location}")"
328 question="${ARGUMENT%%=*}"
329 value="${ARGUMENT#*=}"
330 PRESEEDS="${PRESEEDS}\"${question}=${value}\" "
345 TIMEZONE="${ARGUMENT#timezone=}"
355 TODISK="${ARGUMENT#todisk=}"
366 MODULETORAM="${ARGUMENT#toram=}"
367 export TORAM MODULETORAM
371 UNIONTYPE="${ARGUMENT#union=}"
376 UTC="${ARGUMENT#utc=}"
386 XVIDEOMODE="${ARGUMENT#xvideomode=}"
392 # sort of compatibility with netboot.h from linux docs
393 if [ -z "${NETBOOT}" ]
395 if [ "${ROOT}" = "/dev/nfs" ]
399 elif [ "${ROOT}" = "/dev/cifs" ]
406 if [ -z "${MODULE}" ]
412 if [ -z "${UNIONTYPE}" ]
423 if [ -d "${DIRECTORY}"/"${LIVE_MEDIA_PATH}" ]
425 for FILESYSTEM in squashfs ext2 ext3 xfs dir
427 if [ "$(echo ${DIRECTORY}/${LIVE_MEDIA_PATH}/*.${FILESYSTEM})" != "${DIRECTORY}/${LIVE_MEDIA_PATH}/*.${FILESYSTEM}" ]
437 get_backing_device ()
440 *.squashfs|*.ext2|*.ext3)
441 echo $(setup_loop "${1}" "loop" "/sys/block/loop*" '0' "${LIVE_MEDIA_ENCRYPTION}")
449 panic "Unrecognized live filesystem: ${1}"
454 match_files_in_dir ()
456 # Does any files match pattern ${1} ?
459 if [ "$(echo ${pattern})" != "${pattern}" ]
467 mount_images_in_directory ()
472 if match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.squashfs" ||
473 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.ext2" ||
474 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.ext3" ||
475 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.dir"
477 setup_unionfs "${directory}/${LIVE_MEDIA_PATH}" "${rootmnt}"
485 sysfs_path="${1#/sys}"
487 if /lib/udev/path_id "${sysfs_path}" | grep -E -q "ID_PATH=(usb|pci-[^-]*-[ide|scsi|usb])"
497 # FIXME: do something better like the scan of supported filesystems
501 vfat|iso9660|udf|ext2|ext3|ntfs)
513 copyto="${copyfrom}_swap"
515 if [ -z "${MODULETORAM}" ]
517 size=$(fs_size "" ${copyfrom} "used")
519 MODULETORAMFILE="${copyfrom}/${LIVE_MEDIA_PATH}/${MODULETORAM}"
521 if [ -f "${MODULETORAMFILE}" ]
523 size=$( expr $(ls -la ${MODULETORAMFILE} | awk '{print $5}') / 1024 + 5000 )
525 log_warning_msg "Error: toram-module ${MODULETORAM} (${MODULETORAMFILE}) could not be read."
530 if [ "${copytodev}" = "ram" ]
533 freespace=$( expr $(awk '/MemFree/{print $2}' /proc/meminfo) + $( cat /proc/meminfo | grep Cached | head -n 1 | awk '/Cached/{print $2}' - ) )
534 mount_options="-o size=${size}k"
539 # it should be a writable block device
540 if [ -b "${copytodev}" ]
544 fstype=$(get_fstype "${dev}")
545 freespace=$(fs_size "${dev}")
547 [ "$quiet" != "y" ] && log_warning_msg "${copytodev} is not a block device."
552 if [ "${freespace}" -lt "${size}" ]
554 [ "${quiet}" != "y" ] && log_warning_msg "Not enough free ${free_string} (${freespace}k free, ${size}k needed) to copy live media in ${copytodev}."
558 # begin copying (or uncompressing)
560 echo "mount -t ${fstype} ${mount_options} ${dev} ${copyto}"
561 mount -t "${fstype}" ${mount_options} "${dev}" "${copyto}"
563 if [ "${extension}" = "tgz" ]
566 tar zxf "${copyfrom}/${LIVE_MEDIA_PATH}/$(basename ${FETCH})"
567 rm -f "${copyfrom}/${LIVE_MEDIA_PATH}/$(basename ${FETCH})"
568 mount -r --move "${copyto}" "${rootmnt}"
571 if [ -n "${MODULETORAMFILE}" ]
573 cp ${MODULETORAMFILE} ${copyto} # copy only the filesystem module
575 cp -a ${copyfrom}/* ${copyto} # "cp -a" from busybox also copies hidden files
580 mount -r --move ${copyto} ${copyfrom}
591 modprobe "${MP_QUIET}" af_packet # For DHCP
596 ipconfig ${DEVICE} | tee /netboot.config
598 # source relevant ipconfig output
599 OLDHOSTNAME=${HOSTNAME}
600 . /tmp/net-${DEVICE}.conf
601 [ -z ${HOSTNAME} ] && HOSTNAME=${OLDHOSTNAME}
604 if [ "${NFSROOT}" = "auto" ]
606 NFSROOT=${ROOTSERVER}:${ROOTPATH}
609 if [ -n "${FETCH}" ] && do_httpmount
615 if [ "${NFSROOT#*:}" = "${NFSROOT}" ] && [ "$NETBOOT" != "cifs" ]
617 NFSROOT=${ROOTSERVER}:${NFSROOT}
620 [ "${quiet}" != "y" ] && log_begin_msg "Trying netboot from ${NFSROOT}"
622 if [ "${NETBOOT}" != "nfs" ] && do_cifsmount
632 [ "${quiet}" != "y" ] && log_end_msg
639 extension=$(echo "${FETCH}" | sed 's/\(.*\)\.\(.*\)/\2/')
641 case "${extension}" in
643 [ "${quiet}" != "y" ] && log_begin_msg "Trying wget ${FETCH} -O ${mountpoint}/$(basename ${FETCH})"
644 mkdir -p "${mountpoint}/${LIVE_MEDIA_PATH}"
645 wget "${FETCH}" -O "${mountpoint}/${LIVE_MEDIA_PATH}/$(basename ${FETCH})"
646 [ ${?} -eq 0 ] && rc=0
647 [ "${extension}" = "tgz" ] && live_dest="ram"
651 [ "${quiet}" != "y" ] && log_begin_msg "Unrecognized archive extension for ${FETCH}"
661 modprobe "${MP_QUIET}" nfs
663 if [ -z "${NFSOPTS}" ]
668 [ "${quiet}" != "y" ] && log_begin_msg "Trying nfsmount -o nolock -o ro ${NFSOPTS} ${NFSROOT} ${mountpoint}"
670 # FIXME: This for loop is an ugly HACK round an nfs bug
671 for i in 0 1 2 3 4 5 6 7 8 9 a b c d e f 10 11 12 13
673 nfsmount -o nolock -o ro ${NFSOPTS} "${NFSROOT}" "${mountpoint}" && rc=0 && break
684 if [ -x "/sbin/mount.cifs" ]
686 if [ -z "${NFSOPTS}" ]
688 CIFSOPTS="-ouser=root,password="
690 CIFSOPTS="${NFSOPTS}"
693 [ "${quiet}" != "y" ] && log_begin_msg "Trying mount.cifs ${NFSROOT} ${mountpoint} ${CIFSOPTS}"
694 modprobe "${MP_QUIET}" cifs
696 if mount.cifs "${NFSROOT}" "${mountpoint}" "${CIFSOPTS}"
710 size=$(fs_size "${fromdev}" "" "used")
712 if [ -b "${fromdev}" ]
715 if [ -n "${HOMEMOUNTED}" -a "${snap_type}" = "HOME" ]
717 todev=$(cat /proc/mounts | grep -s " $(base_path ${todir}) " | awk '{print $1}' )
718 freespace=$(df -k | grep -s ${todev} | awk '{print $4}')
720 freespace=$( expr $(awk '/MemFree/{print $2}' /proc/meminfo) + $( cat /proc/meminfo | grep Cached | head -n 1 | awk '/Cached/{print $2}' - ))
723 tomount="/mnt/tmpsnap"
725 if [ ! -d "${tomount}" ]
727 mkdir -p "${tomount}"
730 fstype=$(get_fstype "${fromdev}")
732 if [ -n "${fstype}" ]
735 mount -t "${fstype}" -o ro,noatime "${fromdev}" "${tomount}"
736 cp -a "${tomount}"/* ${todir}
739 log_warning_msg "Unrecognized fstype: ${fstype} on ${fromdev}:${snap_type}"
744 if echo ${fromdev} | grep -qs loop
746 losetup -d "${fromdev}"
753 [ "${quiet}" != "y" ] && log_warning_msg "Unable to find the snapshot ${snap_type} medium"
759 # Look for ${snap_label}.* in block devices and copy the contents to ${snap_mount}
760 # and remember the device and filename for resync on exit in live-initramfs.init
765 snapdata=$(find_files "${snap_label}.squashfs ${snap_label}.cpio.gz ${snap_label}.ext2 ${snap_label}.ext3")
767 if [ ! -z "${snapdata}" ]
769 snapdev="$(echo ${snapdata} | cut -f1 -d ' ')"
770 snapback="$(echo ${snapdata} | cut -f2 -d ' ')"
771 snapfile="$(echo ${snapdata} | cut -f3 -d ' ')"
773 if echo "${snapfile}" | grep -qs '\(squashfs\|ext2\|ext3\)'
775 # squashfs or ext2/ext3 snapshot
776 dev=$(get_backing_device "${snapback}/${snapfile}")
778 if ! do_snap_copy "${dev}" "${snap_mount}" "${snap_type}"
780 log_warning_msg "Impossible to include the ${snapfile} Snapshot"
785 if ! (cd "${snap_mount}" && zcat "${snapback}/${snapfile}" | cpio -i -u -d 2>/dev/null)
787 log_warning_msg "Impossible to include the ${snapfile} Snapshot"
794 dev=$(find_cow_device "${snap_label}")
798 if echo "${dev}" | grep -qs loop
800 # strange things happens, user confused?
801 snaploop=$( losetup ${dev} | awk '{print $3}' | tr -d '()' )
802 snapfile=$(basename ${snaploop})
803 snapdev=$(cat /proc/mounts | awk '{print $2,$1}' | grep -es "^$( dirname ${snaploop} )" | cut -f2 -d ' ')
808 if ! do_snap_copy "${dev}" "${snap_mount}" "${snap_type}"
810 log_warning_msg "Impossible to include the ${snap_label} Snapshot"
813 if [ -n "${snapfile}" ]
815 # it was a loop device, user confused
820 log_warning_msg "Impossible to include the ${snap_label} Snapshot"
825 echo "export ${snap_type}SNAP="${snap_mount}":${snapdev}:${snapfile}" >> /etc/live.conf # for resync on reboot/halt
831 image_directory="${1}"
834 modprobe "${MP_QUIET}" -b ${UNIONTYPE}
836 # run-init can't deal with images in a subdir, but we're going to
837 # move all of these away before it runs anyway. No, we're not,
838 # put them in / since move-mounting them into / breaks mono and
843 # Let's just mount the read-only file systems first
846 minor_kernel_version=$(uname -r|cut -c 5-|sed 's/[^0-9].*//')
848 if [ "${NETBOOT}" = "nfs" ] && [ "${minor_kernel_version}" -lt 22 ]
850 # go aroung a bug in nfs-unionfs locking for unionfs <= 1.4
856 # Read image names from ${MODULE}.module if it exists
857 if [ -e "${image_directory}/filesystem.${MODULE}.module" ]
859 for IMAGE in $(cat ${image_directory}/filesystem.${MODULE}.module)
861 image_string="${image_string} ${image_directory}/${IMAGE}"
863 elif [ -e "${image_directory}/${MODULE}.module" ]
865 for IMAGE in $(cat ${image_directory}/${MODULE}.module)
867 image_string="${image_string} ${image_directory}/${IMAGE}"
870 # ${MODULE}.module does not exist, create a list of images
871 for FILESYSTEM in squashfs ext2 ext3 xfs dir
873 for IMAGE in "${image_directory}"/*."${FILESYSTEM}"
877 image_string="${image_string} ${IMAGE}"
883 image_string="$(echo ${image_string} | sed -e 's/ /\n/g' | sort )"
886 [ -n "${MODULETORAMFILE}" ] && image_string="${image_directory}/$(basename ${MODULETORAMFILE})"
890 for image in ${image_string}
892 imagename=$(basename "${image}")
896 # it is a plain directory: do nothing
897 rofsstring="${image}=${roopt}:${rofsstring}"
898 rofslist="${image} ${rofslist}"
899 elif [ -f "${image}" ]
901 backdev=$(get_backing_device "${image}")
902 fstype=$(get_fstype "${backdev}")
904 if [ "${fstype}" = "unknown" ]
906 panic "Unknown file system type on ${backdev} (${image})"
909 mkdir -p "${croot}/${imagename}"
910 echo "debug: Can not mount backdev ${backdev} (image = ${image}) on croot/imagename ${croot}/${imagename}"
911 mount -t "${fstype}" -o ro,noatime "${backdev}" "${croot}/${imagename}" || panic "Can not mount ${backdev} (${image}) on ${croot}/${imagename}" && rofsstring="${croot}/${imagename}=${roopt}:${rofsstring}" && rofslist="${croot}/${imagename} ${rofslist}"
915 rofsstring=${rofsstring%:}
921 # Looking for "${root_persistence}" device or file
922 if [ -n "${PERSISTENT}" ]
924 cowprobe=$(find_cow_device "${root_persistence}")
926 if [ -b "${cowprobe}" ]
928 cowdevice=${cowprobe}
929 cow_fstype=$(get_fstype "${cowprobe}")
931 [ "${quiet}" != "y" ] && log_warning_msg "Unable to find the persistent medium"
935 mount ${cowdevice} -t ${cow_fstype} -o rw,noatime /cow || panic "Can not mount ${cowdevice} on /cow"
937 mount -t ${UNIONTYPE} -o noatime,dirs=/cow=rw:${rofsstring} ${UNIONTYPE} "${rootmnt}" || panic "${UNIONTYPE} mount failed"
939 # Adding other custom mounts
940 if [ -n "${PERSISTENT}" ]
942 # directly mount /home
943 # FIXME: add a custom mounts configurable system
944 homecow=$(find_cow_device "${home_persistence}" )
946 if [ -b "${homecow}" ]
948 mount -t $(get_fstype "${homecow}") -o rw,noatime "${homecow}" "${rootmnt}/home"
949 export HOMEMOUNTED=1 # used to proper calculate free space in do_snap_copy()
951 [ "${quiet}" != "y" ] && log_warning_msg "Unable to find the persistent home medium"
954 # Look for other snapshots to copy in
955 try_snap "${root_snapshot_label}" "${rootmnt}" "ROOT"
956 try_snap "${home_snapshot_label}" "${rootmnt}/home" "HOME"
959 if [ -n "${SHOWMOUNTS}" ]
963 mkdir -p "${rootmnt}/live/${d##*/}"
967 # do nothing # mount -o bind "${d}" "${rootmnt}/live/${d##*/}"
971 mount --move "${d}" "${rootmnt}/live/${d##*/}"
977 # shows cow fs on /cow for use by live-snapshot
978 mkdir -p "${rootmnt}/live/cow"
979 mount -o move /cow "${rootmnt}/live/cow"
987 if [ -z "${devname}" ]
989 devname=$(sys2dev "${sysdev}")
992 if [ -n "${LIVE_MEDIA_OFFSET}" ]
994 loopdevname=$(setup_loop "${devname}" "loop" "/sys/block/loop*" "${LIVE_MEDIA_OFFSET}" '')
995 devname="${loopdevname}"
998 fstype=$(get_fstype "${devname}")
1000 if is_supported_fs ${fstype}
1002 mount -t ${fstype} -o ro,noatime "${devname}" ${mountpoint} || continue
1004 if is_live_path ${mountpoint}
1009 umount ${mountpoint}
1013 if [ -n "${LIVE_MEDIA_OFFSET}" ]
1015 losetup -d "${loopdevname}"
1025 # first look at the one specified in the command line
1026 if [ ! -z "${LIVE_MEDIA}" ]
1028 if check_dev "null" "${LIVE_MEDIA}"
1034 # don't start autodetection before timeout has expired
1035 if [ -n "${LIVE_MEDIA_TIMEOUT}" ]
1037 if [ "${timeout}" -lt "${LIVE_MEDIA_TIMEOUT}" ]
1043 # or do the scan of block devices
1044 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -v loop | grep -v ram)
1046 devname=$(sys2dev "${sysblock}")
1047 fstype=$(get_fstype "${devname}")
1049 if /lib/udev/cdrom_id ${devname} > /dev/null
1051 if check_dev "null" "${devname}"
1055 elif is_nice_device "${sysblock}"
1057 for dev in $(subdevices "${sysblock}")
1059 if check_dev "${dev}"
1064 elif [ "${fstype}" = "squashfs" -o \
1065 "${fstype}" = "ext2" -o \
1066 "${fstype}" = "ext3" ]
1068 # This is an ugly hack situation, the block device has
1069 # an image directly on it. It's hopefully
1070 # live-initramfs, so take it and run with it.
1071 ln -s "${devname}" "${devname}.${fstype}"
1072 echo "${devname}.${fstype}"
1082 if [ -x /sbin/usplash_write ]
1084 /sbin/usplash_write "PULSATE"
1088 set_usplash_timeout ()
1090 if [ -x /sbin/usplash_write ]
1092 /sbin/usplash_write "TIMEOUT 120"
1106 [ "${quiet}" != "y" ] && log_begin_msg "Running /scripts/live-premount"
1108 run_scripts /scripts/live-premount
1109 [ "${quiet}" != "y" ] && log_end_msg
1111 # Needed here too because some things (*cough* udev *cough*)
1112 # changes the timeout
1116 if [ ! -z "${NETBOOT}" ] || [ ! -z "${FETCH}" ]
1120 livefs_root="${mountpoint}"
1122 panic "Unable to find a live file system on the network"
1125 # Scan local devices for the image
1126 for i in 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
1128 livefs_root=$(find_livefs ${i})
1130 if [ -n "${livefs_root}" ]
1139 if [ -z "${livefs_root}" ]
1141 panic "Unable to find a medium containing a live file system"
1147 elif [ "${TODISK}" ]
1149 live_dest="${TODISK}"
1152 if [ "${live_dest}" ]
1154 log_begin_msg "Copying live media to ${live_dest}"
1155 copy_live_to "${livefs_root}" "${live_dest}"
1159 if [ -n "${MODULETORAMFILE}" ]
1161 setup_unionfs "${livefs_root}" "${rootmnt}"
1163 mount_images_in_directory "${livefs_root}" "${rootmnt}"
1168 maybe_break live-bottom
1169 [ "${quiet}" != "y" ] && log_begin_msg "Running /scripts/live-bottom"
1172 run_scripts /scripts/live-bottom
1173 [ "${quiet}" != "y" ] && log_end_msg
1177 cp live.log "${rootmnt}/var/log/"