#!/bin/sh # TODO: use installer fast-path w/ T2 label mkdir -p /mnt mount -t tmpfs none /mnt mkdir -p /mnt/{media,mnt,overlay,work} live="live=live.squash `cat /proc/cmdline`"; live=${live##*live=}; live=${live%% *} echo "Searching for media with $live image ..." i=0 while [ $i -le 14 ]; do for x in /sys/block/*/device; do x=${x%/device}; x=${x#/sys/block/} [ "$x" = "*" ] && continue # TODO: make option to skip fixed devices #case "`ls -l /sys/block/$x/device`" in # */usb*|*/ieee1394) : ;; # *) [ "`cat /sys/block/$x/removable`" = 1 ] || continue ;; #esac x=/dev/$x for x in ${x}*; do [ -e $x ] || continue fs=`disktype $x 2>/dev/null | sed -e '/file system/!d' -e 's/file system.*//' -e 's/ //g' \ -e 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/' \ -e 's/fat.*/vfat/' | sed -n '1p'` # TODO: for fs in `| sed '1!G; $p; h; d` [ $i -gt 2 ] && echo "Testing device $x, type $fs ..." if mount -t $fs -o ro $x /mnt/media 2>/dev/null; then [ $i -gt 0 ] && echo "Successfully mounted $x" if [ -f /mnt/media/$live ]; then echo "Found the $live image on $x" if losetup /dev/loop0 /mnt/media/$live && mount -t squashfs -o ro /dev/loop0 /mnt/mnt then kill %1 # udevd # pre-load overlay module, before moving it modprobe overlay 2> /dev/null # re-use kernel modules and firmware mkdir -p /mnt/overlay/lib mv /lib/{firmware,modules} /mnt/overlay/lib mount -t overlay -o lowerdir=/mnt/mnt,upperdir=/mnt/overlay,workdir=/mnt/work \ none /mnt init=${init:-/sbin/init} boot $init "$@" else echo "Failed to loop-mount $live." losetup -d /dev/loop0 fi else echo "No $live image found." fi umount /media/live fi done done : $(( i++ )) sleep 1 done echo "No live media found, giving up. Debug shell:" exec /bin/sh