6 root_persistence="casper-rw"
7 home_persistence="home-rw"
11 overlay_method=unionfs
12 if [ "${DPKG_ARCH}" = "ia64" ] || [ "${DPKG_ARCH}" = "hppa" ] || [ "${DPKG_ARCH}" = "sparc" ]; then
13 overlay_method=devmapper
17 USERFULLNAME="Debian Live user"
20 [ -f /etc/casper.conf ] && . /etc/casper.conf
22 export USERNAME USERFULLNAME HOST
24 casper_path() { # Fixme: uglyness
26 if [ -e "$path/casper/filesystem.cloop" ]; then
27 echo "$path/casper/filesystem.cloop"
29 elif [ -e "$path/casper/filesystem.squashfs" ]; then
30 echo "$path/casper/filesystem.squashfs"
32 elif [ -e "$path/casper/filesystem.ext2" ]; then
33 echo "$path/casper/filesystem.ext2"
35 elif [ -e "$path/casper/filesystem.xfs" ]; then
36 echo "$path/casper/filesystem.xfs"
45 for dev in "${sysblock}" "${sysblock}"/*; do
46 if [ -e "${dev}/dev" ]; then
53 get_backing_device() {
56 echo $(setup_loop "$1" "cloop" "/sys/block/cloop*")
58 *.squashfs|*.ext2|*.xfs)
59 echo $(setup_loop "$1" "loop" "/sys/block/loop*")
62 panic "Unrecognized casper filesystem: $1"
70 setup_unionfs "$2" "$rootmnt"
73 setup_devmapper "$2" "$rootmnt"
79 echo "/dev/$(udevinfo -q name -p ${sysdev} 2>/dev/null|| echo ${sysdev##*/})"
87 modprobe -qb "$module"
88 if [ -x /sbin/udevplug ]; then
94 for loopdev in $pattern; do
95 if [ "$(cat $loopdev/size)" -eq 0 ]; then
96 dev=$(sys2dev "${loopdev}")
97 losetup "$dev" "$fspath"
102 panic "No loop devices available"
109 if [ "$FSTYPE" != "unknown" ]; then
113 /lib/udev/vol_id -t $1 2>/dev/null
122 COW_NAME="casper-cow"
124 BACKING_FILE_SIZE=$(blockdev --getsize "$backdev")
125 MAX_COW_SIZE=$(blockdev --getsize "$COW_DEVICE")
126 CHUNK_SIZE=8 # sectors
128 if [ -z "$COW_SIZE" -o "$COW_SIZE" -gt "$MAX_COW_SIZE" ]; then
129 COW_SIZE=$MAX_COW_SIZE
132 echo "0 $COW_SIZE linear $COW_DEVICE 0" | dmsetup create $COW_NAME
134 echo "0 $BACKING_FILE_SIZE snapshot $backdev /dev/mapper/$COW_NAME p $CHUNK_SIZE" | \
135 dmsetup create casper-snapshot
136 if [ "$(get_fstype $backdev)" = "unknown" ]; then
137 panic "Unknown file system type on $backdev"
139 mount -t $(get_fstype "$backdev") /dev/mapper/casper-snapshot $rootmnt || panic "Can not mount /dev/mapper/casper/snapshot on $rootmnt"
141 mkdir -p "$rootmnt/rofs"
142 echo "0 $BACKING_FILE_SIZE linear $backdev 0" | dmsetup create casper-backing
143 mount -t $(get_fstype "$backdev") /dev/mapper/casper-backing "$rootmnt/rofs"
148 if grep -q "^$device " /proc/mounts; then
149 grep "^$device " /proc/mounts | read d mountpoint rest
157 copyto="${mountpoint}_swap"
159 size=$(du -ks ${mountpoint} | cut -f1)
160 size=$(expr ${size} + ${size}/20 ) # Fixme: 5% more to be sure
161 needed_space=$(expr ${size} * 1024)
162 freespace=$( expr $(awk '/MemFree/{print $2}' /proc/meminfo) + $( cat /proc/meminfo | grep Cached | head -n 1 | awk '/Cached/{print $2}' - ))
164 if [ ! ${freespace} -lt ${needed_space} ] ; then
165 [ "$quiet" != "y" ] && log_begin_msg "Not enough free memory to copy to ram"
166 [ "$quiet" != "y" ] && log_end_msg
169 [ "$quiet" != "y" ] && log_begin_msg "Copying live media to ram..."
171 mount -t tmpfs -o size=${size}k /dev/shm ${copyto}
172 cp -a ${mountpoint}/* ${copyto}
174 mount -r -o move ${copyto} ${mountpoint}
176 [ "$quiet" != "y" ] && log_end_msg
182 cow_backing="/${pers_label}-backing"
183 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -v loop); do
184 for dev in $(subdevices "${sysblock}"); do
185 devname=$(sys2dev "${dev}")
186 if [ "$(/lib/udev/vol_id -l $devname 2>/dev/null)" = "${pers_label}" ]; then
189 elif [ "$(get_fstype ${devname})" = "vfat" ]; then
190 mkdir -p "${cow_backing}"
191 if where_is_mounted ${devname} > /dev/null; then
192 mount -o remount,rw ${devname} $(where_is_mounted ${devname}) || panic "Remounting failed"
193 mount -o bind $(where_is_mounted ${devname}) ${cow_backing} || panic "Cannot bind-mount"
195 mount -t $(get_fstype "${devname}") -o rw "${devname}" ${cow_backing} || panic "Cannot mount $devname on /cow-backing"
198 if [ -e "${cow_backing}/${pers_label}" ]; then
199 echo $(setup_loop "${cow_backing}/${pers_label}" "loop" "/sys/block/loop*")
202 umount ${cow_backing}
211 # adapted from NFS filesystem mounting
215 modprobe -q af_packet
217 ipconfig ${DEVICE} /tmp/net-${DEVICE}.conf
218 if [ "x${NFSROOT}" = "xauto" ]; then
219 NFSROOT=${ROOTSERVER}:${ROOTPATH}
222 NFSOPTS="-ouser=root,password="
224 [ "$quiet" != "y" ] && log_begin_msg "Mounting using mount.cifs with ${NFSROOT} ${rofsmnt} ${NFSOPTS}"
225 mount.cifs "${NFSROOT}" "${rofsmnt}" "${NFSOPTS}"
226 [ "$quiet" != "y" ] && log_end_msg
236 # Looking for "${root_persistence}" device or file
237 if grep -q persistent /proc/cmdline; then
238 cowprobe=$(find_cow_device "${root_persistence}")
239 if [ -b "${cowprobe}" ]; then
240 cowdevice=${cowprobe}
241 cow_fstype=$(get_fstype "${cowprobe}")
243 [ "$quiet" != "y" ] && log_begin_msg "Unable to find the persistent medium"
247 mount ${cowdevice} -t ${cow_fstype} -o rw /cow || panic "Can not mount $cowdevice on /cow"
250 if grep -q netboot /proc/cmdline; then
251 do_netmount /rofs || panic "Can not mount netroot on /rofs"
253 if [ "$(get_fstype $backdev)" = "unknown" ]; then
254 panic "Unknown file system type on $backdev"
256 mount -t $(get_fstype "$backdev") -o ro "$backdev" /rofs || panic "Can not mount $backdev on /rofs"
259 mount -t unionfs -o dirs=/cow=rw:/rofs=ro unionfs "$rootmnt"
260 if grep -q show-cow /proc/cmdline; then
261 mkdir -p "$rootmnt/cow"
262 mount -o bind /cow "$rootmnt/cow"
264 mkdir -p "$rootmnt/rofs"
265 mount -o bind /rofs "$rootmnt/rofs"
267 # Adding home persitence
268 if grep -q homepersistence /proc/cmdline; then
269 homecow=$(find_cow_device "${home_persistence}" )
270 if [ -b "${homecow}" ]; then
271 mount ${homecow} -t $(get_fstype "${homecow}") -o rw "${rootmnt}/home"
273 [ "$quiet" != "y" ] && log_begin_msg "Unable to find the persistent home medium"
279 sysfs_path="${1#/sys}"
280 if /lib/udev/path_id "${sysfs_path}" | grep -q "ID_PATH=usb"; then
288 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -v loop | grep -v ram); do
289 devname=$(sys2dev "${sysblock}")
290 fstype=$(get_fstype "${devname}")
291 if /lib/udev/cdrom_id ${devname} > /dev/null; then
292 mount -t ${fstype} -o ro "$devname" $mountpoint || continue
293 if casper_path $mountpoint; then
294 echo $(casper_path $mountpoint)
299 elif is_usb_device "$sysblock"; then
300 for dev in $(subdevices "${sysblock}"); do
301 devname=$(sys2dev "${dev}")
302 fstype=$(get_fstype "${devname}")
305 mount -t ${fstype} -o ro "${devname}" $mountpoint || continue
306 if casper_path $mountpoint; then
307 echo $(casper_path $mountpoint)
315 elif [ "${fstype}" = "squashfs" ]; then
317 # This is an ugly hack situation, the block device has
318 # a squashfs image directly on it. It's hopefully
319 # casper, so take it and run with it.
321 ln -s "${devname}" "${devname}.${fstype}"
322 echo "${devname}.${fstype}"
328 set_usplash_timeout() {
329 if [ -x /sbin/usplash_write ]; then
330 /sbin/usplash_write "TIMEOUT 120"
341 [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/casper-premount"
342 run_scripts /scripts/casper-premount
343 [ "$quiet" != "y" ] && log_end_msg
345 # Needed here too because some things (*cough* udev *cough*)
346 # changes the timeout
350 for i in 0 1 2 3 4 5 6 7 8 9 a b c d e f 10 11 12 13; do
351 live_image=$(find_live)
352 if [ "${live_image}" ]; then
357 if [ "$?" -gt 0 ]; then
358 panic "Unable to find a medium containing a live file system"
361 if grep -q toram /proc/cmdline; then
365 setup_cow "$overlay_method" "$(get_backing_device $live_image)" "$rootmnt"
367 # show it on new rootfs
368 mkdir ${rootmnt}/${mountpoint}
369 mount -o bind ${mountpoint} ${rootmnt}/${mountpoint}
373 maybe_break casper-bottom
374 [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/casper-bottom"
376 PATH=/root/usr/bin:/root/usr/sbin:/root/bin:/root/sbin:$PATH run_scripts /scripts/casper-bottom
377 [ "$quiet" != "y" ] && log_end_msg
381 cp casper.log "${rootmnt}/var/log/"