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="Ubuntu LiveCD user"
20 [ -f /etc/casper.conf ] && . /etc/casper.conf
22 export USERNAME USERFULLNAME HOST
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"
39 for dev in "${sysblock}" "${sysblock}"/*; do
40 if [ -e "${dev}/dev" ]; then
47 get_backing_device() {
50 echo $(setup_loop "$1" "cloop" "/sys/block/cloop*")
53 echo $(setup_loop "$1" "loop" "/sys/block/loop*")
56 panic "Unrecognized casper filesystem: $1"
64 setup_unionfs "$2" "$rootmnt"
67 setup_devmapper "$2" "$rootmnt"
73 echo "/dev/$(udevinfo -q name -p ${sysdev} 2>/dev/null|| echo ${sysdev##*/})"
81 modprobe -Qb "$module"
84 for loopdev in $pattern; do
85 if [ "$(cat $loopdev/size)" -eq 0 ]; then
86 dev=$(sys2dev "${loopdev}")
87 losetup "$dev" "$fspath"
92 panic "No loop devices available"
99 if [ "$FSTYPE" != "unknown" ]; then
103 /lib/udev/vol_id -t $1 2>/dev/null
112 COW_NAME="casper-cow"
114 BACKING_FILE_SIZE=$(blockdev --getsize "$backdev")
115 MAX_COW_SIZE=$(blockdev --getsize "$COW_DEVICE")
116 CHUNK_SIZE=8 # sectors
118 if [ -z "$COW_SIZE" -o "$COW_SIZE" -gt "$MAX_COW_SIZE" ]; then
119 COW_SIZE=$MAX_COW_SIZE
122 echo "0 $COW_SIZE linear $COW_DEVICE 0" | dmsetup create $COW_NAME
124 echo "0 $BACKING_FILE_SIZE snapshot $backdev /dev/mapper/$COW_NAME p $CHUNK_SIZE" | \
125 dmsetup create casper-snapshot
126 if [ "$(get_fstype $backdev)" = "unknown" ]; then
127 panic "Unknown file system type on $backdev"
129 mount -t $(get_fstype "$backdev") /dev/mapper/casper-snapshot $rootmnt || panic "Can not mount /dev/mapper/casper/snapshot on $rootmnt"
131 mkdir -p "$rootmnt/rofs"
132 echo "0 $BACKING_FILE_SIZE linear $backdev 0" | dmsetup create casper-backing
133 mount -t $(get_fstype "$backdev") /dev/mapper/casper-backing "$rootmnt/rofs"
138 if grep -q "^$device " /proc/mounts; then
139 grep "^$device " /proc/mounts | read d mountpoint rest
147 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -v loop); do
148 for dev in $(subdevices "${sysblock}"); do
149 devname=$(sys2dev "${dev}")
150 if [ "$(/lib/udev/vol_id -l $devname 2>/dev/null)" = "casper-rw" ]; then
153 elif [ "$(get_fstype ${devname})" = "vfat" ]; then
154 mkdir -p /cow-backing
155 if where_is_mounted ${devname} > /dev/null; then
156 mount -o remount,rw ${devname} $(where_is_mounted ${devname}) || panic "Remounting failed"
157 mount -o bind $(where_is_mounted ${devname}) /cow-backing || panic "Cannot bind-mount"
159 mount -t $(get_fstype "${devname}") -o rw "${devname}" /cow-backing || panic "Cannot mount $devname on /cow-backing"
162 if [ -e "/cow-backing/casper-rw" ]; then
163 echo $(setup_loop "/cow-backing/casper-rw" "loop" "/sys/block/loop*")
181 if grep -q persistent /proc/cmdline; then
183 # We love udev and the kernel!
184 while [ "$i" -lt 300 ]; do
185 cowdevice=$(find_cow_device)
186 if [ -b "$cowdevice" ]; then
187 mount -t $(get_fstype "$cowdevice") -o rw "$cowdevice" /cow || panic "Can not mount $cowdevice on /cow"
195 mount -t tmpfs tmpfs /cow
199 if [ "$(get_fstype $backdev)" = "unknown" ]; then
200 panic "Unknown file system type on $backdev"
202 mount -t $(get_fstype "$backdev") -o ro "$backdev" /rofs || panic "Can not mount $backdev on /rofs"
204 mount -t unionfs -o dirs=/cow=rw:/rofs=ro unionfs "$rootmnt"
205 if grep -q show-cow /proc/cmdline; then
206 mkdir -p "$rootmnt/cow"
207 mount -o bind /cow "$rootmnt/cow"
209 mkdir -p "$rootmnt/rofs"
210 mount -o bind /rofs "$rootmnt/rofs"
214 sysfs_path="${1#/sys}"
215 if /lib/udev/path_id "${sysfs_path}" | grep -q "ID_PATH=usb"; then
223 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -v loop | grep -v ram); do
224 devname=$(sys2dev "${sysblock}")
225 fstype=$(get_fstype "${devname}")
226 if /lib/udev/cdrom_id ${devname} > /dev/null; then
227 mount -t ${fstype} -o ro "$devname" $mountpoint || continue
228 if casper_path $mountpoint; then
229 echo $(casper_path $mountpoint)
234 elif is_usb_device "$sysblock"; then
235 for dev in $(subdevices "${sysblock}"); do
236 devname=$(sys2dev "${dev}")
237 fstype=$(get_fstype "${devname}")
240 mount -t ${fstype} -o ro "${devname}" $mountpoint || continue
241 if casper_path $mountpoint; then
242 echo $(casper_path $mountpoint)
250 elif [ "${fstype}" = "squashfs" ]; then
252 # This is an ugly hack situation, the block device has
253 # a squashfs image directly on it. It's hopefully
254 # casper, so take it and run with it.
256 ln -s "${devname}" "${devname}.${fstype}"
257 echo "${devname}.${fstype}"
263 set_usplash_timeout() {
264 if [ -x /sbin/usplash_write ]; then
265 /sbin/usplash_write "TIMEOUT 120"
276 [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/casper-premount"
277 run_scripts /scripts/casper-premount
278 [ "$quiet" != "y" ] && log_end_msg
280 # Needed here too because some things (*cough* udev *cough*)
281 # changes the timeout
285 for i in 0 1 2 3 4 5 6 7 8 9 a b c d e f 10 11 12 13; do
286 live_image=$(find_cd)
287 if [ "${live_image}" ]; then
292 if [ "$?" -gt 0 ]; then
293 panic "Unable to find a CD-ROM containing a live file system"
296 setup_cow "$overlay_method" "$(get_backing_device $live_image)" "$rootmnt"
300 maybe_break casper-bottom
301 [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/casper-bottom"
303 run_scripts /scripts/casper-bottom
304 [ "$quiet" != "y" ] && log_end_msg
308 cp casper.log "${rootmnt}/var/log/"