5 export PATH=/root/usr/bin:/root/usr/sbin:/root/bin:/root/sbin:/usr/bin:/usr/sbin:/bin:/sbin
11 #overlay_method=unionfs
12 #if [ "${DPKG_ARCH}" = "ia64" ] || [ "${DPKG_ARCH}" = "hppa" ] || [ "${DPKG_ARCH}" = "sparc" ]; then
13 # overlay_method=devmapper
17 USERFULLNAME="Live session user"
20 [ -f /etc/casper.conf ] && . /etc/casper.conf
22 export USERNAME USERFULLNAME HOST
26 if [ -d "$path/casper" ]; then
27 if [ "$(echo $path/casper/*.cloop)" != "$path/casper/*.cloop" ] ||
28 [ "$(echo $path/casper/*.squashfs)" != "$path/casper/*.squashfs" ]; then
38 for dev in "${sysblock}" "${sysblock}"/*; do
39 if [ -e "${dev}/dev" ]; then
46 get_backing_device() {
49 echo $(setup_loop "$1" "cloop" "/sys/block/cloop*")
52 echo $(setup_loop "$1" "loop" "/sys/block/loop*")
55 panic "Unrecognized casper filesystem: $1"
60 match_files_in_dir() {
61 # Does any files match pattern $1 ?
64 if [ "$(echo $pattern)" != "$pattern" ]; then
70 mount_images_in_directory() {
73 if match_files_in_dir "$directory/casper/*.cloop"; then
74 # Let's hope there's just one matching *.cloop... FIXME
75 setup_devmapper $(get_backing_device "$directory/casper/*.cloop") "$rootmnt"
76 elif match_files_in_dir "$directory/casper/*.squashfs"; then
77 setup_unionfs "$directory/casper" "$rootmnt"
85 echo "/dev/$(udevinfo -q name -p ${sysdev} 2>/dev/null|| echo ${sysdev##*/})"
93 modprobe -Qb "$module"
96 for loopdev in $pattern; do
97 if [ "$(cat $loopdev/size)" -eq 0 ]; then
98 dev=$(sys2dev "${loopdev}")
99 losetup "$dev" "$fspath"
104 panic "No loop devices available"
111 if [ "$FSTYPE" != "unknown" ]; then
115 /lib/udev/vol_id -t $1 2>/dev/null
124 COW_NAME="casper-cow"
126 BACKING_FILE_SIZE=$(blockdev --getsize "$backdev")
127 MAX_COW_SIZE=$(blockdev --getsize "$COW_DEVICE")
128 CHUNK_SIZE=8 # sectors
130 if [ -z "$COW_SIZE" -o "$COW_SIZE" -gt "$MAX_COW_SIZE" ]; then
131 COW_SIZE=$MAX_COW_SIZE
134 echo "0 $COW_SIZE linear $COW_DEVICE 0" | dmsetup create $COW_NAME
136 echo "0 $BACKING_FILE_SIZE snapshot $backdev /dev/mapper/$COW_NAME p $CHUNK_SIZE" | \
137 dmsetup create casper-snapshot
138 if [ "$(get_fstype $backdev)" = "unknown" ]; then
139 panic "Unknown file system type on $backdev"
141 mount -t $(get_fstype "$backdev") /dev/mapper/casper-snapshot $rootmnt || panic "Can not mount /dev/mapper/casper/snapshot on $rootmnt"
143 mkdir -p "$rootmnt/rofs"
144 echo "0 $BACKING_FILE_SIZE linear $backdev 0" | dmsetup create casper-backing
145 mount -t $(get_fstype "$backdev") /dev/mapper/casper-backing "$rootmnt/rofs"
150 if grep -q "^$device " /proc/mounts; then
151 grep "^$device " /proc/mounts | read d mountpoint rest
159 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -v loop); do
160 for dev in $(subdevices "${sysblock}"); do
161 devname=$(sys2dev "${dev}")
162 if [ "$(/lib/udev/vol_id -l $devname 2>/dev/null)" = "casper-rw" ]; then
165 elif [ "$(get_fstype ${devname})" = "vfat" ]; then
166 mkdir -p /cow-backing
167 if where_is_mounted ${devname} > /dev/null; then
168 mount -o remount,rw ${devname} $(where_is_mounted ${devname}) || panic "Remounting failed"
169 mount -o bind $(where_is_mounted ${devname}) /cow-backing || panic "Cannot bind-mount"
171 mount -t $(get_fstype "${devname}") -o rw "${devname}" /cow-backing || panic "Cannot mount $devname on /cow-backing"
174 if [ -e "/cow-backing/casper-rw" ]; then
175 echo $(setup_loop "/cow-backing/casper-rw" "loop" "/sys/block/loop*")
192 # run-init can't deal with images in a subdir, but we're going to
193 # move all of these away before it runs anyway. No, we're not,
194 # put them in / since move-mounting them into / breaks mono and
199 # Let's just mount the read-only file systems first
201 for image in "${image_directory}"/*.squashfs; do
202 imagename=$(basename "${image}")
203 backdev=$(get_backing_device "$image")
204 fstype=$(get_fstype "${backdev}")
205 if [ "${fstype}" = "unknown" ]; then
206 panic "Unknown file system type on ${backdev} (${image})"
208 mkdir -p "${croot}/${imagename}"
209 mount -t "${fstype}" -o ro "${backdev}" "${croot}/${imagename}" || panic "Can not mount $backdev ($image) on ${croot}/${imagename}"
213 for dir in $(mount -t squashfs | cut -d\ -f 3); do
214 rofsstring="$dir=ro:$rofsstring"
216 rofsstring=${rofsstring%:}
220 if grep -q persistent /proc/cmdline; then
222 # We love udev and the kernel!
223 while [ "$i" -lt 300 ]; do
224 cowdevice=$(find_cow_device)
225 if [ -b "$cowdevice" ]; then
226 mount -t $(get_fstype "$cowdevice") -o rw "$cowdevice" /cow || panic "Can not mount $cowdevice on /cow"
233 mount -t tmpfs tmpfs /cow
236 mount -t unionfs -o dirs=/cow=rw:$rofsstring unionfs "$rootmnt"
238 # move the first mount; no head in busybox-initramfs
239 for d in $(mount -t squashfs | cut -d\ -f 3); do
240 mkdir -p "${rootmnt}/rofs"
241 mount -o move "${d}" "${rootmnt}/rofs"
245 if grep -q showmounts /proc/cmdline; then
246 for d in $(mount -t squashfs | cut -d\ -f 3); do
247 mkdir -p "${rootmnt}/casper/${d##*/}"
248 mount -o move "${d}" "${rootmnt}/casper/${d##*/}"
251 mkdir -p "$rootmnt/cow"
252 mount -o bind /cow "$rootmnt/cow"
258 sysfs_path="${1#/sys}"
259 if /lib/udev/path_id "${sysfs_path}" | grep -E -q "ID_PATH=(usb|pci-[^-]*-usb)"; then
267 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -v loop | grep -v ram); do
268 devname=$(sys2dev "${sysblock}")
269 fstype=$(get_fstype "${devname}")
270 if /lib/udev/cdrom_id ${devname} > /dev/null; then
271 mount -t ${fstype} -o ro "$devname" $mountpoint || continue
272 if is_casper_path $mountpoint; then
278 elif is_usb_device "$sysblock"; then
279 for dev in $(subdevices "${sysblock}"); do
280 devname=$(sys2dev "${dev}")
281 fstype=$(get_fstype "${devname}")
284 mount -t ${fstype} -o ro "${devname}" $mountpoint || continue
285 if is_casper_path $mountpoint; then
294 elif [ "${fstype}" = "squashfs" ]; then
296 # This is an ugly hack situation, the block device has
297 # a squashfs image directly on it. It's hopefully
298 # casper, so take it and run with it.
300 ln -s "${devname}" "${devname}.${fstype}"
301 echo "${devname}.${fstype}"
308 if [ -x /sbin/usplash_write ]; then
309 /sbin/usplash_write "PULSATE"
313 set_usplash_timeout() {
314 if [ -x /sbin/usplash_write ]; then
315 /sbin/usplash_write "TIMEOUT 120"
326 [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/casper-premount"
328 run_scripts /scripts/casper-premount
329 [ "$quiet" != "y" ] && log_end_msg
331 # Needed here too because some things (*cough* udev *cough*)
332 # changes the timeout
336 for i in 0 1 2 3 4 5 6 7 8 9 a b c d e f 10 11 12 13; do
337 livefs_root=$(find_livefs)
338 if [ "${livefs_root}" ]; then
343 if [ "$?" -gt 0 ]; then
344 panic "Unable to find a medium containing a live file system"
347 mount_images_in_directory "$livefs_root" "$rootmnt"
350 maybe_break casper-bottom
351 [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/casper-bottom"
354 run_scripts /scripts/casper-bottom
355 [ "$quiet" != "y" ] && log_end_msg
359 cp casper.log "${rootmnt}/var/log/"