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
13 USERFULLNAME="Live session user"
19 [ -f /etc/casper.conf ] && . /etc/casper.conf
20 export USERNAME USERFULLNAME HOST BUILD_SYSTEM
22 . /scripts/casper-helpers
24 if [ ! -f /casper.vars ]; then
30 if [ -d "$path/casper" ]; then
31 if [ "$(echo $path/casper/*.squashfs)" != "$path/casper/*.squashfs" ] ||
32 [ "$(echo $path/casper/*.ext2)" != "$path/casper/*.ext2" ] ||
33 [ "$(echo $path/casper/*.dir)" != "$path/casper/*.dir" ]; then
40 get_backing_device() {
43 echo $(setup_loop "$1" "loop" "/sys/block/loop*")
49 panic "Unrecognized casper filesystem: $1"
54 match_files_in_dir() {
55 # Does any files match pattern $1 ?
58 if [ "$(echo $pattern)" != "$pattern" ]; then
64 mount_images_in_directory() {
67 if match_files_in_dir "$directory/casper/*.squashfs" ||
68 match_files_in_dir "$directory/casper/*.ext2" ||
69 match_files_in_dir "$directory/casper/*.dir"; then
70 setup_unionfs "$directory/casper" "$rootmnt"
77 sysfs_path="${1#/sys}"
78 if /lib/udev/path_id "${sysfs_path}" | grep -E -q "ID_PATH=(usb|pci-[^-]*-[ide|scsi|usb])"; then
85 # FIXME: do something better like the scan of supported filesystems
88 vfat|iso9660|udf|ext2|ext3|ntfs)
98 copyto="${copyfrom}_swap"
100 size=$(fs_size "" ${copyfrom} "used")
102 if [ "${copytodev}" = "ram" ]; then
104 freespace=$( expr $(awk '/MemFree/{print $2}' /proc/meminfo) + $( cat /proc/meminfo | grep Cached | head -n 1 | awk '/Cached/{print $2}' - ) )
105 mount_options="-o size=${size}k"
110 # it should be a writable block device
111 if [ -b "${copytodev}" ]; then
114 fstype=$(get_fstype "${dev}")
115 freespace=$(fs_size "${dev}")
117 [ "$quiet" != "y" ] && log_warning_msg "${copytodev} is not a block device."
121 if [ "${freespace}" -lt "${size}" ] ; then
122 [ "$quiet" != "y" ] && log_warning_msg "Not enough free ${free_string} (${freespace}k > ${size}k) to copy live media in ${copytodev}."
128 echo "mount -t ${fstype} ${mount_options} ${dev} ${copyto}"
129 mount -t "${fstype}" ${mount_options} "${dev}" "${copyto}"
130 cp -a ${copyfrom}/* ${copyto} # "cp -a" from busybox also copies hidden files
132 mount -r -o move ${copyto} ${copyfrom}
140 modprobe "${MP_QUIET}" af_packet # For DHCP
145 ipconfig ${DEVICE} /tmp/net-${DEVICE}.conf | tee /netboot.config
147 if [ "${NFSROOT}" = "auto" ]; then
148 NFSROOT=${ROOTSERVER}:${ROOTPATH}
151 [ "$quiet" != "y" ] && log_begin_msg "Trying netboot from ${NFSROOT}"
153 if [ "${NETBOOT}" != "nfs" ] && do_cifsmount ; then
155 elif do_nfsmount ; then
161 [ "$quiet" != "y" ] && log_end_msg
167 modprobe "${MP_QUIET}" nfs
168 if [ -z "${NFSOPTS}" ]; then
172 [ "$quiet" != "y" ] && log_begin_msg "Trying nfsmount -o nolock -o ro ${NFSOPTS} ${NFSROOT} ${mountpoint}"
173 # FIXME: This for loop is an ugly HACK round an nfs bug
174 for i in 0 1 2 3 4 5 6 7 8 9 a b c d e f 10 11 12 13; do
175 nfsmount -o nolock -o ro ${NFSOPTS} "${NFSROOT}" "${mountpoint}" && rc=0 && break
183 if [ -x "/sbin/mount.cifs" ]; then
184 if [ -z "${NFSOPTS}" ]; then
185 CIFSOPTS="-ouser=root,password="
187 CIFSOPTS="${NFSOPTS}"
190 [ "$quiet" != "y" ] && log_begin_msg "Trying mount.cifs ${NFSROOT} ${mountpoint} ${CIFSOPTS}"
191 modprobe "${MP_QUIET}" cifs
193 if mount.cifs "${NFSROOT}" "${mountpoint}" "${CIFSOPTS}" ; then
206 size=$(fs_size "${fromdev}" "" "used")
208 if [ -b "${fromdev}" ]; then
210 if [ -n "${HOMEMOUNTED}" -a "${snap_type}" = "HOME" ]; then
211 todev=$(cat /proc/mounts | grep -s " $(base_path ${todir}) " | awk '{print $1}' )
212 freespace=$(df -k | grep -s ${todev} | awk '{print $4}')
214 freespace=$( expr $(awk '/MemFree/{print $2}' /proc/meminfo) + $( cat /proc/meminfo | grep Cached | head -n 1 | awk '/Cached/{print $2}' - ))
217 tomount="/mnt/tmpsnap"
218 if [ ! -d "${tomount}" ] ; then
219 mkdir -p "${tomount}"
222 fstype=$(get_fstype "${fromdev}")
223 if [ -n "${fstype}" ]; then
225 mount -t "${fstype}" -o ro "${fromdev}" "${tomount}"
226 cp -a "${tomount}"/* ${todir}
229 log_warning_msg "Unrecognized fstype: ${fstype} on ${fromdev}:${snap_type}"
233 if echo ${fromdev} | grep -qs loop; then
234 losetup -d "${fromdev}"
239 [ "$quiet" != "y" ] && log_warning_msg "Unable to find the snapshot ${snap_type} medium"
245 # Look for $snap_label.* in block devices and copy the contents to $snap_mount
246 # and remember the device and filename for resync on exit in casper.init
252 snapdata=$(find_files "${snap_label}.squashfs ${snap_label}.cpio.gz ${snap_label}.ext2")
253 if [ ! -z "${snapdata}" ]; then
254 snapdev="$(echo ${snapdata} | cut -f1 -d ' ')"
255 snapback="$(echo ${snapdata} | cut -f2 -d ' ')"
256 snapfile="$(echo ${snapdata} | cut -f3 -d ' ')"
257 if echo "${snapfile}" | grep -qs '\(squashfs\|ext2\)'; then
258 # squashfs or ext2 snapshot
259 dev=$(get_backing_device "${snapback}/${snapfile}")
260 if ! do_snap_copy "${dev}" "${snap_mount}" "${snap_type}"; then
261 log_warning_msg "Impossible to include the ${snapfile} Snapshot"
266 if ! (cd "${snap_mount}" && zcat "${snapback}/${snapfile}" | cpio -i -u -d 2>/dev/null) ; then
267 log_warning_msg "Impossible to include the ${snapfile} Snapshot"
273 dev=$(find_cow_device "${snap_label}")
274 if [ -b ${dev} ]; then
275 if echo "${dev}" | grep -qs loop; then
276 # strange things happens, user confused?
277 snaploop=$( losetup ${dev} | awk '{print $3}' | tr -d '()' )
278 snapfile=$(basename ${snaploop})
279 snapdev=$(cat /proc/mounts | awk '{print $2,$1}' | grep -es "^$( dirname ${snaploop} )" | cut -f2 -d ' ')
283 if ! do_snap_copy "${dev}" "${snap_mount}" "${snap_type}" ; then
284 log_warning_msg "Impossible to include the ${snap_label} Snapshot"
287 if [ -n "${snapfile}" ]; then
288 # it was a loop device, user confused
293 log_warning_msg "Impossible to include the ${snap_label} Snapshot"
297 echo "export ${snap_type}SNAP="${snap_mount}":${snapdev}:${snapfile}" >> /etc/casper.conf # for resync on reboot/halt
305 modprobe "${MP_QUIET}" -b unionfs
307 # run-init can't deal with images in a subdir, but we're going to
308 # move all of these away before it runs anyway. No, we're not,
309 # put them in / since move-mounting them into / breaks mono and
314 # Let's just mount the read-only file systems first
317 if [ "${NETBOOT}" = "nfs" ] ; then
318 roopt="nfsro" # go aroung a bug in nfs-unionfs locking
324 for image_type in "ext2" "squashfs" "dir" ; do
325 for image in "${image_directory}"/*."${image_type}"; do
326 imagename=$(basename "${image}")
327 if [ -d "${image}" ]; then
328 # it is a plain directory: do nothing
329 rofsstring="${image}=${roopt}:${rofsstring}"
330 rofslist="${image} ${rofslist}"
331 elif [ -f "${image}" ]; then
332 backdev=$(get_backing_device "$image")
333 fstype=$(get_fstype "${backdev}")
334 if [ "${fstype}" = "unknown" ]; then
335 panic "Unknown file system type on ${backdev} (${image})"
337 mkdir -p "${croot}/${imagename}"
338 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}"
342 rofsstring=${rofsstring%:}
348 # Looking for "${root_persistence}" device or file
349 if [ -n "${PERSISTENT}" ]; then
350 cowprobe=$(find_cow_device "${root_persistence}")
351 if [ -b "${cowprobe}" ]; then
352 cowdevice=${cowprobe}
353 cow_fstype=$(get_fstype "${cowprobe}")
355 [ "$quiet" != "y" ] && log_warning_msg "Unable to find the persistent medium"
359 mount ${cowdevice} -t ${cow_fstype} -o rw /cow || panic "Can not mount $cowdevice on /cow"
361 mount -t unionfs -o dirs=/cow=rw:$rofsstring unionfs "$rootmnt" || panic "Unionfs mount failed"
363 # Adding other custom mounts
364 if [ -n "${PERSISTENT}" ]; then
365 # directly mount /home
366 # FIXME: add a custom mounts configurable system
367 homecow=$(find_cow_device "${home_persistence}" )
368 if [ -b "${homecow}" ]; then
369 mount -t $(get_fstype "${homecow}") -o rw "${homecow}" "${rootmnt}/home"
370 export HOMEMOUNTED=1 # used to proper calculate free space in do_snap_copy()
372 [ "$quiet" != "y" ] && log_warning_msg "Unable to find the persistent home medium"
374 # Look for other snapshots to copy in
375 try_snap "${root_snapshot_label}" "${rootmnt}" "ROOT"
376 try_snap "${home_snapshot_label}" "${rootmnt}/home" "HOME"
379 if [ -n "${SHOWMOUNTS}" ]; then
380 for d in ${rofslist}; do
381 mkdir -p "${rootmnt}/casper/${d##*/}"
383 *.dir) # do nothing # mount -o bind "${d}" "${rootmnt}/casper/${d##*/}"
385 *) mount -o move "${d}" "${rootmnt}/casper/${d##*/}"
389 # shows cow fs on /cow for use by casper-snapshot
390 mkdir -p "${rootmnt}/cow"
391 mount -o bind /cow "${rootmnt}/cow"
394 # move the first mount; no head in busybox-initramfs
395 for d in $(mount -t squashfs | cut -d\ -f 3); do
396 mkdir -p "${rootmnt}/rofs"
397 mount -o move "${d}" "${rootmnt}/rofs"
406 if [ -z "${devname}" ]; then
407 devname=$(sys2dev "${sysdev}")
410 if [ -n "${LIVEMEDIA_OFFSET}" ]; then
411 loopdevname=$(setup_loop "${devname}" "loop" "/sys/block/loop*" "${LIVEMEDIA_OFFSET}")
412 devname="${loopdevname}"
415 fstype=$(get_fstype "${devname}")
416 if is_supported_fs ${fstype}; then
417 mount -t ${fstype} -o ro "${devname}" $mountpoint || continue
418 if is_casper_path $mountpoint; then
426 if [ -n "${LIVEMEDIA_OFFSET}" ]; then
427 losetup -d "${loopdevname}"
434 # first look at the one specified in the command line
435 if [ ! -z "${LIVEMEDIA}" ]; then
436 if check_dev "null" "${LIVEMEDIA}"; then
440 # don't start autodetection before timeout has expired
441 if [ -n "${LIVEMEDIA_TIMEOUT}" ]; then
442 if [ "${timeout}" -lt "${LIVEMEDIA_TIMEOUT}" ]; then
446 # or do the scan of block devices
447 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -v loop | grep -v ram); do
448 devname=$(sys2dev "${sysblock}")
449 fstype=$(get_fstype "${devname}")
450 if /lib/udev/cdrom_id ${devname} > /dev/null; then
451 if check_dev "null" "${devname}" ; then
454 elif is_nice_device "${sysblock}" ; then
455 for dev in $(subdevices "${sysblock}"); do
456 if check_dev "${dev}" ; then
460 elif [ "${fstype}" = "squashfs" -o \
461 "${fstype}" = "ext3" -o \
462 "${fstype}" = "ext2" ]; then
463 # This is an ugly hack situation, the block device has
464 # an image directly on it. It's hopefully
465 # casper, so take it and run with it.
466 ln -s "${devname}" "${devname}.${fstype}"
467 echo "${devname}.${fstype}"
475 if [ -x /sbin/usplash_write ]; then
476 /sbin/usplash_write "PULSATE"
480 set_usplash_timeout() {
481 if [ -x /sbin/usplash_write ]; then
482 /sbin/usplash_write "TIMEOUT 120"
493 [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/casper-premount"
495 run_scripts /scripts/casper-premount
496 [ "$quiet" != "y" ] && log_end_msg
498 # Needed here too because some things (*cough* udev *cough*)
499 # changes the timeout
503 if [ ! -z "${NETBOOT}" ]; then
504 if do_netmount ; then
505 livefs_root="${mountpoint}"
507 panic "Unable to find a live file system on the network"
510 # Scan local devices for the image
511 for i in 0 1 2 3 4 5 6 7 8 9 a b c d e f 10 11 12 13; do
512 livefs_root=$(find_livefs $i)
513 if [ "${livefs_root}" ]; then
520 if [ -z "${livefs_root}" ]; then
521 panic "Unable to find a medium containing a live file system"
524 if [ "${TORAM}" ]; then
526 elif [ "${TODISK}" ]; then
527 live_dest="${TODISK}"
529 if [ "${live_dest}" ]; then
530 log_begin_msg "Copying live_media to ${live_dest}"
531 copy_live_to "${livefs_root}" "${live_dest}"
535 mount_images_in_directory "${livefs_root}" "${rootmnt}"
539 maybe_break casper-bottom
540 [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/casper-bottom"
543 run_scripts /scripts/casper-bottom
544 [ "$quiet" != "y" ] && log_end_msg
548 cp casper.log "${rootmnt}/var/log/"