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
)
56 NOCONSOLEKEYBOARD
="Yes"
65 export NOACCESSIBILITY NOAPTCDROM NOAUTOLOGIN NOCONSOLEKEYBOARD NOFASTBOOT NOFSTAB NOHOSTS NONETWORKING NOTIMEZONE NOXAUTOCONFIG NOXAUTOLOGIN
69 ACCESS
="${ARGUMENT#access=}"
74 DEFCONSOLE
="${ARGUMENT#*=}"
86 # Force dhcp even while netbooting
87 # Use for debugging in case somebody works on fixing dhclient
97 DEVICE
="${ARGUMENT#ethdevice=}"
102 ETHDEVICE
="${ARGUMENT#ethdevice=}"
107 ETHDEV_TIMEOUT
="${ARGUMENT#ethdevice-timeout=}"
108 export ETHDEV_TIMEOUT
112 FETCH
="${ARGUMENT#fetch=}"
117 FORCEPERSISTENTFSCK
="Yes"
118 export FORCEPERSISTENTFSCK
122 FTPFS
="${ARGUMENT#ftpfs=}"
127 HTTPFS
="${ARGUMENT#httpfs=}"
132 FROMISO
="${ARGUMENT#*=}"
137 USERNAME
="${ARGUMENT#username=}"
139 export USERNAME LIVECONF
143 USERFULLNAME
="${ARGUMENT#userfullname=}"
145 export USERFULLNAME LIVECONF
154 INTEGRITY_CHECK
="Yes"
155 export INTEGRITY_CHECK
159 STATICIP
="${ARGUMENT#ip=}"
161 if [ -z "${STATICIP}" ]
169 keyb
=*|kbd-chooser
/method
=*)
174 klayout
=*|console-setup
/layoutcode
=*)
175 KLAYOUT
="${ARGUMENT#*=}"
179 kvariant
=*|console-setup
/variantcode
=*)
180 KVARIANT
="${ARGUMENT#*=}"
184 kmodel
=*|console-setup
/modelcode
=*)
185 KMODEL
="${ARGUMENT#*=}"
190 KOPTIONS
="${ARGUMENT#koptions=}"
199 live-media
=*|bootfrom
=*)
200 LIVE_MEDIA
="${ARGUMENT#*=}"
204 live-media-encryption
=*|encryption
=*)
205 LIVE_MEDIA_ENCRYPTION
="${ARGUMENT#*=}"
206 export LIVE_MEDIA_ENCRYPTION
210 LIVE_MEDIA_OFFSET
="${ARGUMENT#live-media-offset=}"
211 export LIVE_MEDIA_OFFSET
215 LIVE_MEDIA_PATH
="${ARGUMENT#live-media-path=}"
216 export LIVE_MEDIA_PATH
219 live-media-timeout
=*)
220 LIVE_MEDIA_TIMEOUT
="${ARGUMENT#live-media-timeout=}"
221 export LIVE_MEDIA_TIMEOUT
225 MODULE
="${ARGUMENT#module=}"
230 NETBOOT
="${ARGUMENT#netboot=}"
235 NFSOPTS
="${ARGUMENT#nfsopts=}"
240 NFS_COW
="${ARGUMENT#nfscow=}"
245 NOACCESSIBILITY
="Yes"
246 export NOACCESSIBILITY
265 NOCONSOLEKEYBOARD
="Yes"
266 export NOCONSOLEKEYBOARD
301 export NOXSCREENSAVER
310 PERSISTENT
="${ARGUMENT#persistent=}"
311 if [ -z "${PERSISTENT}" ]
319 PERSISTENT_PATH
="${ARGUMENT#persistent-path=}"
320 export PERSISTENT_PATH
323 persistent-subtext
=*)
324 root_persistence
="${root_persistence}-${ARGUMENT#persistent-subtext=}"
325 home_persistence
="${home_persistence}-${ARGUMENT#persistent-subtext=}"
326 root_snapshot_label
="${root_snapshot_label}-${ARGUMENT#persistent-subtext=}"
327 home_snapshot_label
="${home_snapshot_label}-${ARGUMENT#persistent-subtext=}"
336 QUICKUSBMODULES
="Yes"
337 export QUICKUSBMODULES
340 preseed
/file=*|
file=*)
341 LOCATIONS
="${ARGUMENT#*=} ${LOCATIONS}"
351 question
="${ARGUMENT%%=*}"
352 value
="${ARGUMENT#*=}"
353 PRESEEDS
="${PRESEEDS}\"${question}=${value}\" "
373 TIMEZONE
="${ARGUMENT#timezone=}"
383 TODISK
="${ARGUMENT#todisk=}"
394 MODULETORAM
="${ARGUMENT#toram=}"
395 export TORAM MODULETORAM
409 SKIP_UNION_MOUNTS
="Yes"
410 export SKIP_UNION_MOUNTS
414 ROOT
="${ARGUMENT#root=}"
419 UNIONTYPE
="${ARGUMENT#union=}"
429 XDRIVER
="${ARGUMENT#xdriver=}"
434 XVIDEOMODE
="${ARGUMENT#xvideomode=}"
440 # sort of compatibility with netboot.h from linux docs
441 if [ -z "${NETBOOT}" ]
443 if [ "${ROOT}" = "/dev/nfs" ]
447 elif [ "${ROOT}" = "/dev/cifs" ]
454 if [ -z "${MODULE}" ]
460 if [ -z "${UNIONTYPE}" ]
471 if [ -d "${DIRECTORY}"/"${LIVE_MEDIA_PATH}" ]
473 for FILESYSTEM
in squashfs ext2 ext3 ext4 xfs dir jffs2
475 if [ "$(echo ${DIRECTORY}/${LIVE_MEDIA_PATH}/*.${FILESYSTEM})" != "${DIRECTORY}/${LIVE_MEDIA_PATH}/*.${FILESYSTEM}" ]
487 if [ "${IGNORE_UUID}" ] ||
[ ! -e /conf
/uuid.conf
]
493 uuid
="$(cat /conf/uuid.conf)"
495 for try_uuid_file
in "${path}/.disk/live-uuid"*
497 [ -e "${try_uuid_file}" ] ||
continue
499 try_uuid
="$(cat "${try_uuid_file}")"
501 if [ "${uuid}" = "${try_uuid}" ]
510 get_backing_device
()
513 *.squashfs|
*.ext2|
*.ext3|
*.ext4|
*.jffs2
)
514 echo $
(setup_loop
"${1}" "loop" "/sys/block/loop*" '0' "${LIVE_MEDIA_ENCRYPTION}" "${2}")
522 panic
"Unrecognized live filesystem: ${1}"
527 match_files_in_dir
()
529 # Does any files match pattern ${1} ?
532 if [ "$(echo ${pattern})" != "${pattern}" ]
540 mount_images_in_directory
()
547 if match_files_in_dir
"${directory}/${LIVE_MEDIA_PATH}/*.squashfs" ||
548 match_files_in_dir
"${directory}/${LIVE_MEDIA_PATH}/*.ext2" ||
549 match_files_in_dir
"${directory}/${LIVE_MEDIA_PATH}/*.ext3" ||
550 match_files_in_dir
"${directory}/${LIVE_MEDIA_PATH}/*.ext4" ||
551 match_files_in_dir
"${directory}/${LIVE_MEDIA_PATH}/*.jffs2" ||
552 match_files_in_dir
"${directory}/${LIVE_MEDIA_PATH}/*.dir"
554 [ -n "${mac}" ] && adddirectory="${directory}/${LIVE_MEDIA_PATH}/${mac}"
555 setup_unionfs
"${directory}/${LIVE_MEDIA_PATH}" "${rootmnt}" "${adddirectory}"
557 panic
"No supported filesystem images found at /${LIVE_MEDIA_PATH}."
563 sysfs_path
="${1#/sys}"
565 if /lib
/udev
/path_id
"${sysfs_path}" |
egrep -q "ID_PATH=(usb|pci-|platform-orion-ehci|platform-mmc|platform-mxsdhci|)"
568 elif echo "${sysfs_path}" |
grep -q '^/block/vd[a-z]$'
571 elif echo ${sysfs_path} |
grep -q "^/block/dm-"
583 copyto
="${copyfrom}_swap"
585 if [ -z "${MODULETORAM}" ]
587 size
=$
(fs_size
"" ${copyfrom}/${LIVE_MEDIA_PATH} "used")
589 MODULETORAMFILE
="${copyfrom}/${LIVE_MEDIA_PATH}/${MODULETORAM}"
591 if [ -f "${MODULETORAMFILE}" ]
593 size
=$
( expr $
(ls -la ${MODULETORAMFILE} |
awk '{print $5}') / 1024 + 5000 )
595 log_warning_msg
"Error: toram-module ${MODULETORAM} (${MODULETORAMFILE}) could not be read."
600 if [ "${copytodev}" = "ram" ]
603 freespace
=$
(awk '/^MemFree:/{f=$2} /^Cached:/{c=$2} END{print f+c}' /proc
/meminfo
)
604 mount_options
="-o size=${size}k"
609 # it should be a writable block device
610 if [ -b "${copytodev}" ]
614 fstype
=$
(get_fstype
"${dev}")
615 freespace
=$
(fs_size
"${dev}")
617 log_warning_msg
"${copytodev} is not a block device."
622 if [ "${freespace}" -lt "${size}" ]
624 log_warning_msg
"Not enough free ${free_string} (${freespace}k free, ${size}k needed) to copy live media in ${copytodev}."
628 # begin copying (or uncompressing)
630 log_begin_msg
"mount -t ${fstype} ${mount_options} ${dev} ${copyto}"
631 mount
-t "${fstype}" ${mount_options} "${dev}" "${copyto}"
633 if [ "${extension}" = "tgz" ]
636 tar zxf
"${copyfrom}/${LIVE_MEDIA_PATH}/$(basename ${FETCH})"
637 rm -f "${copyfrom}/${LIVE_MEDIA_PATH}/$(basename ${FETCH})"
638 mount
-r -o move
"${copyto}" "${rootmnt}"
641 if [ -n "${MODULETORAMFILE}" ]
645 echo " * Copying $MODULETORAMFILE to RAM" 1>/dev
/console
646 rsync
-a --progress ${MODULETORAMFILE} ${copyto} 1>/dev
/console
# copy only the filesystem module
648 cp ${MODULETORAMFILE} ${copyto} # copy only the filesystem module
653 echo " * Copying whole medium to RAM" 1>/dev
/console
654 rsync
-a --progress ${copyfrom}/* ${copyto} 1>/dev
/console
# "cp -a" from busybox also copies hidden files
656 mkdir
-p ${copyto}/${LIVE_MEDIA_PATH}
657 cp -a ${copyfrom}/${LIVE_MEDIA_PATH}/* ${copyto}/${LIVE_MEDIA_PATH}
658 if [ -e ${copyfrom}/${LIVE_MEDIA_PATH}/.disk
]
660 cp -a ${copyfrom}/${LIVE_MEDIA_PATH}/.disk ${copyto}
666 mount
-r -o move
${copyto} ${copyfrom}
675 modprobe
-q af_packet
# For DHCP
680 if [ -z "${NETBOOT}" ] && [ -z "${FETCH}" ] && \
681 [ -z "${HTTPFS}" ] && [ -z "${FTPFS}" ]
684 # if ethdevice was not specified on the kernel command line
685 # make sure we try to get a working network configuration
686 # for *every* present network device (except for loopback of course)
687 if [ -z "$ETHDEVICE" ] ; then
688 echo "If you want to boot from a specific device use bootoption ethdevice=..."
689 for device
in /sys
/class
/net
/*; do
691 if [ "$dev" != "lo" ] ; then
692 ETHDEVICE
="$ETHDEVICE $dev"
697 # split args of ethdevice=eth0,eth1 into "eth0 eth1"
698 for device
in $
(echo $ETHDEVICE |
sed 's/,/ /g') ; do
699 devlist
="$devlist $device"
702 [ -n "$ETHDEV_TIMEOUT" ] || ETHDEV_TIMEOUT
=15
703 echo "Using timeout of $ETHDEV_TIMEOUT seconds for network configuration."
705 # this is tricky (and ugly) because ipconfig sometimes just hangs/runs into
706 # an endless loop; iff execution fails give it two further tries, that's
707 # why we use '$devlist $devlist $devlist' for the other for loop
708 for dev
in $devlist $devlist $devlist ; do
709 echo "Executing ipconfig -t $ETHDEV_TIMEOUT $dev"
710 ipconfig
-t "$ETHDEV_TIMEOUT" $dev |
tee -a /netboot.config
&
712 sleep "$ETHDEV_TIMEOUT" ; sleep 1
713 if [ -r /proc
/"$jobid"/status
] ; then
714 echo "Killing job $jobid for device $dev as ipconfig ran into recursion..."
718 # if configuration of device worked we should have an assigned
719 # IP address, iff so let's use the according as $DEVICE for later usage
720 # simple and primitive approach which seems to work fine
721 if ifconfig
$dev |
grep -q 'inet.*addr:' ; then
728 ipconfig
${DEVICE} |
tee /netboot.config
731 # source relevant ipconfig output
732 OLDHOSTNAME
=${HOSTNAME}
733 .
/tmp
/net-
${DEVICE}.conf
734 [ -z ${HOSTNAME} ] && HOSTNAME
=${OLDHOSTNAME}
737 # Check if we have a network device at all
738 if ! ls /sys
/class
/net
/"$DEVICE" > /dev
/null
2>&1 && \
739 ! ls /sys
/class
/net
/eth0
> /dev
/null
2>&1 && \
740 ! ls /sys
/class
/net
/wlan0
> /dev
/null
2>&1 && \
741 ! ls /sys
/class
/net
/ath0
> /dev
/null
2>&1 && \
742 ! ls /sys
/class
/net
/ra0
> /dev
/null
2>&1
744 panic
"No supported network device found, maybe a non-mainline driver is required."
747 if [ "${NFSROOT}" = "auto" ]
749 NFSROOT
=${ROOTSERVER}:${ROOTPATH}
754 if ( [ -n "${FETCH}" ] || [ -n "${HTTPFS}" ] || [ -n "${FTPFS}" ] )
760 if [ "${NFSROOT#*:}" = "${NFSROOT}" ] && [ "$NETBOOT" != "cifs" ]
762 NFSROOT
=${ROOTSERVER}:${NFSROOT}
765 log_begin_msg
"Trying netboot from ${NFSROOT}"
767 if [ "${NETBOOT}" != "nfs" ] && do_cifsmount
785 for webfile
in HTTPFS FTPFS FETCH
787 local url
="$(eval echo \"\$\{${webfile}\}\")"
788 local extension
="$(echo "${url}" | sed 's/\(.*\)\.\(.*\)/\2/')"
792 case "${extension}" in
793 iso|squashfs|tgz|
tar)
794 if [ "${extension}" = "iso" ]
796 mkdir
-p "${alt_mountpoint}"
797 dest
="${alt_mountpoint}"
799 local dest
="${mountpoint}/${LIVE_MEDIA_PATH}"
800 mount
-t ramfs ram
"${mountpoint}"
803 if [ "${webfile}" = "FETCH" ]
807 ip
="$(dirname $url | sed -e 's|tftp://||g' -e 's|/.*$||g')"
808 rfile
="$(echo $url | sed -e "s|tftp
://$ip||g
")"
809 lfile
="$(basename $url)"
810 log_begin_msg
"Trying tftp -g -b 10240 -r $rfile -l ${dest}/$lfile $ip"
811 tftp
-g -b 10240 -r $rfile -l ${dest}/$lfile $ip
815 log_begin_msg
"Trying wget ${url} -O ${dest}/$(basename ${url})"
816 wget
"${url}" -O "${dest}/$(basename ${url})"
820 log_begin_msg
"Trying to mount ${url} on ${dest}/$(basename ${url})"
821 if [ "${webfile}" = "FTPFS" ]
823 FUSE_MOUNT
="curlftpfs"
824 url
="$(dirname ${url})"
829 $FUSE_MOUNT "${url}" "${dest}"
831 [ ${?} -eq 0 ] && rc
=0
832 [ "${extension}" = "tgz" ] && live_dest
="ram"
833 if [ "${extension}" = "iso" ]
835 isoloop
=$
(setup_loop
"${dest}/$(basename "${url}")" "loop" "/sys/block/loop*" "" '')
836 mount
-t iso9660
"${isoloop}" "${mountpoint}"
843 log_begin_msg
"Unrecognized archive extension for ${url}"
851 if [ -d "${alt_mountpoint}" ]
853 umount
"${alt_mountpoint}"
854 rmdir "${alt_mountpoint}"
856 umount
"${mountpoint}"
857 elif [ "${webfile}" != "FETCH" ] ; then
871 if [ -z "${NFSOPTS}" ]
876 log_begin_msg
"Trying nfsmount -o nolock -o ro ${NFSOPTS} ${NFSROOT} ${mountpoint}"
878 # FIXME: This while loop is an ugly HACK round an nfs bug
880 while [ "$i" -lt 60 ]
882 nfsmount
-o nolock
-o ro
${NFSOPTS} "${NFSROOT}" "${mountpoint}" && rc=0 && break
894 if [ -x "/sbin
/mount.cifs
" ]
896 if [ -z "${NFSOPTS}" ]
898 CIFSOPTS="-ouser=root
,password
="
900 CIFSOPTS="${NFSOPTS}"
903 log_begin_msg "Trying mount.cifs
${NFSROOT} ${mountpoint} ${CIFSOPTS}"
906 if mount.cifs "${NFSROOT}" "${mountpoint}" "${CIFSOPTS}"
920 size=$(fs_size "${fromdev}" "" "used
")
922 if [ -b "${fromdev}" ]
925 if [ -n "${HOMEMOUNTED}" -a "${snap_type}" = "HOME
" ]
927 todev=$(awk -v pat="$
(base_path
${todir})" '$2 == pat { print $1 }' /proc/mounts)
928 freespace=$(df -k | awk '/'${todev}'/{print $4}')
930 freespace=$(awk '/^MemFree:/{f=$2} /^Cached:/{c=$2} END{print f+c}' /proc/meminfo)
933 tomount="/mnt
/tmpsnap
"
935 if [ ! -d "${tomount}" ]
937 mkdir -p "${tomount}"
940 fstype=$(get_fstype "${fromdev}")
942 if [ -n "${fstype}" ]
945 mount -o ro -t "${fstype}" "${fromdev}" "${tomount}" || log_warning_msg "Error in mount -t ${fstype} -o ro ${fromdev} ${tomount}"
946 cp -a "${tomount}"/* ${todir}
949 log_warning_msg "Unrecognized fstype
: ${fstype} on ${fromdev}:${snap_type}"
954 if echo ${fromdev} | grep -qs loop
956 losetup -d "${fromdev}"
963 log_warning_msg "Unable to
find the snapshot
${snap_type} medium
"
969 # Look for ${snap_label}.* in block devices
972 if [ "${PERSISTENT}" != "nofiles
" ]
974 # search for image files
975 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
")
978 if [ -z "${snapdata}" ]
980 snapdata=$(find_cow_device "${snap_label}")
987 # copy the contents of previously found snapshot to ${snap_mount}
988 # and remember the device and filename for resync on exit in live-boot.init
994 if [ -n "${snapdata}" ] && [ ! -b "${snapdata}" ]
996 log_success_msg "found snapshot
: ${snapdata}"
997 snapdev="$
(echo ${snapdata} | cut
-f1 -d ' ')"
998 snapback="$
(echo ${snapdata} | cut
-f2 -d ' ')"
999 snapfile="$
(echo ${snapdata} | cut
-f3 -d ' ')"
1002 if ! try_mount "${snapdev}" "${snapback}" "ro
"
1007 if echo "${snapfile}" | grep -qs '\(squashfs\|ext2\|ext3\|ext4\|jffs2\)'
1009 # squashfs, jffs2 or ext2/ext3/ext4 snapshot
1010 dev=$(get_backing_device "${snapback}/${snapfile}")
1012 do_snap_copy "${dev}" "${snap_mount}" "${snap_type}"
1017 # Unfortunately klibc's cpio is incompatible with the
1018 # rest of the world; everything else requires -u -d,
1019 # while klibc doesn't implement them. Try to detect
1020 # whether it's in use.
1021 cpiopath="$
(which cpio)" || true
1022 if [ "$cpiopath" ] && grep -aq /lib/klibc "$cpiopath"
1026 cpioargs='--unconditional --make-directories'
1029 if ! (cd "${snap_mount}" && zcat "${snapback}/${snapfile}" | cpio $cpioargs --extract --preserve-modification-time --no-absolute-filenames --sparse 2>/dev/null)
1031 log_warning_msg "failure to
\"zcat
${snapback}/${snapfile} |
cpio $cpioargs --extract --preserve-modification-time --no-absolute-filenames --sparse\""
1035 umount "${snapback}" || log_warning_msg "failure to
\"umount
${snapback}\""
1037 if [ "${RES}" != "0" ]
1039 log_warning_msg "Impossible to include the
${snapfile} Snapshot
file"
1042 elif [ -b "${snapdata}" ]
1044 # Try to find if it could be a snapshot partition
1046 log_success_msg "found snapshot
${snap_type} device on
${dev}"
1047 if echo "${dev}" | grep -qs loop
1049 # strange things happens, user confused?
1050 snaploop=$( losetup ${dev} | awk '{print $3}' | tr -d '()' )
1051 snapfile=$(basename ${snaploop})
1052 snapdev=$(awk -v pat="$
( dirname ${snaploop})" '$2 == pat { print $1 }' /proc/mounts)
1057 if ! do_snap_copy "${dev}" "${snap_mount}" "${snap_type}"
1059 log_warning_msg "Impossible to include the
${snap_type} Snapshot
"
1062 if [ -n "${snapfile}" ]
1064 # it was a loop device, user confused
1069 log_warning_msg "Impossible to include the
${snap_type} Snapshot
"
1073 echo "export ${snap_type}SNAP="/cow${snap_mount#$rootmnt}":${snapdev}:${snapfile}" >> /etc/live.conf # for resync on reboot/halt
1079 image_directory="${1}"
1081 addimage_directory="${3}"
1083 case ${UNIONTYPE} in
1085 modprobe -q -b ${UNIONTYPE}
1087 if ! cut -f2 /proc/filesystems | grep -q "^
${UNIONTYPE}\$
" && [ -x /bin/unionfs-fuse ]
1089 echo "${UNIONTYPE} not available
, falling back to unionfs-fuse.
"
1090 echo "This might be really slow.
"
1092 UNIONTYPE="unionfs-fuse
"
1097 if [ "${UNIONTYPE}" = unionfs-fuse ]
1102 # run-init can't deal with images in a subdir, but we're going to
1103 # move all of these away before it runs anyway. No, we're not,
1104 # put them in / since move-mounting them into / breaks mono and
1109 # Let's just mount the read-only file systems first
1113 if [ "${UNIONTYPE}" = "aufs
" ]
1116 noxino_opt="noxino
,"
1117 elif [ "${UNIONTYPE}" = "unionfs-fuse
" ]
1124 if [ -z "${PLAIN_ROOT}" ]
1126 # Read image names from ${MODULE}.module if it exists
1127 if [ -e "${image_directory}/filesystem.
${MODULE}.module
" ]
1129 for IMAGE in $(cat ${image_directory}/filesystem.${MODULE}.module)
1131 image_string="${image_string} ${image_directory}/${IMAGE}"
1133 elif [ -e "${image_directory}/${MODULE}.module
" ]
1135 for IMAGE in $(cat ${image_directory}/${MODULE}.module)
1137 image_string="${image_string} ${image_directory}/${IMAGE}"
1140 # ${MODULE}.module does not exist, create a list of images
1141 for FILESYSTEM in squashfs ext2 ext3 ext4 xfs jffs2 dir
1143 for IMAGE in "${image_directory}"/*."${FILESYSTEM}"
1145 if [ -e "${IMAGE}" ]
1147 image_string="${image_string} ${IMAGE}"
1152 if [ -n "${addimage_directory}" ] && [ -d "${addimage_directory}" ]
1154 for FILESYSTEM in squashfs ext2 ext3 ext4 xfs jffs2 dir
1156 for IMAGE in "${addimage_directory}"/*."${FILESYSTEM}"
1158 if [ -e "${IMAGE}" ]
1160 image_string="${image_string} ${IMAGE}"
1167 image_string="$
(echo ${image_string} |
sed -e 's/ /\n/g' |
sort )"
1170 [ -n "${MODULETORAMFILE}" ] && image_string="${image_directory}/$(basename ${MODULETORAMFILE})"
1174 for image in ${image_string}
1176 imagename=$(basename "${image}")
1178 export image devname
1179 maybe_break live-realpremount
1180 log_begin_msg "Running
/scripts
/live-realpremount
"
1181 run_scripts /scripts/live-realpremount
1184 if [ -d "${image}" ]
1186 # it is a plain directory: do nothing
1187 rofsstring="${image}=${roopt}:${rofsstring}"
1188 rofslist="${image} ${rofslist}"
1189 elif [ -f "${image}" ]
1191 if losetup --help 2>&1 | grep -q -- "-r\b"
1193 backdev=$(get_backing_device "${image}" "-r")
1195 backdev=$(get_backing_device "${image}")
1197 fstype=$(get_fstype "${backdev}")
1199 if [ "${fstype}" = "unknown
" ]
1201 panic "Unknown
file system
type on
${backdev} (${image})"
1204 if [ -z "${fstype}" ]
1206 fstype="${imagename##*.}"
1207 log_warning_msg "Unknown
file system
type on
${backdev} (${image}), assuming ${fstype}.
"
1210 mkdir -p "${croot}/${imagename}"
1211 log_begin_msg "Mounting
\"${image}\" on \"${croot}${imagename}\" via \"${backdev}\""
1212 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}"
1217 # we have a plain root system
1218 mkdir -p "${croot}/filesystem
"
1219 log_begin_msg "Mounting
\"${image_directory}\" on
\"${croot}/filesystem
\""
1220 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}"
1222 mount -o bind ${croot}/filesystem $mountpoint
1226 rofsstring=${rofsstring%:}
1230 # Looking for "${root_persistence}" device or file
1231 if [ -n "${PERSISTENT}" ] && [ -z "${NOPERSISTENT}" ]
1233 if [ -z "${QUICKUSBMODULES}" ]
1236 num_block=$(ls -l /sys/block | wc -l)
1237 for module in sd_mod uhci-hcd ehci-hcd ohci-hcd usb-storage
1239 modprobe -q -b ${module}
1245 # For some reason, udevsettle does not block in this scenario,
1246 # so we sleep for a little while.
1248 # See https://bugs.launchpad.net/ubuntu/+source/casper/+bug/84591
1249 for timeout in 5 4 3 2 1
1253 if [ $(ls -l /sys/block | wc -l) -gt ${num_block} ]
1260 # search for label and files (this could be hugely optimized)
1261 cowprobe=$(find_cow_device "${root_persistence}")
1262 if [ -b "${cowprobe}" ]
1264 # Blacklist /cow device, to avoid inconsistent setups for overlapping snapshots
1265 # makes sense to have both persistence for /cow and /home mounted, maybe also with
1266 # snapshots to be sure to really store some e.g key config files,
1267 # but not on the same media
1268 blacklistdev="${cowprobe}"
1269 PERSISTENCE_IS_ON="1"
1270 export PERSISTENCE_IS_ON
1272 # homecow just mount something on /home, this should be generalized some way
1273 homecow=$(find_cow_device "${home_persistence}" "${blacklistdev}")
1274 if [ -b "${homecow}" ]
1276 PERSISTENCE_IS_ON="1"
1277 export PERSISTENCE_IS_ON
1279 root_snapdata=$(find_snap "${root_snapshot_label}" "${blacklistdev}")
1280 # This second type should be removed when snapshot will get smarter,
1281 # hence when "/etc
/live-snapshot
*list
" will be supported also by
1282 # ext2|ext3|ext4|jffs2 snapshot types.
1283 home_snapdata=$(find_snap "${home_snapshot_label}" "${blacklistdev}")
1285 if [ -b "${cowprobe}" ]
1287 cowdevice=${cowprobe}
1288 cow_fstype=$(get_fstype "${cowprobe}")
1289 cow_mountopt="rw
,noatime
"
1291 if [ "${FORCEPERSISTENTFSCK}" = "Yes
" ]
1293 fsck -y ${cowdevice}
1296 log_warning_msg "Unable to
find the persistent medium
"
1299 cow_mountopt="rw
,noatime
,mode
=755"
1301 elif [ -n "${NFS_COW}" ] && [ -z "${NOPERSISTENT}" ]
1303 # check if there are any nfs options
1304 if echo ${NFS_COW}|grep -q ','
1306 nfs_cow_opts="-o nolock
,$
(echo ${NFS_COW}|cut
-d, -f2-)"
1307 nfs_cow=$(echo ${NFS_COW}|cut -d, -f1)
1309 nfs_cow_opts="-o nolock
"
1315 cowdevice=$(echo ${nfs_cow}|sed "s
/client_mac_address
/${mac}/")
1318 panic "unable to determine mac address
"
1323 cow_mountopt="rw
,noatime
,mode
=755"
1326 if [ "${cow_fstype}" = "nfs
" ]
1329 "Trying nfsmount
${nfs_cow_opts} ${cowdevice} /cow
"
1330 nfsmount ${nfs_cow_opts} ${cowdevice} /cow || \
1331 panic "Can not mount
${cowdevice} (n
: ${cow_fstype}) on
/cow
"
1333 mount -t ${cow_fstype} -o ${cow_mountopt} ${cowdevice} /cow || \
1334 panic "Can not mount
${cowdevice} (o
: ${cow_fstype}) on
/cow
"
1337 rofscount=$(echo ${rofslist} |wc -w)
1339 if [ -n "${EXPOSED_ROOT}" ]
1341 if [ ${rofscount} -ne 1 ]
1343 panic "only one RO
file system supported with exposedroot
: ${rofslist}"
1345 exposedrootfs=${rofslist%% }
1347 mount --bind ${exposedrootfs} ${rootmnt} || \
1348 panic "bind mount of
${exposedrootfs} failed
"
1350 if [ -z "${SKIP_UNION_MOUNTS}" ]
1352 cow_dirs='/var/tmp /var/lock /var/run /var/log /var/spool /home /var/lib/live'
1357 for dir in ${cow_dirs}; do
1360 case "${UNIONTYPE}" in
1362 (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}")
1363 mkdir
-p /dev
/.initramfs
/varrun
1364 pidof unionfs-fuse
>> /dev
/.initramfs
/varrun
/sendsigs.omit || true
1368 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
"
1373 case "${UNIONTYPE}" in
1375 (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}")
1376 mkdir
-p /dev
/.initramfs
/varrun
1377 pidof unionfs-fuse
>> /dev
/.initramfs
/varrun
/sendsigs.omit || true
1381 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}"
1386 # Correct the permissions of /:
1387 chmod 0755 "${rootmnt}"
1389 # tmpfs file systems
1391 mkdir -p "${rootmnt}/live
"
1392 mount -t tmpfs tmpfs ${rootmnt}/live
1394 # Adding other custom mounts
1395 if [ -n "${PERSISTENT}" ] && [ -z "${NOPERSISTENT}" ]
1397 # directly mount /home
1398 # FIXME: add a custom mounts configurable system
1400 if [ -b "${homecow}" ]
1402 mount -t $(get_fstype "${homecow}") -o rw,noatime "${homecow}" "${rootmnt}/home
"
1403 export HOMEMOUNTED=1 # used to proper calculate free space in do_snap_copy()
1405 log_warning_msg "Unable to
find the persistent home medium
"
1408 # Look for other snapshots to copy in
1409 try_snap "${root_snapdata}" "${rootmnt}" "ROOT
"
1410 # This second type should be removed when snapshot grow smarter
1411 try_snap "${home_snapdata}" "${rootmnt}/home
" "HOME
"
1414 if [ -n "${SHOWMOUNTS}" ]
1416 for d in ${rofslist}
1418 mkdir -p "${rootmnt}/live
/${d##*/}"
1422 # do nothing # mount -o bind "${d}" "${rootmnt}/live/${d##*/}"
1426 case "${UNIONTYPE}" in
1428 mount -o bind "${d}" "${rootmnt}/live/${d##*/}"
1432 mount -o move "${d}" "${rootmnt}/live/${d##*/}"
1440 # shows cow fs on /cow for use by live-snapshot
1441 mkdir -p "${rootmnt}/live
/cow
"
1442 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
"
1449 skip_uuid_check="${3}"
1451 # support for fromiso=.../isofrom=....
1452 if [ -n "$FROMISO" ]
1454 ISO_DEVICE=$(dirname $FROMISO)
1455 if ! [ -b $ISO_DEVICE ]
1457 # to support unusual device names like /dev/cciss/c0d0p1
1458 # as well we have to identify the block device name, let's
1459 # do that for up to 15 levels
1461 while [ -n "$ISO_DEVICE" ] && [ "$i" -gt 0 ]
1463 ISO_DEVICE=$(dirname ${ISO_DEVICE})
1464 [ -b "$ISO_DEVICE" ] && break
1469 if [ "$ISO_DEVICE" = "/" ]
1471 echo "Warning
: device
for bootoption isofrom
= ($FROMISO) not found.
">>/live.log
1474 mount "$ISO_DEVICE" /isofrom
1475 ISO_NAME="$
(echo $FROMISO |
sed "s|$ISO_DEVICE||")"
1476 loopdevname=$(setup_loop "/isofrom
/${ISO_NAME}" "loop
" "/sys
/block
/loop
*" "" '')
1477 devname="${loopdevname}"
1481 if [ -z "${devname}" ]
1483 devname=$(sys2dev "${sysdev}")
1486 if [ -d "${devname}" ]
1488 mount -o bind "${devname}" $mountpoint || continue
1490 if is_live_path $mountpoint
1498 [ -e "$devname" ] || continue
1500 if [ -n "${LIVE_MEDIA_OFFSET}" ]
1502 loopdevname=$(setup_loop "${devname}" "loop
" "/sys
/block
/loop
*" "${LIVE_MEDIA_OFFSET}" '')
1503 devname="${loopdevname}"
1506 fstype=$(get_fstype "${devname}")
1508 if is_supported_fs ${fstype}
1510 devuid=$(blkid -o value -s UUID "$devname")
1511 [ -n "$devuid" ] && grep -qs "\
<$devuid\
>" $tried && continue
1512 mount -t ${fstype} -o ro,noatime "${devname}" ${mountpoint} || continue
1513 [ -n "$devuid" ] && echo "$devuid" >> $tried
1515 if is_live_path ${mountpoint} && \
1516 ([ "${skip_uuid_check}" ] || matches_uuid ${mountpoint})
1521 umount ${mountpoint}
1525 if [ -n "${LIVE_MEDIA_OFFSET}" ]
1527 losetup -d "${loopdevname}"
1537 # don't start autodetection before timeout has expired
1538 if [ -n "${LIVE_MEDIA_TIMEOUT}" ]
1540 if [ "${timeout}" -lt "${LIVE_MEDIA_TIMEOUT}" ]
1546 # first look at the one specified in the command line
1547 case "${LIVE_MEDIA}" in
1549 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -vE "/(loop|ram|dm-|fd
)")
1551 if [ "$
(cat ${sysblock}/removable
)" = "1" ]
1553 if readlink ${sysblock} | grep -q usb ||
1554 readlink ${sysblock}/device | grep -q usb # linux < 2.6.29
1556 for dev in $(subdevices "${sysblock}")
1558 if check_dev "${dev}"
1570 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -vE "/(loop|ram|dm-|fd
)")
1572 if [ "$
(cat ${sysblock}/removable
)" = "1" ]
1574 for dev in $(subdevices "${sysblock}")
1576 if check_dev "${dev}"
1587 if [ ! -z "${LIVE_MEDIA}" ]
1589 if check_dev "null
" "${LIVE_MEDIA}" "skip_uuid_check
"
1597 # or do the scan of block devices
1598 # prefer removable devices over non-removable devices, so scan them first
1599 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | egrep -v "/(loop|ram|dm-|fd
)")
1601 if [ "$
(cat ${sysblock}/removable
)" = "1" ]
1603 removable_devices_to_scan="$removable_devices_to_scan $sysblock"
1605 nonremovable_devices_to_scan="$nonremovable_devices_to_scan $sysblock"
1608 devices_to_scan="$removable_devices_to_scan $nonremovable_devices_to_scan"
1610 for sysblock in $devices_to_scan
1612 devname=$(sys2dev "${sysblock}")
1613 [ -e "$devname" ] || continue
1614 fstype=$(get_fstype "${devname}")
1616 if /lib/udev/cdrom_id ${devname} > /dev/null
1618 if check_dev "null
" "${devname}"
1622 elif is_nice_device "${sysblock}"
1624 for dev in $(subdevices "${sysblock}")
1626 if check_dev "${dev}"
1631 elif [ "${fstype}" = "squashfs
" -o \
1632 "${fstype}" = "ext2
" -o \
1633 "${fstype}" = "ext3
" -o \
1634 "${fstype}" = "ext4
" -o \
1635 "${fstype}" = "jffs2
" ]
1637 # This is an ugly hack situation, the block device has
1638 # an image directly on it. It's hopefully
1639 # live-boot, so take it and run with it.
1640 ln -s "${devname}" "${devname}.${fstype}"
1641 echo "${devname}.
${fstype}"
1649 set_usplash_timeout ()
1651 if [ -x /sbin/usplash_write ]
1653 /sbin/usplash_write "TIMEOUT
120"
1654 else if [ -x /sbin/splashy_update ] ; then
1655 /sbin/splashy_update "TIMEOUT
120"
1661 media_mountpoint="${1}"
1663 log_begin_msg "Checking media integrity
"
1665 cd ${media_mountpoint}
1666 /bin/md5sum -c md5sum.txt < /dev/tty8 > /dev/tty8
1671 if [ "${RC}" -eq 0 ]
1673 log_success_msg "Everything ok
, will reboot
in 10 seconds.
"
1676 umount ${media_mountpoint}
1678 echo u > /proc/sysrq-trigger
1679 echo b > /proc/sysrq-trigger
1681 panic "Not ok
, a media defect is likely
, switch to VT8
for details.
"
1685 start_usplash_pulse ()
1687 if [ -x /sbin/usplash_write ]
1689 /sbin/usplash_write "PULSELOGO
"
1695 if [ -x /scripts/local-top/cryptroot ]; then
1696 /scripts/local-top/cryptroot
1703 tail -f live.log >&7 &
1706 # Ensure 'panic' function is overridden
1707 . /scripts/live-functions
1714 maybe_break live-premount
1715 log_begin_msg "Running
/scripts
/live-premount
"
1716 run_scripts /scripts/live-premount
1719 # Needed here too because some things (*cough* udev *cough*)
1720 # changes the timeout
1724 if [ ! -z "${NETBOOT}" ] || [ ! -z "${FETCH}" ] || [ ! -z "${HTTPFS}" ] || [ ! -z "${FTPFS}" ]
1728 livefs_root="${mountpoint}"
1730 panic "Unable to
find a live
file system on the network
"
1733 if [ -n "${PLAIN_ROOT}" ] && [ -n "${ROOT}" ]
1735 # Do a local boot from hd
1738 # Scan local devices for the image
1740 while [ "$i" -lt 60 ]
1742 livefs_root=$(find_livefs ${i})
1744 if [ -n "${livefs_root}" ]
1755 if [ -z "${livefs_root}" ]
1757 panic "Unable to
find a medium containing a live
file system
"
1760 if [ "${INTEGRITY_CHECK}" ]
1762 integrity_check "${livefs_root}"
1768 elif [ "${TODISK}" ]
1770 live_dest="${TODISK}"
1773 if [ "${live_dest}" ]
1775 log_begin_msg "Copying live media to
${live_dest}"
1776 copy_live_to "${livefs_root}" "${live_dest}"
1780 # if we do not unmount the ISO we can't run "fsck
/dev
/ice
" later on
1781 # because the mountpoint is left behind in /proc/mounts, so let's get
1782 # rid of it when running from RAM
1783 if [ -n "$FROMISO" ] && [ "${TORAM}" ]
1785 losetup -d /dev/loop0
1786 grep -q /isofrom /proc/mounts && umount /isofrom
1789 if [ -n "${MODULETORAMFILE}" ] || [ -n "${PLAIN_ROOT}" ]
1791 setup_unionfs "${livefs_root}" "${rootmnt}"
1794 mac="$
(echo ${mac} |
sed 's/-//g')"
1795 mount_images_in_directory "${livefs_root}" "${rootmnt}" "${mac}"
1800 # unionfs-fuse needs /dev to be bind-mounted for the duration of
1801 # live-bottom; udev's init script will take care of things after that
1802 if [ "${UNIONTYPE}" = unionfs-fuse ]
1804 mount -n -o bind /dev "${rootmnt}/dev
"
1807 # Move to the new root filesystem so that programs there can get at it.
1808 if [ ! -d /root/live/image ]
1810 mkdir -p /root/live/image
1811 mount --move /live/image /root/live/image
1814 maybe_break live-bottom
1815 log_begin_msg "Running
/scripts
/live-bottom
\n"
1817 run_scripts /scripts/live-bottom
1820 if [ "${UNIONFS}" = unionfs-fuse ]
1822 umount "${rootmnt}/dev
"
1828 [ -w "${rootmnt}/var
/log
/" ] && cp live.log "${rootmnt}/var
/log
/" 2>/dev/null