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 alt_mountpoint
="/media"
12 LIVE_MEDIA_PATH
="live"
14 root_persistence
="live-rw"
15 home_persistence
="home-rw"
16 root_snapshot_label
="live-sn"
17 home_snapshot_label
="home-sn"
20 USERFULLNAME
="Live user"
23 mkdir
-p "${mountpoint}"
26 # Create /etc/mtab for debug purpose and future syncs
37 .
/scripts
/live-helpers
39 if [ ! -f /live.vars
]
49 for ARGUMENT
in $
(cat /proc
/cmdline
)
58 export NOACCESSIBILITY NOFASTBOOT NOFSTAB NONETWORKING
62 ACCESS
="${ARGUMENT#access=}"
67 DEFCONSOLE
="${ARGUMENT#*=}"
79 # Force dhcp even while netbooting
80 # Use for debugging in case somebody works on fixing dhclient
90 DEVICE
="${ARGUMENT#ethdevice=}"
92 export DEVICE ETHDEVICE
96 ETHDEV_TIMEOUT
="${ARGUMENT#ethdevice-timeout=}"
101 FETCH
="${ARGUMENT#fetch=}"
106 FORCEPERSISTENTFSCK
="Yes"
107 export FORCEPERSISTENTFSCK
111 FTPFS
="${ARGUMENT#ftpfs=}"
116 HTTPFS
="${ARGUMENT#httpfs=}"
121 ISCSI
="${ARGUMENT#iscsi=}"
122 #ip:port - separated by ;
123 ISCSI_PORTAL
="${ISCSI%;*}"
124 if echo "${ISCSI_PORTAL}" |
grep -q , ; then
125 ISCSI_SERVER
="${ISCSI_PORTAL%,*}"
126 ISCSI_PORT
="${ISCSI_PORTAL#*,}"
129 ISCSI_TARGET
="${ISCSI#*;}"
130 export ISCSI ISCSI_PORTAL ISCSI_TARGET ISCSI_SERVER ISCSI_PORT
134 FROMISO
="${ARGUMENT#*=}"
144 INTEGRITY_CHECK
="Yes"
145 export INTEGRITY_CHECK
149 STATICIP
="${ARGUMENT#ip=}"
151 if [ -z "${STATICIP}" ]
164 live-media
=*|bootfrom
=*)
165 LIVE_MEDIA
="${ARGUMENT#*=}"
169 live-media-encryption
=*|encryption
=*)
170 LIVE_MEDIA_ENCRYPTION
="${ARGUMENT#*=}"
171 export LIVE_MEDIA_ENCRYPTION
175 LIVE_MEDIA_OFFSET
="${ARGUMENT#live-media-offset=}"
176 export LIVE_MEDIA_OFFSET
180 LIVE_MEDIA_PATH
="${ARGUMENT#live-media-path=}"
181 export LIVE_MEDIA_PATH
184 live-media-timeout
=*)
185 LIVE_MEDIA_TIMEOUT
="${ARGUMENT#live-media-timeout=}"
186 export LIVE_MEDIA_TIMEOUT
190 MODULE
="${ARGUMENT#module=}"
195 NETBOOT
="${ARGUMENT#netboot=}"
200 NFSOPTS
="${ARGUMENT#nfsopts=}"
205 NFS_COW
="${ARGUMENT#nfscow=}"
210 NOACCESSIBILITY
="Yes"
211 export NOACCESSIBILITY
240 PERSISTENT
="${ARGUMENT#persistent=}"
241 if [ -z "${PERSISTENT}" ]
249 PERSISTENT_PATH
="${ARGUMENT#persistent-path=}"
250 export PERSISTENT_PATH
253 persistent-subtext
=*)
254 root_persistence
="${root_persistence}-${ARGUMENT#persistent-subtext=}"
255 home_persistence
="${home_persistence}-${ARGUMENT#persistent-subtext=}"
256 root_snapshot_label
="${root_snapshot_label}-${ARGUMENT#persistent-subtext=}"
257 home_snapshot_label
="${home_snapshot_label}-${ARGUMENT#persistent-subtext=}"
266 QUICKUSBMODULES
="Yes"
267 export QUICKUSBMODULES
270 preseed
/file=*|
file=*)
271 LOCATIONS
="${ARGUMENT#*=} ${LOCATIONS}"
281 question
="${ARGUMENT%%=*}"
282 value
="${ARGUMENT#*=}"
283 PRESEEDS
="${PRESEEDS}\"${question}=${value}\" "
298 TODISK
="${ARGUMENT#todisk=}"
309 MODULETORAM
="${ARGUMENT#toram=}"
310 export TORAM MODULETORAM
324 SKIP_UNION_MOUNTS
="Yes"
325 export SKIP_UNION_MOUNTS
329 ROOT
="${ARGUMENT#root=}"
334 UNIONTYPE
="${ARGUMENT#union=}"
340 # sort of compatibility with netboot.h from linux docs
341 if [ -z "${NETBOOT}" ]
343 if [ "${ROOT}" = "/dev/nfs" ]
347 elif [ "${ROOT}" = "/dev/cifs" ]
354 if [ -z "${MODULE}" ]
360 if [ -z "${UNIONTYPE}" ]
371 if [ -d "${DIRECTORY}"/"${LIVE_MEDIA_PATH}" ]
373 for FILESYSTEM
in squashfs ext2 ext3 ext4 xfs dir jffs2
375 if [ "$(echo ${DIRECTORY}/${LIVE_MEDIA_PATH}/*.${FILESYSTEM})" != "${DIRECTORY}/${LIVE_MEDIA_PATH}/*.${FILESYSTEM}" ]
387 if [ "${IGNORE_UUID}" ] ||
[ ! -e /conf
/uuid.conf
]
393 uuid
="$(cat /conf/uuid.conf)"
395 for try_uuid_file
in "${path}/.disk/live-uuid"*
397 [ -e "${try_uuid_file}" ] ||
continue
399 try_uuid
="$(cat "${try_uuid_file}")"
401 if [ "${uuid}" = "${try_uuid}" ]
410 get_backing_device
()
413 *.squashfs|
*.ext2|
*.ext3|
*.ext4|
*.jffs2
)
414 echo $
(setup_loop
"${1}" "loop" "/sys/block/loop*" '0' "${LIVE_MEDIA_ENCRYPTION}" "${2}")
422 panic
"Unrecognized live filesystem: ${1}"
427 match_files_in_dir
()
429 # Does any files match pattern ${1} ?
432 if [ "$(echo ${pattern})" != "${pattern}" ]
440 mount_images_in_directory
()
447 if match_files_in_dir
"${directory}/${LIVE_MEDIA_PATH}/*.squashfs" ||
448 match_files_in_dir
"${directory}/${LIVE_MEDIA_PATH}/*.ext2" ||
449 match_files_in_dir
"${directory}/${LIVE_MEDIA_PATH}/*.ext3" ||
450 match_files_in_dir
"${directory}/${LIVE_MEDIA_PATH}/*.ext4" ||
451 match_files_in_dir
"${directory}/${LIVE_MEDIA_PATH}/*.jffs2" ||
452 match_files_in_dir
"${directory}/${LIVE_MEDIA_PATH}/*.dir"
454 [ -n "${mac}" ] && adddirectory="${directory}/${LIVE_MEDIA_PATH}/${mac}"
455 setup_unionfs
"${directory}/${LIVE_MEDIA_PATH}" "${rootmnt}" "${adddirectory}"
457 panic
"No supported filesystem images found at /${LIVE_MEDIA_PATH}."
463 sysfs_path
="${1#/sys}"
465 if /lib
/udev
/path_id
"${sysfs_path}" |
egrep -q "ID_PATH=(usb|pci-|platform-orion-ehci|platform-mmc|platform-mxsdhci|)"
468 elif echo "${sysfs_path}" |
grep -q '^/block/vd[a-z]$'
471 elif echo ${sysfs_path} |
grep -q "^/block/dm-"
483 copyto
="${copyfrom}_swap"
485 if [ -z "${MODULETORAM}" ]
487 size
=$
(fs_size
"" ${copyfrom}/${LIVE_MEDIA_PATH} "used")
489 MODULETORAMFILE
="${copyfrom}/${LIVE_MEDIA_PATH}/${MODULETORAM}"
491 if [ -f "${MODULETORAMFILE}" ]
493 size
=$
( expr $
(ls -la ${MODULETORAMFILE} |
awk '{print $5}') / 1024 + 5000 )
495 log_warning_msg
"Error: toram-module ${MODULETORAM} (${MODULETORAMFILE}) could not be read."
500 if [ "${copytodev}" = "ram" ]
503 freespace
=$
(awk '/^MemFree:/{f=$2} /^Cached:/{c=$2} END{print f+c}' /proc
/meminfo
)
504 mount_options
="-o size=${size}k"
509 # it should be a writable block device
510 if [ -b "${copytodev}" ]
514 fstype
=$
(get_fstype
"${dev}")
515 freespace
=$
(fs_size
"${dev}")
517 log_warning_msg
"${copytodev} is not a block device."
522 if [ "${freespace}" -lt "${size}" ]
524 log_warning_msg
"Not enough free ${free_string} (${freespace}k free, ${size}k needed) to copy live media in ${copytodev}."
528 # begin copying (or uncompressing)
530 log_begin_msg
"mount -t ${fstype} ${mount_options} ${dev} ${copyto}"
531 mount
-t "${fstype}" ${mount_options} "${dev}" "${copyto}"
533 if [ "${extension}" = "tgz" ]
536 tar zxf
"${copyfrom}/${LIVE_MEDIA_PATH}/$(basename ${FETCH})"
537 rm -f "${copyfrom}/${LIVE_MEDIA_PATH}/$(basename ${FETCH})"
538 mount
-r -o move
"${copyto}" "${rootmnt}"
541 if [ -n "${MODULETORAMFILE}" ]
545 echo " * Copying $MODULETORAMFILE to RAM" 1>/dev
/console
546 rsync
-a --progress ${MODULETORAMFILE} ${copyto} 1>/dev
/console
# copy only the filesystem module
548 cp ${MODULETORAMFILE} ${copyto} # copy only the filesystem module
553 echo " * Copying whole medium to RAM" 1>/dev
/console
554 rsync
-a --progress ${copyfrom}/* ${copyto} 1>/dev
/console
# "cp -a" from busybox also copies hidden files
556 mkdir
-p ${copyto}/${LIVE_MEDIA_PATH}
557 cp -a ${copyfrom}/${LIVE_MEDIA_PATH}/* ${copyto}/${LIVE_MEDIA_PATH}
558 if [ -e ${copyfrom}/${LIVE_MEDIA_PATH}/.disk
]
560 cp -a ${copyfrom}/${LIVE_MEDIA_PATH}/.disk ${copyto}
566 mount
-r -o move
${copyto} ${copyfrom}
575 modprobe
-q af_packet
# For DHCP
580 if [ -z "${NETBOOT}" ] && [ -z "${FETCH}" ] && \
581 [ -z "${HTTPFS}" ] && [ -z "${FTPFS}" ]
584 # if ethdevice was not specified on the kernel command line
585 # make sure we try to get a working network configuration
586 # for *every* present network device (except for loopback of course)
587 if [ -z "$ETHDEVICE" ] ; then
588 echo "If you want to boot from a specific device use bootoption ethdevice=..."
589 for device
in /sys
/class
/net
/*; do
591 if [ "$dev" != "lo" ] ; then
592 ETHDEVICE
="$ETHDEVICE $dev"
597 # split args of ethdevice=eth0,eth1 into "eth0 eth1"
598 for device
in $
(echo $ETHDEVICE |
sed 's/,/ /g') ; do
599 devlist
="$devlist $device"
602 [ -n "$ETHDEV_TIMEOUT" ] || ETHDEV_TIMEOUT
=15
603 echo "Using timeout of $ETHDEV_TIMEOUT seconds for network configuration."
605 # this is tricky (and ugly) because ipconfig sometimes just hangs/runs into
606 # an endless loop; iff execution fails give it two further tries, that's
607 # why we use '$devlist $devlist $devlist' for the other for loop
608 for dev
in $devlist $devlist $devlist ; do
609 echo "Executing ipconfig -t $ETHDEV_TIMEOUT $dev"
610 ipconfig
-t "$ETHDEV_TIMEOUT" $dev |
tee -a /netboot.config
&
612 sleep "$ETHDEV_TIMEOUT" ; sleep 1
613 if [ -r /proc
/"$jobid"/status
] ; then
614 echo "Killing job $jobid for device $dev as ipconfig ran into recursion..."
618 # if configuration of device worked we should have an assigned
619 # IP address, iff so let's use the according as $DEVICE for later usage
620 # simple and primitive approach which seems to work fine
621 if ifconfig
$dev |
grep -q 'inet.*addr:' ; then
628 ipconfig
${DEVICE} |
tee /netboot.config
631 # source relevant ipconfig output
632 OLDHOSTNAME
=${HOSTNAME}
633 .
/tmp
/net-
${DEVICE}.conf
634 [ -z ${HOSTNAME} ] && HOSTNAME
=${OLDHOSTNAME}
637 if [ -n "${DEVICE}" ]
639 HWADDR
="$(cat /sys/class/net/${DEVICE}/address)"
642 if [ ! -e "/etc/resolv.conf" ]
644 echo "Creating /etc/resolv.conf"
646 if [ -n "${DNSDOMAIN}" ]
648 echo "domain ${DNSDOMAIN}" > /etc
/resolv.conf
649 echo "search ${DNSDOMAIN}" > /etc
/resolv.conf
652 for i
in ${IPV4DNS0} ${IPV4DNS1} ${IPV4DNS1}
654 echo "nameserver $i" >> /etc
/resolv.conf
658 # Check if we have a network device at all
659 if ! ls /sys
/class
/net
/"$DEVICE" > /dev
/null
2>&1 && \
660 ! ls /sys
/class
/net
/eth0
> /dev
/null
2>&1 && \
661 ! ls /sys
/class
/net
/wlan0
> /dev
/null
2>&1 && \
662 ! ls /sys
/class
/net
/ath0
> /dev
/null
2>&1 && \
663 ! ls /sys
/class
/net
/ra0
> /dev
/null
2>&1
665 panic
"No supported network device found, maybe a non-mainline driver is required."
673 if [ "${NFSROOT}" = "auto" ]
675 NFSROOT
=${ROOTSERVER}:${ROOTPATH}
680 if ( [ -n "${FETCH}" ] || [ -n "${HTTPFS}" ] || [ -n "${FTPFS}" ] )
686 if [ "${NFSROOT#*:}" = "${NFSROOT}" ] && [ "$NETBOOT" != "cifs" ]
688 NFSROOT
=${ROOTSERVER}:${NFSROOT}
691 log_begin_msg
"Trying netboot from ${NFSROOT}"
693 if [ "${NETBOOT}" != "nfs" ] && do_cifsmount
713 [ "${DEBUG}" == "Yes" ] && debugopt
="-d 8"
714 #FIXME this name is supposed to be unique - some date + ifconfig hash?
715 ISCSI_INITIATORNAME
="iqn.1993-08.org.debian.live:01:$(echo "${HWADDR}" | sed -e s/://g)"
716 export ISCSI_INITIATORNAME
717 if [ -n "${ISCSI_SERVER}" ] ; then
718 iscsistart
$debugopt -i "${ISCSI_INITIATORNAME}" -t "${ISCSI_TARGET}" -g 1 -a "${ISCSI_SERVER}" -p "${ISCSI_PORT}"
720 iscsistart
$debugopt -i "${ISCSI_INITIATORNAME}" -t "${ISCSI_TARGET}" -g 1 -a "${ISCSI_PORTAL}" -p 3260
724 panic
"Failed to log into iscsi target"
726 local host="$(ls -d /sys/class/scsi_host/host*/device/iscsi_host:host* \
727 /sys/class/scsi_host/host*/device/iscsi_host/host* | sed -e 's:/device.*::' -e 's:.*host::')"
732 while [ -z "${devices}" -a $i -lt 60 ]
735 devices
="$(ls -d /sys/class/scsi_device/${host}*/device/block:* \
736 /sys/class/scsi_device/${host}*/device/block/* | sed -e 's!.*[:/]!!')"
742 if check_dev
"null" "/dev/$dev"
749 panic
"Failed to locate a live device on iSCSI devices (tried: $devices)."
751 panic
"Failed to locate iSCSI host in /sys"
759 for webfile
in HTTPFS FTPFS FETCH
761 local url
="$(eval echo \"\$\{${webfile}\}\")"
762 local extension
="$(echo "${url}" | sed 's/\(.*\)\.\(.*\)/\2/')"
766 case "${extension}" in
767 iso|squashfs|tgz|
tar)
768 if [ "${extension}" = "iso" ]
770 mkdir
-p "${alt_mountpoint}"
771 dest
="${alt_mountpoint}"
773 local dest
="${mountpoint}/${LIVE_MEDIA_PATH}"
774 mount
-t ramfs ram
"${mountpoint}"
777 if [ "${webfile}" = "FETCH" ]
781 ip
="$(dirname $url | sed -e 's|tftp://||g' -e 's|/.*$||g')"
782 rfile
="$(echo $url | sed -e "s|tftp
://$ip||g
")"
783 lfile
="$(basename $url)"
784 log_begin_msg
"Trying tftp -g -b 10240 -r $rfile -l ${dest}/$lfile $ip"
785 tftp
-g -b 10240 -r $rfile -l ${dest}/$lfile $ip
789 log_begin_msg
"Trying wget ${url} -O ${dest}/$(basename ${url})"
790 wget
"${url}" -O "${dest}/$(basename ${url})"
794 log_begin_msg
"Trying to mount ${url} on ${dest}/$(basename ${url})"
795 if [ "${webfile}" = "FTPFS" ]
797 FUSE_MOUNT
="curlftpfs"
798 url
="$(dirname ${url})"
803 $FUSE_MOUNT "${url}" "${dest}"
804 ROOT_PID
="$(minips h -C "$FUSE_MOUNT" | { read x y ; echo "$x" ; } )"
806 [ ${?} -eq 0 ] && rc
=0
807 [ "${extension}" = "tgz" ] && live_dest
="ram"
808 if [ "${extension}" = "iso" ]
810 isoloop
=$
(setup_loop
"${dest}/$(basename "${url}")" "loop" "/sys/block/loop*" "" '')
811 mount
-t iso9660
"${isoloop}" "${mountpoint}"
818 log_begin_msg
"Unrecognized archive extension for ${url}"
826 if [ -d "${alt_mountpoint}" ]
828 umount
"${alt_mountpoint}"
829 rmdir "${alt_mountpoint}"
831 umount
"${mountpoint}"
832 elif [ "${webfile}" != "FETCH" ] ; then
846 if [ -z "${NFSOPTS}" ]
851 log_begin_msg
"Trying nfsmount -o nolock -o ro ${NFSOPTS} ${NFSROOT} ${mountpoint}"
853 # FIXME: This while loop is an ugly HACK round an nfs bug
855 while [ "$i" -lt 60 ]
857 nfsmount
-o nolock
-o ro
${NFSOPTS} "${NFSROOT}" "${mountpoint}" && rc=0 && break
869 if [ -x "/sbin
/mount.cifs
" ]
871 if [ -z "${NFSOPTS}" ]
873 CIFSOPTS="-ouser=root
,password
="
875 CIFSOPTS="${NFSOPTS}"
878 log_begin_msg "Trying mount.cifs
${NFSROOT} ${mountpoint} ${CIFSOPTS}"
881 if mount.cifs "${NFSROOT}" "${mountpoint}" "${CIFSOPTS}"
895 size=$(fs_size "${fromdev}" "" "used
")
897 if [ -b "${fromdev}" ]
900 if [ -n "${HOMEMOUNTED}" -a "${snap_type}" = "HOME
" ]
902 todev=$(awk -v pat="$
(base_path
${todir})" '$2 == pat { print $1 }' /proc/mounts)
903 freespace=$(df -k | awk '/'${todev}'/{print $4}')
905 freespace=$(awk '/^MemFree:/{f=$2} /^Cached:/{c=$2} END{print f+c}' /proc/meminfo)
908 tomount="/mnt
/tmpsnap
"
910 if [ ! -d "${tomount}" ]
912 mkdir -p "${tomount}"
915 fstype=$(get_fstype "${fromdev}")
917 if [ -n "${fstype}" ]
920 mount -o ro -t "${fstype}" "${fromdev}" "${tomount}" || log_warning_msg "Error in mount -t ${fstype} -o ro ${fromdev} ${tomount}"
921 cp -a "${tomount}"/* ${todir}
924 log_warning_msg "Unrecognized fstype
: ${fstype} on ${fromdev}:${snap_type}"
929 if echo ${fromdev} | grep -qs loop
931 losetup -d "${fromdev}"
938 log_warning_msg "Unable to
find the snapshot
${snap_type} medium
"
944 # Look for ${snap_label}.* in block devices
947 if [ "${PERSISTENT}" != "nofiles
" ]
949 # search for image files
950 snapdata=$(find_files "${PERSISTENT_PATH}${snap_label}.squashfs ${PERSISTENT_PATH}${snap_label}.cpio.gz ${PERSISTENT_PATH}${snap_label}.ext2 ${PERSISTENT_PATH}${snap_label}.ext3 ${PERSISTENT_PATH}${snap_label}.ext4 ${PERSISTENT_PATH}${snap_label}.jffs2
")
953 if [ -z "${snapdata}" ]
955 snapdata=$(find_cow_device "${snap_label}")
962 # copy the contents of previously found snapshot to ${snap_mount}
963 # and remember the device and filename for resync on exit in live-boot.init
969 if [ -n "${snapdata}" ] && [ ! -b "${snapdata}" ]
971 log_success_msg "found snapshot
: ${snapdata}"
972 snapdev="$
(echo ${snapdata} | cut
-f1 -d ' ')"
973 snapback="$
(echo ${snapdata} | cut
-f2 -d ' ')"
974 snapfile="$
(echo ${snapdata} | cut
-f3 -d ' ')"
976 if ! try_mount "${snapdev}" "${snapback}" "ro
"
983 if echo "${snapfile}" | grep -qs '\(squashfs\|ext2\|ext3\|ext4\|jffs2\)'
985 # squashfs, jffs2 or ext2/ext3/ext4 snapshot
986 dev=$(get_backing_device "${snapback}/${snapfile}")
988 do_snap_copy "${dev}" "${snap_mount}" "${snap_type}"
993 # Unfortunately klibc's cpio is incompatible with the
994 # rest of the world; everything else requires -u -d,
995 # while klibc doesn't implement them. Try to detect
996 # whether it's in use.
997 cpiopath="$
(which cpio)" || true
998 if [ "$cpiopath" ] && grep -aq /lib/klibc "$cpiopath"
1002 cpioargs='--unconditional --make-directories'
1005 cd "${snap_mount}" && zcat "${snapback}/${snapfile}" | $cpiopath $cpioargs --extract --preserve-modification-time --no-absolute-filenames --sparse 2>/dev/null
1008 if [ "${RES}" != "0" ]
1010 log_warning_msg "failure to
\"zcat
${snapback}/${snapfile} |
$cpiopath $cpioargs --extract --preserve-modification-time --no-absolute-filenames --sparse\""
1014 umount "${snapback}" || log_warning_msg "failure to
\"umount
${snapback}\""
1016 if [ "${RES}" != "0" ]
1018 log_warning_msg "Impossible to include the
${snapfile} Snapshot
file"
1021 elif [ -b "${snapdata}" ]
1023 # Try to find if it could be a snapshot partition
1025 log_success_msg "found snapshot
${snap_type} device on
${dev}"
1026 if echo "${dev}" | grep -qs loop
1028 # strange things happens, user confused?
1029 snaploop=$( losetup ${dev} | awk '{print $3}' | tr -d '()' )
1030 snapfile=$(basename ${snaploop})
1031 snapdev=$(awk -v pat="$
( dirname ${snaploop})" '$2 == pat { print $1 }' /proc/mounts)
1036 if ! do_snap_copy "${dev}" "${snap_mount}" "${snap_type}"
1038 log_warning_msg "Impossible to include the
${snap_type} Snapshot
"
1041 if [ -n "${snapfile}" ]
1043 # it was a loop device, user confused
1048 log_warning_msg "Impossible to include the
${snap_type} Snapshot
"
1052 echo "export ${snap_type}SNAP="/cow${snap_mount#$rootmnt}":${snapdev}:${snapfile}" >> /etc/live.conf # for resync on reboot/halt
1058 image_directory="${1}"
1060 addimage_directory="${3}"
1062 case ${UNIONTYPE} in
1064 modprobe -q -b ${UNIONTYPE}
1066 if ! cut -f2 /proc/filesystems | grep -q "^
${UNIONTYPE}\$
" && [ -x /bin/unionfs-fuse ]
1068 echo "${UNIONTYPE} not available
, falling back to unionfs-fuse.
"
1069 echo "This might be really slow.
"
1071 UNIONTYPE="unionfs-fuse
"
1076 if [ "${UNIONTYPE}" = unionfs-fuse ]
1081 # run-init can't deal with images in a subdir, but we're going to
1082 # move all of these away before it runs anyway. No, we're not,
1083 # put them in / since move-mounting them into / breaks mono and
1088 # Let's just mount the read-only file systems first
1092 if [ "${UNIONTYPE}" = "aufs
" ]
1095 noxino_opt="noxino
,"
1096 elif [ "${UNIONTYPE}" = "unionfs-fuse
" ]
1103 if [ -z "${PLAIN_ROOT}" ]
1105 # Read image names from ${MODULE}.module if it exists
1106 if [ -e "${image_directory}/filesystem.
${MODULE}.module
" ]
1108 for IMAGE in $(cat ${image_directory}/filesystem.${MODULE}.module)
1110 image_string="${image_string} ${image_directory}/${IMAGE}"
1112 elif [ -e "${image_directory}/${MODULE}.module
" ]
1114 for IMAGE in $(cat ${image_directory}/${MODULE}.module)
1116 image_string="${image_string} ${image_directory}/${IMAGE}"
1119 # ${MODULE}.module does not exist, create a list of images
1120 for FILESYSTEM in squashfs ext2 ext3 ext4 xfs jffs2 dir
1122 for IMAGE in "${image_directory}"/*."${FILESYSTEM}"
1124 if [ -e "${IMAGE}" ]
1126 image_string="${image_string} ${IMAGE}"
1131 if [ -n "${addimage_directory}" ] && [ -d "${addimage_directory}" ]
1133 for FILESYSTEM in squashfs ext2 ext3 ext4 xfs jffs2 dir
1135 for IMAGE in "${addimage_directory}"/*."${FILESYSTEM}"
1137 if [ -e "${IMAGE}" ]
1139 image_string="${image_string} ${IMAGE}"
1146 image_string="$
(echo ${image_string} |
sed -e 's/ /\n/g' |
sort )"
1149 [ -n "${MODULETORAMFILE}" ] && image_string="${image_directory}/$(basename ${MODULETORAMFILE})"
1153 for image in ${image_string}
1155 imagename=$(basename "${image}")
1157 export image devname
1158 maybe_break live-realpremount
1159 log_begin_msg "Running
/scripts
/live-realpremount
"
1160 run_scripts /scripts/live-realpremount
1163 if [ -d "${image}" ]
1165 # it is a plain directory: do nothing
1166 rofsstring="${image}=${roopt}:${rofsstring}"
1167 rofslist="${image} ${rofslist}"
1168 elif [ -f "${image}" ]
1170 if losetup --help 2>&1 | grep -q -- "-r\b"
1172 backdev=$(get_backing_device "${image}" "-r")
1174 backdev=$(get_backing_device "${image}")
1176 fstype=$(get_fstype "${backdev}")
1178 if [ "${fstype}" = "unknown
" ]
1180 panic "Unknown
file system
type on
${backdev} (${image})"
1183 if [ -z "${fstype}" ]
1185 fstype="${imagename##*.}"
1186 log_warning_msg "Unknown
file system
type on
${backdev} (${image}), assuming ${fstype}.
"
1189 mkdir -p "${croot}/${imagename}"
1190 log_begin_msg "Mounting
\"${image}\" on \"${croot}${imagename}\" via \"${backdev}\""
1191 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}"
1196 # we have a plain root system
1197 mkdir -p "${croot}/filesystem
"
1198 log_begin_msg "Mounting
\"${image_directory}\" on
\"${croot}/filesystem
\""
1199 mount -t $(get_fstype "${image_directory}") -o ro,noatime "${image_directory}" "${croot}/filesystem" || panic "Can not mount ${image_directory} on ${croot}/filesystem" && rofsstring="${croot}/filesystem=${roopt}:${rofsstring}" && rofslist="${croot}/filesystem ${rofslist}"
1201 mount -o bind ${croot}/filesystem $mountpoint
1205 rofsstring=${rofsstring%:}
1209 # Looking for "${root_persistence}" device or file
1210 if [ -n "${PERSISTENT}" ] && [ -z "${NOPERSISTENT}" ]
1212 if [ -z "${QUICKUSBMODULES}" ]
1215 num_block=$(ls -l /sys/block | wc -l)
1216 for module in sd_mod uhci-hcd ehci-hcd ohci-hcd usb-storage
1218 modprobe -q -b ${module}
1224 # For some reason, udevsettle does not block in this scenario,
1225 # so we sleep for a little while.
1227 # See https://bugs.launchpad.net/ubuntu/+source/casper/+bug/84591
1228 for timeout in 5 4 3 2 1
1232 if [ $(ls -l /sys/block | wc -l) -gt ${num_block} ]
1239 # search for label and files (this could be hugely optimized)
1240 cowprobe=$(find_cow_device "${root_persistence}")
1241 if [ -b "${cowprobe}" ]
1243 # Blacklist /cow device, to avoid inconsistent setups for overlapping snapshots
1244 # makes sense to have both persistence for /cow and /home mounted, maybe also with
1245 # snapshots to be sure to really store some e.g key config files,
1246 # but not on the same media
1247 blacklistdev="${cowprobe}"
1248 PERSISTENCE_IS_ON="1"
1249 export PERSISTENCE_IS_ON
1251 # homecow just mount something on /home, this should be generalized some way
1252 homecow=$(find_cow_device "${home_persistence}" "${blacklistdev}")
1253 if [ -b "${homecow}" ]
1255 PERSISTENCE_IS_ON="1"
1256 export PERSISTENCE_IS_ON
1258 root_snapdata=$(find_snap "${root_snapshot_label}" "${blacklistdev}")
1259 # This second type should be removed when snapshot will get smarter,
1260 # hence when "/etc
/live-snapshot
*list
" will be supported also by
1261 # ext2|ext3|ext4|jffs2 snapshot types.
1262 home_snapdata=$(find_snap "${home_snapshot_label}" "${blacklistdev}")
1264 if [ -b "${cowprobe}" ]
1266 cowdevice=${cowprobe}
1267 cow_fstype=$(get_fstype "${cowprobe}")
1268 cow_mountopt="rw
,noatime
"
1270 if [ "${FORCEPERSISTENTFSCK}" = "Yes
" ]
1272 fsck -y ${cowdevice}
1275 log_warning_msg "Unable to
find the persistent medium
"
1278 cow_mountopt="rw
,noatime
,mode
=755"
1280 elif [ -n "${NFS_COW}" ] && [ -z "${NOPERSISTENT}" ]
1282 # check if there are any nfs options
1283 if echo ${NFS_COW}|grep -q ','
1285 nfs_cow_opts="-o nolock
,$
(echo ${NFS_COW}|cut
-d, -f2-)"
1286 nfs_cow=$(echo ${NFS_COW}|cut -d, -f1)
1288 nfs_cow_opts="-o nolock
"
1294 cowdevice=$(echo ${nfs_cow}|sed "s
/client_mac_address
/${mac}/")
1297 panic "unable to determine mac address
"
1302 cow_mountopt="rw
,noatime
,mode
=755"
1305 if [ "${cow_fstype}" = "nfs
" ]
1308 "Trying nfsmount
${nfs_cow_opts} ${cowdevice} /cow
"
1309 nfsmount ${nfs_cow_opts} ${cowdevice} /cow || \
1310 panic "Can not mount
${cowdevice} (n
: ${cow_fstype}) on
/cow
"
1312 mount -t ${cow_fstype} -o ${cow_mountopt} ${cowdevice} /cow || \
1313 panic "Can not mount
${cowdevice} (o
: ${cow_fstype}) on
/cow
"
1316 rofscount=$(echo ${rofslist} |wc -w)
1318 if [ -n "${EXPOSED_ROOT}" ]
1320 if [ ${rofscount} -ne 1 ]
1322 panic "only one RO
file system supported with exposedroot
: ${rofslist}"
1324 exposedrootfs=${rofslist%% }
1326 mount --bind ${exposedrootfs} ${rootmnt} || \
1327 panic "bind mount of
${exposedrootfs} failed
"
1329 if [ -z "${SKIP_UNION_MOUNTS}" ]
1331 cow_dirs='/var/tmp /var/lock /var/run /var/log /var/spool /home /var/lib/live'
1336 for dir in ${cow_dirs}; do
1339 case "${UNIONTYPE}" in
1341 (ulimit -n 16384; unionfs-fuse -o cow -o noinitgroups -o default_permissions -o allow_other -o use_ino -o suid /cow=RW:${exposedrootfs}${dir} "${rootmnt}${dir}" || panic "mount ${UNIONTYPE} on ${rootmnt}${dir} failed with option cow,noinitgroups,default_permissions,allow_other,use_ino,suid=/cow=RW:${exposedrootfs}${dir}")
1342 mkdir
-p /dev
/.initramfs
/varrun
1343 pidof unionfs-fuse
>> /dev
/.initramfs
/varrun
/sendsigs.omit || true
1347 mount
-t ${UNIONTYPE} -o rw,noatime,dirs=/cow${dir}=rw:${exposedrootfs}${dir}=ro ${UNIONTYPE} "${rootmnt}${dir}" || panic "mount ${UNIONTYPE} on ${rootmnt}${dir} failed with option rw,noatime,dirs=/cow${dir}=rw:${exposedrootfs}${dir}=ro
"
1352 case "${UNIONTYPE}" in
1354 (ulimit -n 16384; unionfs-fuse -o cow -o noinitgroups -o default_permissions -o allow_other -o use_ino -o suid /cow=RW:${rofsstring} "${rootmnt}" || panic "mount ${UNIONTYPE} on ${rootmnt} failed with option cow,noinitgroups,default_permissions,allow_other,use_ino,suid=/cow:RW:${rofsstring}")
1355 mkdir
-p /dev
/.initramfs
/varrun
1356 pidof unionfs-fuse
>> /dev
/.initramfs
/varrun
/sendsigs.omit || true
1360 mount
-t ${UNIONTYPE} -o noatime,${noxino_opt}dirs=/cow=rw:${rofsstring} ${UNIONTYPE} "${rootmnt}" || panic "mount ${UNIONTYPE} on ${rootmnt} failed with option noatime,${noxino_opt}dirs=/cow=rw:${rofsstring}"
1365 # Correct the permissions of /:
1366 chmod 0755 "${rootmnt}"
1368 # tmpfs file systems
1370 mkdir -p "${rootmnt}/live
"
1371 mount -t tmpfs tmpfs ${rootmnt}/live
1373 # Adding other custom mounts
1374 if [ -n "${PERSISTENT}" ] && [ -z "${NOPERSISTENT}" ]
1376 # directly mount /home
1377 # FIXME: add a custom mounts configurable system
1379 if [ -b "${homecow}" ]
1381 mount -t $(get_fstype "${homecow}") -o rw,noatime "${homecow}" "${rootmnt}/home
"
1382 export HOMEMOUNTED=1 # used to proper calculate free space in do_snap_copy()
1384 log_warning_msg "Unable to
find the persistent home medium
"
1387 # Look for other snapshots to copy in
1388 try_snap "${root_snapdata}" "${rootmnt}" "ROOT
"
1389 # This second type should be removed when snapshot grow smarter
1390 try_snap "${home_snapdata}" "${rootmnt}/home
" "HOME
"
1393 if [ -n "${SHOWMOUNTS}" ]
1395 for d in ${rofslist}
1397 mkdir -p "${rootmnt}/live
/${d##*/}"
1401 # do nothing # mount -o bind "${d}" "${rootmnt}/live/${d##*/}"
1405 case "${UNIONTYPE}" in
1407 mount -o bind "${d}" "${rootmnt}/live/${d##*/}"
1411 mount -o move "${d}" "${rootmnt}/live/${d##*/}"
1419 # shows cow fs on /cow for use by live-snapshot
1420 mkdir -p "${rootmnt}/live
/cow
"
1421 mount -o move /cow "${rootmnt}/live/cow" >/dev/null 2>&1 || mount -o bind /cow "${rootmnt}/live/cow" || log_warning_msg "Unable to move or bind /cow to ${rootmnt}/live
/cow
"
1428 skip_uuid_check="${3}"
1430 # support for fromiso=.../isofrom=....
1431 if [ -n "$FROMISO" ]
1433 ISO_DEVICE=$(dirname $FROMISO)
1434 if ! [ -b $ISO_DEVICE ]
1436 # to support unusual device names like /dev/cciss/c0d0p1
1437 # as well we have to identify the block device name, let's
1438 # do that for up to 15 levels
1440 while [ -n "$ISO_DEVICE" ] && [ "$i" -gt 0 ]
1442 ISO_DEVICE=$(dirname ${ISO_DEVICE})
1443 [ -b "$ISO_DEVICE" ] && break
1448 if [ "$ISO_DEVICE" = "/" ]
1450 echo "Warning
: device
for bootoption isofrom
= ($FROMISO) not found.
">>/live.log
1453 mount "$ISO_DEVICE" /isofrom
1454 ISO_NAME="$
(echo $FROMISO |
sed "s|$ISO_DEVICE||")"
1455 loopdevname=$(setup_loop "/isofrom
/${ISO_NAME}" "loop
" "/sys
/block
/loop
*" "" '')
1456 devname="${loopdevname}"
1460 if [ -z "${devname}" ]
1462 devname=$(sys2dev "${sysdev}")
1465 if [ -d "${devname}" ]
1467 mount -o bind "${devname}" $mountpoint || continue
1469 if is_live_path $mountpoint
1477 [ -e "$devname" ] || continue
1479 if [ -n "${LIVE_MEDIA_OFFSET}" ]
1481 loopdevname=$(setup_loop "${devname}" "loop
" "/sys
/block
/loop
*" "${LIVE_MEDIA_OFFSET}" '')
1482 devname="${loopdevname}"
1485 fstype=$(get_fstype "${devname}")
1487 if is_supported_fs ${fstype}
1489 devuid=$(blkid -o value -s UUID "$devname")
1490 [ -n "$devuid" ] && grep -qs "\
<$devuid\
>" $tried && continue
1491 mount -t ${fstype} -o ro,noatime "${devname}" ${mountpoint} || continue
1492 [ -n "$devuid" ] && echo "$devuid" >> $tried
1494 if is_live_path ${mountpoint} && \
1495 ([ "${skip_uuid_check}" ] || matches_uuid ${mountpoint})
1500 umount ${mountpoint}
1504 if [ -n "${LIVE_MEDIA_OFFSET}" ]
1506 losetup -d "${loopdevname}"
1516 # don't start autodetection before timeout has expired
1517 if [ -n "${LIVE_MEDIA_TIMEOUT}" ]
1519 if [ "${timeout}" -lt "${LIVE_MEDIA_TIMEOUT}" ]
1525 # first look at the one specified in the command line
1526 case "${LIVE_MEDIA}" in
1528 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -vE "/(loop|ram|dm-|fd
)")
1530 if [ "$
(cat ${sysblock}/removable
)" = "1" ]
1532 if readlink ${sysblock} | grep -q usb ||
1533 readlink ${sysblock}/device | grep -q usb # linux < 2.6.29
1535 for dev in $(subdevices "${sysblock}")
1537 if check_dev "${dev}"
1549 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -vE "/(loop|ram|dm-|fd
)")
1551 if [ "$
(cat ${sysblock}/removable
)" = "1" ]
1553 for dev in $(subdevices "${sysblock}")
1555 if check_dev "${dev}"
1566 if [ ! -z "${LIVE_MEDIA}" ]
1568 if check_dev "null
" "${LIVE_MEDIA}" "skip_uuid_check
"
1576 # or do the scan of block devices
1577 # prefer removable devices over non-removable devices, so scan them first
1578 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | egrep -v "/(loop|ram|dm-|fd
)")
1580 if [ "$
(cat ${sysblock}/removable
)" = "1" ]
1582 removable_devices_to_scan="$removable_devices_to_scan $sysblock"
1584 nonremovable_devices_to_scan="$nonremovable_devices_to_scan $sysblock"
1587 devices_to_scan="$removable_devices_to_scan $nonremovable_devices_to_scan"
1589 for sysblock in $devices_to_scan
1591 devname=$(sys2dev "${sysblock}")
1592 [ -e "$devname" ] || continue
1593 fstype=$(get_fstype "${devname}")
1595 if /lib/udev/cdrom_id ${devname} > /dev/null
1597 if check_dev "null
" "${devname}"
1601 elif is_nice_device "${sysblock}"
1603 for dev in $(subdevices "${sysblock}")
1605 if check_dev "${dev}"
1610 elif [ "${fstype}" = "squashfs
" -o \
1611 "${fstype}" = "btrfs
" -o \
1612 "${fstype}" = "ext2
" -o \
1613 "${fstype}" = "ext3
" -o \
1614 "${fstype}" = "ext4
" -o \
1615 "${fstype}" = "jffs2
" ]
1617 # This is an ugly hack situation, the block device has
1618 # an image directly on it. It's hopefully
1619 # live-boot, so take it and run with it.
1620 ln -s "${devname}" "${devname}.${fstype}"
1621 echo "${devname}.
${fstype}"
1629 set_usplash_timeout ()
1631 if [ -x /sbin/usplash_write ]
1633 /sbin/usplash_write "TIMEOUT
120"
1634 else if [ -x /sbin/splashy_update ] ; then
1635 /sbin/splashy_update "TIMEOUT
120"
1641 media_mountpoint="${1}"
1643 log_begin_msg "Checking media integrity
"
1645 cd ${media_mountpoint}
1646 /bin/md5sum -c md5sum.txt < /dev/tty8 > /dev/tty8
1651 if [ "${RC}" -eq 0 ]
1653 log_success_msg "Everything ok
, will reboot
in 10 seconds.
"
1656 umount ${media_mountpoint}
1658 echo u > /proc/sysrq-trigger
1659 echo b > /proc/sysrq-trigger
1661 panic "Not ok
, a media defect is likely
, switch to VT8
for details.
"
1665 start_usplash_pulse ()
1667 if [ -x /sbin/usplash_write ]
1669 /sbin/usplash_write "PULSELOGO
"
1675 if [ -x /scripts/local-top/cryptroot ]; then
1676 /scripts/local-top/cryptroot
1683 tail -f live.log >&7 &
1686 # Ensure 'panic' function is overridden
1687 . /scripts/live-functions
1694 maybe_break live-premount
1695 log_begin_msg "Running
/scripts
/live-premount
"
1696 run_scripts /scripts/live-premount
1699 # Needed here too because some things (*cough* udev *cough*)
1700 # changes the timeout
1704 if [ ! -z "${NETBOOT}" ] || [ ! -z "${FETCH}" ] || [ ! -z "${HTTPFS}" ] || [ ! -z "${FTPFS}" ]
1708 livefs_root="${mountpoint}"
1710 panic "Unable to
find a live
file system on the network
"
1713 if [ -n "${ISCSI_PORTAL}" ]
1715 do_iscsi && livefs_root="${mountpoint}"
1716 elif [ -n "${PLAIN_ROOT}" ] && [ -n "${ROOT}" ]
1718 # Do a local boot from hd
1721 if [ -x /usr/bin/memdiskfind ]
1723 MEMDISK=$(/usr/bin/memdiskfind)
1727 # We found a memdisk, set up phram
1728 modprobe phram phram=memdisk,${MEMDISK}
1730 # Load mtdblock, the memdisk will be /dev/mtdblock0
1735 # Scan local devices for the image
1737 while [ "$i" -lt 60 ]
1739 livefs_root=$(find_livefs ${i})
1741 if [ -n "${livefs_root}" ]
1752 if [ -z "${livefs_root}" ]
1754 panic "Unable to
find a medium containing a live
file system
"
1757 if [ "${INTEGRITY_CHECK}" ]
1759 integrity_check "${livefs_root}"
1765 elif [ "${TODISK}" ]
1767 live_dest="${TODISK}"
1770 if [ "${live_dest}" ]
1772 log_begin_msg "Copying live media to
${live_dest}"
1773 copy_live_to "${livefs_root}" "${live_dest}"
1777 # if we do not unmount the ISO we can't run "fsck
/dev
/ice
" later on
1778 # because the mountpoint is left behind in /proc/mounts, so let's get
1779 # rid of it when running from RAM
1780 if [ -n "$FROMISO" ] && [ "${TORAM}" ]
1782 losetup -d /dev/loop0
1783 grep -q /isofrom /proc/mounts && umount /isofrom
1786 if [ -n "${MODULETORAMFILE}" ] || [ -n "${PLAIN_ROOT}" ]
1788 setup_unionfs "${livefs_root}" "${rootmnt}"
1791 mac="$
(echo ${mac} |
sed 's/-//g')"
1792 mount_images_in_directory "${livefs_root}" "${rootmnt}" "${mac}"
1796 if [ -n "${ROOT_PID}" ] ; then
1797 echo "${ROOT_PID}" > "${rootmnt}"/live/root.pid
1802 # unionfs-fuse needs /dev to be bind-mounted for the duration of
1803 # live-bottom; udev's init script will take care of things after that
1804 if [ "${UNIONTYPE}" = unionfs-fuse ]
1806 mount -n -o bind /dev "${rootmnt}/dev
"
1809 # Move to the new root filesystem so that programs there can get at it.
1810 if [ ! -d /root/live/image ]
1812 mkdir -p /root/live/image
1813 mount --move /live/image /root/live/image
1816 # aufs2 in kernel versions around 2.6.33 has a regression:
1817 # directories can't be accessed when read for the first the time,
1818 # causing a failure for example when accessing /var/lib/fai
1819 # when booting FAI, this simple workaround solves it
1820 ls /root/* >/dev/null 2>&1
1822 maybe_break live-bottom
1823 log_begin_msg "Running
/scripts
/live-bottom
\n"
1825 run_scripts /scripts/live-bottom
1828 if [ "${UNIONFS}" = unionfs-fuse ]
1830 umount "${rootmnt}/dev
"
1836 [ -w "${rootmnt}/var
/log
/" ] && cp live.log "${rootmnt}/var
/log
/" 2>/dev/null