10 if [ "${DPKG_ARCH}" = "ia64" ] || [ "${DPKG_ARCH}" = "hppa" ] || [ "${DPKG_ARCH}" = "sparc" ]; then
11 overlay_method=devmapper
15 USERFULLNAME="Ubuntu LiveCD user"
18 [ -f /etc/casper.conf ] && . /etc/casper.conf
20 export USERNAME USERFULLNAME HOST
24 if [ -e "$path/casper/filesystem.cloop" ]; then
25 echo "$path/casper/filesystem.cloop"
27 elif [ -e "$path/casper/filesystem.squashfs" ]; then
28 echo "$path/casper/filesystem.squashfs"
37 for dev in "${sysblock}" "${sysblock}"/*; do
38 if [ -e "${dev}/dev" ]; then
45 get_backing_device() {
48 echo $(setup_loop "$1" "cloop" "/sys/block/cloop*")
51 echo $(setup_loop "$1" "loop" "/sys/block/loop*")
54 panic "Unrecognized casper filesystem: $1"
62 setup_unionfs "$2" "$rootmnt"
65 setup_devmapper "$2" "$rootmnt"
71 echo "/dev/$(udevinfo -q name -p ${sysdev} 2>/dev/null|| echo ${sysdev##*/})"
79 modprobe -Qb "$module"
82 for loopdev in $pattern; do
83 if [ "$(cat $loopdev/size)" -eq 0 ]; then
84 dev=$(sys2dev "${loopdev}")
85 losetup "$dev" "$fspath"
90 panic "No loop devices available"
97 if [ "$FSTYPE" != "unknown" ]; then
101 /lib/udev/vol_id -t $1 2>/dev/null
110 COW_NAME="casper-cow"
112 BACKING_FILE_SIZE=$(blockdev --getsize "$backdev")
113 MAX_COW_SIZE=$(blockdev --getsize "$COW_DEVICE")
114 CHUNK_SIZE=8 # sectors
116 if [ -z "$COW_SIZE" -o "$COW_SIZE" -gt "$MAX_COW_SIZE" ]; then
117 COW_SIZE=$MAX_COW_SIZE
120 echo "0 $COW_SIZE linear $COW_DEVICE 0" | dmsetup create $COW_NAME
122 echo "0 $BACKING_FILE_SIZE snapshot $backdev /dev/mapper/$COW_NAME p $CHUNK_SIZE" | \
123 dmsetup create casper-snapshot
124 if [ "$(get_fstype $backdev)" = "unknown" ]; then
125 panic "Unknown file system type on $backdev"
127 mount -t $(get_fstype "$backdev") /dev/mapper/casper-snapshot $rootmnt || panic "Can not mount /dev/mapper/casper/snapshot on $rootmnt"
129 mkdir -p "$rootmnt/rofs"
130 echo "0 $BACKING_FILE_SIZE linear $backdev 0" | dmsetup create casper-backing
131 mount -t $(get_fstype "$backdev") /dev/mapper/casper-backing "$rootmnt/rofs"
136 if grep -q "^$device " /proc/mounts; then
137 grep "^$device " /proc/mounts | read d mountpoint rest
145 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -v loop); do
146 for dev in $(subdevices "${sysblock}"); do
147 devname=$(sys2dev "${dev}")
148 if [ "$(/lib/udev/vol_id -l $devname 2>/dev/null)" = "casper-rw" ]; then
151 elif [ "$(get_fstype ${devname})" = "vfat" ]; then
152 mkdir -p /cow-backing
153 if where_is_mounted ${devname} > /dev/null; then
154 mount -o remount,rw ${devname} $(where_is_mounted ${devname}) || panic "Remounting failed"
155 mount -o bind $(where_is_mounted ${devname}) /cow-backing || panic "Cannot bind-mount"
157 mount -t $(get_fstype "${devname}") -o rw "${devname}" /cow-backing || panic "Cannot mount $devname on /cow-backing"
160 if [ -e "/cow-backing/casper-rw" ]; then
161 echo $(setup_loop "/cow-backing/casper-rw" "loop" "/sys/block/loop*")
179 if grep -q persistent /proc/cmdline; then
181 # We love udev and the kernel!
182 while [ "$i" -lt 300 ]; do
183 cowdevice=$(find_cow_device)
184 if [ -b "$cowdevice" ]; then
185 mount -t $(get_fstype "$cowdevice") -o rw "$cowdevice" /cow || panic "Can not mount $cowdevice on /cow"
193 mount -t tmpfs tmpfs /cow
197 if [ "$(get_fstype $backdev)" = "unknown" ]; then
198 panic "Unknown file system type on $backdev"
200 mount -t $(get_fstype "$backdev") -o ro "$backdev" /rofs || panic "Can not mount $backdev on /rofs"
202 mount -t unionfs -o dirs=/cow=rw:/rofs=ro unionfs "$rootmnt"
203 if grep -q show-cow /proc/cmdline; then
204 mkdir -p "$rootmnt/cow"
205 mount -o bind /cow "$rootmnt/cow"
207 mkdir -p "$rootmnt/rofs"
208 mount -o bind /rofs "$rootmnt/rofs"
212 sysfs_path="${1#/sys}"
213 if /lib/udev/path_id "${sysfs_path}" | grep -q "ID_PATH=usb"; then
221 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -v loop | grep -v ram); do
222 devname=$(sys2dev "${sysblock}")
223 fstype=$(get_fstype "${devname}")
224 if /lib/udev/cdrom_id ${devname} > /dev/null; then
225 mount -t ${fstype} -o ro "$devname" $mountpoint || continue
226 if casper_path $mountpoint; then
227 echo $(casper_path $mountpoint)
232 elif is_usb_device "$sysblock"; then
233 for dev in $(subdevices "${sysblock}"); do
234 devname=$(sys2dev "${dev}")
235 fstype=$(get_fstype "${devname}")
238 mount -t ${fstype} -o ro "${devname}" $mountpoint || continue
239 if casper_path $mountpoint; then
240 echo $(casper_path $mountpoint)
248 elif [ "${fstype}" = "squashfs" ]; then
250 # This is an ugly hack situation, the block device has
251 # a squashfs image directly on it. It's hopefully
252 # casper, so take it and run with it.
254 ln -s "${devname}" "${devname}.${fstype}"
255 echo "${devname}.${fstype}"
261 set_usplash_timeout() {
262 if [ -x /sbin/usplash_write ]; then
263 /sbin/usplash_write "TIMEOUT 120"
274 [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/casper-premount"
275 run_scripts /scripts/casper-premount
276 [ "$quiet" != "y" ] && log_end_msg
278 # Needed here too because some things (*cough* udev *cough*)
279 # changes the timeout
283 for i in 0 1 2 3 4 5 6 7 8 9 a b c d e f 10 11 12 13; do
284 live_image=$(find_cd)
285 if [ "${live_image}" ]; then
290 if [ "$?" -gt 0 ]; then
291 panic "Unable to find a CD-ROM containing a live file system"
294 setup_cow "$overlay_method" "$(get_backing_device $live_image)" "$rootmnt"
298 maybe_break casper-bottom
299 [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/casper-bottom"
301 PATH=/root/usr/bin:/root/usr/sbin:/root/bin:/root/sbin:$PATH run_scripts /scripts/casper-bottom
302 [ "$quiet" != "y" ] && log_end_msg
306 cp casper.log "${rootmnt}/var/log/"