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}\" "
340 TIMEZONE="${ARGUMENT#timezone=}"
350 TODISK="${ARGUMENT#todisk=}"
361 MODULETORAM="${ARGUMENT#toram=}"
362 export TORAM MODULETORAM
366 UNIONTYPE="${ARGUMENT#union=}"
371 UTC="${ARGUMENT#utc=}"
381 XVIDEOMODE="${ARGUMENT#xvideomode=}"
387 # sort of compatibility with netboot.h from linux docs
388 if [ -z "${NETBOOT}" ]
390 if [ "${ROOT}" = "/dev/nfs" ]
394 elif [ "${ROOT}" = "/dev/cifs" ]
401 if [ -z "${MODULE}" ]
407 if [ -z "${UNIONTYPE}" ]
418 if [ -d "${DIRECTORY}"/"${LIVE_MEDIA_PATH}" ]
420 for FILESYSTEM in squashfs ext2 ext3 xfs dir
422 if [ "`echo ${DIRECTORY}/${LIVE_MEDIA_PATH}/*.${FILESYSTEM}`" != "${DIRECTORY}/${LIVE_MEDIA_PATH}/*.${FILESYSTEM}" ]
432 get_backing_device ()
435 *.squashfs|*.ext2|*.ext3)
436 echo $(setup_loop "$1" "loop" "/sys/block/loop*" '0' "${LIVE_MEDIA_ENCRYPTION}")
444 panic "Unrecognized live filesystem: $1"
449 match_files_in_dir ()
451 # Does any files match pattern $1 ?
454 if [ "$(echo $pattern)" != "$pattern" ]
462 mount_images_in_directory ()
467 if match_files_in_dir "$directory/${LIVE_MEDIA_PATH}/*.squashfs" ||
468 match_files_in_dir "$directory/${LIVE_MEDIA_PATH}/*.ext2" ||
469 match_files_in_dir "$directory/${LIVE_MEDIA_PATH}/*.ext3" ||
470 match_files_in_dir "$directory/${LIVE_MEDIA_PATH}/*.dir"
472 setup_unionfs "$directory/${LIVE_MEDIA_PATH}" "$rootmnt"
480 sysfs_path="${1#/sys}"
482 if /lib/udev/path_id "${sysfs_path}" | grep -E -q "ID_PATH=(usb|pci-[^-]*-[ide|scsi|usb])"
492 # FIXME: do something better like the scan of supported filesystems
496 vfat|iso9660|udf|ext2|ext3|ntfs)
508 copyto="${copyfrom}_swap"
510 if [ -z "${MODULETORAM}" ]
512 size=$(fs_size "" ${copyfrom} "used")
514 MODULETORAMFILE="${copyfrom}/${LIVE_MEDIA_PATH}/${MODULETORAM}"
516 if [ -f "${MODULETORAMFILE}" ]
518 size=$( expr $(ls -la ${MODULETORAMFILE} | awk '{print $5}') / 1024 + 5000 )
520 log_warning_msg "Error: toram-module $MODULETORAM ($MODULETORAMFILE) could not be read."
525 if [ "${copytodev}" = "ram" ]
528 freespace=$( expr $(awk '/MemFree/{print $2}' /proc/meminfo) + $( cat /proc/meminfo | grep Cached | head -n 1 | awk '/Cached/{print $2}' - ) )
529 mount_options="-o size=${size}k"
534 # it should be a writable block device
535 if [ -b "${copytodev}" ]
539 fstype=$(get_fstype "${dev}")
540 freespace=$(fs_size "${dev}")
542 [ "$quiet" != "y" ] && log_warning_msg "${copytodev} is not a block device."
547 if [ "${freespace}" -lt "${size}" ]
549 [ "$quiet" != "y" ] && log_warning_msg "Not enough free ${free_string} (${freespace}k free, ${size}k needed) to copy live media in ${copytodev}."
553 # begin copying (or uncompressing)
555 echo "mount -t ${fstype} ${mount_options} ${dev} ${copyto}"
556 mount -t "${fstype}" ${mount_options} "${dev}" "${copyto}"
558 if [ "$extension" = "tgz" ]
561 tar zxf "${copyfrom}/${LIVE_MEDIA_PATH}/$(basename ${FETCH})"
562 rm -f "${copyfrom}/${LIVE_MEDIA_PATH}/$(basename ${FETCH})"
563 mount -r --move "${copyto}" "${rootmnt}"
566 if [ -n "${MODULETORAMFILE}" ]
568 cp ${MODULETORAMFILE} ${copyto} # copy only the filesystem module
570 cp -a ${copyfrom}/* ${copyto} # "cp -a" from busybox also copies hidden files
575 mount -r --move ${copyto} ${copyfrom}
586 modprobe "${MP_QUIET}" af_packet # For DHCP
591 ipconfig ${DEVICE} | tee /netboot.config
593 # source relevant ipconfig output
594 OLDHOSTNAME=$HOSTNAME
595 . /tmp/net-${DEVICE}.conf
596 [ -z $HOSTNAME ] && HOSTNAME=$OLDHOSTNAME
599 if [ "${NFSROOT}" = "auto" ]
601 NFSROOT=${ROOTSERVER}:${ROOTPATH}
604 if [ -n "${FETCH}" ] && do_httpmount
610 if [ "${NFSROOT#*:}" = "$NFSROOT" ] && [ "$NETBOOT" != "cifs" ]
612 NFSROOT=${ROOTSERVER}:${NFSROOT}
615 [ "$quiet" != "y" ] && log_begin_msg "Trying netboot from ${NFSROOT}"
617 if [ "${NETBOOT}" != "nfs" ] && do_cifsmount
627 [ "$quiet" != "y" ] && log_end_msg
634 extension=`echo "${FETCH}" | sed 's/\(.*\)\.\(.*\)/\2/'`
636 case "${extension}" in
638 [ "$quiet" != "y" ] && log_begin_msg "Trying wget ${FETCH} -O ${mountpoint}/$(basename ${FETCH})"
639 mkdir -p "${mountpoint}/${LIVE_MEDIA_PATH}"
640 wget "${FETCH}" -O "${mountpoint}/${LIVE_MEDIA_PATH}/$(basename ${FETCH})"
642 [ "${extension}" == "tgz" ] && live_dest="ram"
646 [ "$quiet" != "y" ] && log_begin_msg "Unrecognized archive extension for ${FETCH}"
656 modprobe "${MP_QUIET}" nfs
658 if [ -z "${NFSOPTS}" ]
663 [ "$quiet" != "y" ] && log_begin_msg "Trying nfsmount -o nolock -o ro ${NFSOPTS} ${NFSROOT} ${mountpoint}"
665 # FIXME: This for loop is an ugly HACK round an nfs bug
666 for i in 0 1 2 3 4 5 6 7 8 9 a b c d e f 10 11 12 13
668 nfsmount -o nolock -o ro ${NFSOPTS} "${NFSROOT}" "${mountpoint}" && rc=0 && break
679 if [ -x "/sbin/mount.cifs" ]
681 if [ -z "${NFSOPTS}" ]
683 CIFSOPTS="-ouser=root,password="
685 CIFSOPTS="${NFSOPTS}"
688 [ "$quiet" != "y" ] && log_begin_msg "Trying mount.cifs ${NFSROOT} ${mountpoint} ${CIFSOPTS}"
689 modprobe "${MP_QUIET}" cifs
691 if mount.cifs "${NFSROOT}" "${mountpoint}" "${CIFSOPTS}"
705 size=$(fs_size "${fromdev}" "" "used")
707 if [ -b "${fromdev}" ]
710 if [ -n "${HOMEMOUNTED}" -a "${snap_type}" = "HOME" ]
712 todev=$(cat /proc/mounts | grep -s " $(base_path ${todir}) " | awk '{print $1}' )
713 freespace=$(df -k | grep -s ${todev} | awk '{print $4}')
715 freespace=$( expr $(awk '/MemFree/{print $2}' /proc/meminfo) + $( cat /proc/meminfo | grep Cached | head -n 1 | awk '/Cached/{print $2}' - ))
718 tomount="/mnt/tmpsnap"
720 if [ ! -d "${tomount}" ]
722 mkdir -p "${tomount}"
725 fstype=$(get_fstype "${fromdev}")
727 if [ -n "${fstype}" ]
730 mount -t "${fstype}" -o ro "${fromdev}" "${tomount}"
731 cp -a "${tomount}"/* ${todir}
734 log_warning_msg "Unrecognized fstype: ${fstype} on ${fromdev}:${snap_type}"
739 if echo ${fromdev} | grep -qs loop
741 losetup -d "${fromdev}"
748 [ "$quiet" != "y" ] && log_warning_msg "Unable to find the snapshot ${snap_type} medium"
754 # Look for $snap_label.* in block devices and copy the contents to $snap_mount
755 # and remember the device and filename for resync on exit in live-initramfs.init
760 snapdata=$(find_files "${snap_label}.squashfs ${snap_label}.cpio.gz ${snap_label}.ext2 ${snap_label}.ext3")
762 if [ ! -z "${snapdata}" ]
764 snapdev="$(echo ${snapdata} | cut -f1 -d ' ')"
765 snapback="$(echo ${snapdata} | cut -f2 -d ' ')"
766 snapfile="$(echo ${snapdata} | cut -f3 -d ' ')"
768 if echo "${snapfile}" | grep -qs '\(squashfs\|ext2\|ext3\)'
770 # squashfs or ext2/ext3 snapshot
771 dev=$(get_backing_device "${snapback}/${snapfile}")
773 if ! do_snap_copy "${dev}" "${snap_mount}" "${snap_type}"
775 log_warning_msg "Impossible to include the ${snapfile} Snapshot"
780 if ! (cd "${snap_mount}" && zcat "${snapback}/${snapfile}" | cpio -i -u -d 2>/dev/null)
782 log_warning_msg "Impossible to include the ${snapfile} Snapshot"
789 dev=$(find_cow_device "${snap_label}")
793 if echo "${dev}" | grep -qs loop
795 # strange things happens, user confused?
796 snaploop=$( losetup ${dev} | awk '{print $3}' | tr -d '()' )
797 snapfile=$(basename ${snaploop})
798 snapdev=$(cat /proc/mounts | awk '{print $2,$1}' | grep -es "^$( dirname ${snaploop} )" | cut -f2 -d ' ')
803 if ! do_snap_copy "${dev}" "${snap_mount}" "${snap_type}"
805 log_warning_msg "Impossible to include the ${snap_label} Snapshot"
808 if [ -n "${snapfile}" ]
810 # it was a loop device, user confused
815 log_warning_msg "Impossible to include the ${snap_label} Snapshot"
820 echo "export ${snap_type}SNAP="${snap_mount}":${snapdev}:${snapfile}" >> /etc/live.conf # for resync on reboot/halt
829 modprobe "${MP_QUIET}" -b ${UNIONTYPE}
831 # run-init can't deal with images in a subdir, but we're going to
832 # move all of these away before it runs anyway. No, we're not,
833 # put them in / since move-mounting them into / breaks mono and
838 # Let's just mount the read-only file systems first
841 minor_kernel_version=`uname -r|cut -c 5-|sed 's/[^0-9].*//'`
843 if [ "${NETBOOT}" = "nfs" ] && [ "${minor_kernel_version}" -lt 22 ]
845 # go aroung a bug in nfs-unionfs locking for unionfs <= 1.4
851 # Read image names from ${MODULE}.module if it exists
852 if [ -e "${image_directory}/filesystem.${MODULE}.module" ]
854 for IMAGE in `cat ${image_directory}/filesystem.${MODULE}.module`
856 image_string="${image_string} ${image_directory}/${image}"
858 elif [ -e "${image_directory}/${MODULE}.module" ]
860 for IMAGE in `cat ${image_directory}/${MODULE}.module`
862 image_string="${image_string} ${image_directory}/${image}"
865 # ${MODULE}.module does not exist, create a list of images
866 for FILESYSTEM in squashfs ext2 ext3 xfs dir
868 for IMAGE in "${image_directory}"/*."${FILESYSTEM}"
872 image_string="${image_string} ${IMAGE}"
878 image_string="`echo ${image_string} | sed -e 's/ /\n/g' | sort `"
881 [ -n "${MODULETORAMFILE}" ] && image_string="${image_directory}/$(basename ${MODULETORAMFILE})"
885 for image in ${image_string}
887 imagename=$(basename "${image}")
891 # it is a plain directory: do nothing
892 rofsstring="${image}=${roopt}:${rofsstring}"
893 rofslist="${image} ${rofslist}"
894 elif [ -f "${image}" ]
896 backdev=$(get_backing_device "$image")
897 fstype=$(get_fstype "${backdev}")
899 if [ "${fstype}" = "unknown" ]
901 panic "Unknown file system type on ${backdev} (${image})"
904 mkdir -p "${croot}/${imagename}"
905 echo "debug: Can not mount backdev $backdev (image = $image) on croot/imagename ${croot}/${imagename}"
906 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}"
910 rofsstring=${rofsstring%:}
916 # Looking for "${root_persistence}" device or file
917 if [ -n "${PERSISTENT}" ]
919 cowprobe=$(find_cow_device "${root_persistence}")
921 if [ -b "${cowprobe}" ]
923 cowdevice=${cowprobe}
924 cow_fstype=$(get_fstype "${cowprobe}")
926 [ "$quiet" != "y" ] && log_warning_msg "Unable to find the persistent medium"
930 mount ${cowdevice} -t ${cow_fstype} -o rw /cow || panic "Can not mount $cowdevice on /cow"
932 mount -t ${UNIONTYPE} -o dirs=/cow=rw:$rofsstring ${UNIONTYPE} "$rootmnt" || panic "${UNIONTYPE} mount failed"
934 # Adding other custom mounts
935 if [ -n "${PERSISTENT}" ]
937 # directly mount /home
938 # FIXME: add a custom mounts configurable system
939 homecow=$(find_cow_device "${home_persistence}" )
941 if [ -b "${homecow}" ]
943 mount -t $(get_fstype "${homecow}") -o rw "${homecow}" "${rootmnt}/home"
944 export HOMEMOUNTED=1 # used to proper calculate free space in do_snap_copy()
946 [ "$quiet" != "y" ] && log_warning_msg "Unable to find the persistent home medium"
949 # Look for other snapshots to copy in
950 try_snap "${root_snapshot_label}" "${rootmnt}" "ROOT"
951 try_snap "${home_snapshot_label}" "${rootmnt}/home" "HOME"
954 if [ -n "${SHOWMOUNTS}" ]
958 mkdir -p "${rootmnt}/live/${d##*/}"
962 # do nothing # mount -o bind "${d}" "${rootmnt}/live/${d##*/}"
966 mount --move "${d}" "${rootmnt}/live/${d##*/}"
972 # shows cow fs on /cow for use by live-snapshot
973 mkdir -p "${rootmnt}/live/cow"
974 mount -o bind /cow "${rootmnt}/live/cow"
982 if [ -z "${devname}" ]
984 devname=$(sys2dev "${sysdev}")
987 if [ -n "${LIVE_MEDIA_OFFSET}" ]
989 loopdevname=$(setup_loop "${devname}" "loop" "/sys/block/loop*" "${LIVE_MEDIA_OFFSET}" '')
990 devname="${loopdevname}"
993 fstype=$(get_fstype "${devname}")
995 if is_supported_fs ${fstype}
997 mount -t ${fstype} -o ro "${devname}" $mountpoint || continue
999 if is_live_path $mountpoint
1008 if [ -n "${LIVE_MEDIA_OFFSET}" ]
1010 losetup -d "${loopdevname}"
1020 # first look at the one specified in the command line
1021 if [ ! -z "${LIVE_MEDIA}" ]
1023 if check_dev "null" "${LIVE_MEDIA}"
1029 # don't start autodetection before timeout has expired
1030 if [ -n "${LIVE_MEDIA_TIMEOUT}" ]
1032 if [ "${timeout}" -lt "${LIVE_MEDIA_TIMEOUT}" ]
1038 # or do the scan of block devices
1039 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -v loop | grep -v ram)
1041 devname=$(sys2dev "${sysblock}")
1042 fstype=$(get_fstype "${devname}")
1044 if /lib/udev/cdrom_id ${devname} > /dev/null
1046 if check_dev "null" "${devname}"
1050 elif is_nice_device "${sysblock}"
1052 for dev in $(subdevices "${sysblock}")
1054 if check_dev "${dev}"
1059 elif [ "${fstype}" = "squashfs" -o \
1060 "${fstype}" = "ext2" -o \
1061 "${fstype}" = "ext3" ]
1063 # This is an ugly hack situation, the block device has
1064 # an image directly on it. It's hopefully
1065 # live-initramfs, so take it and run with it.
1066 ln -s "${devname}" "${devname}.${fstype}"
1067 echo "${devname}.${fstype}"
1077 if [ -x /sbin/usplash_write ]
1079 /sbin/usplash_write "PULSATE"
1083 set_usplash_timeout ()
1085 if [ -x /sbin/usplash_write ]
1087 /sbin/usplash_write "TIMEOUT 120"
1101 [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/live-premount"
1103 run_scripts /scripts/live-premount
1104 [ "$quiet" != "y" ] && log_end_msg
1106 # Needed here too because some things (*cough* udev *cough*)
1107 # changes the timeout
1111 if [ ! -z "${NETBOOT}" ] || [ ! -z "${FETCH}" ]
1115 livefs_root="${mountpoint}"
1117 panic "Unable to find a live file system on the network"
1120 # Scan local devices for the image
1121 for i in 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
1123 livefs_root=$(find_livefs $i)
1125 if [ -n "${livefs_root}" ]
1134 if [ -z "${livefs_root}" ]
1136 panic "Unable to find a medium containing a live file system"
1142 elif [ "${TODISK}" ]
1144 live_dest="${TODISK}"
1147 if [ "${live_dest}" ]
1149 log_begin_msg "Copying live media to ${live_dest}"
1150 copy_live_to "${livefs_root}" "${live_dest}"
1154 if [ -n "${MODULETORAMFILE}" ]
1156 setup_unionfs "${livefs_root}" "$rootmnt"
1158 mount_images_in_directory "${livefs_root}" "${rootmnt}"
1163 maybe_break live-bottom
1164 [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/live-bottom"
1167 run_scripts /scripts/live-bottom
1168 [ "$quiet" != "y" ] && log_end_msg
1172 cp live.log "${rootmnt}/var/log/"