5 export PATH=/root/usr/bin:/root/usr/sbin:/root/bin:/root/sbin:/usr/bin:/usr/sbin:/bin:/sbin
9 # Will be mounted if found as copy on write instead of tmpfs
10 root_persistence="casper-rw"
13 ## Each file found with this pattern will be mounted directly in the
14 ## mountpoint extracted from file name "${other_mounts_pattern}<mountpoint>"
15 #other_mounts_pattern="casper-mount-"
16 home_persistence="home-rw"
18 #overlay_method=unionfs
19 #if [ "${DPKG_ARCH}" = "ia64" ] || [ "${DPKG_ARCH}" = "hppa" ] || [ "${DPKG_ARCH}" = "sparc" ]; then
20 # overlay_method=devmapper
24 USERFULLNAME="Live session user"
29 [ -f /etc/casper.conf ] && . /etc/casper.conf
31 export USERNAME USERFULLNAME HOST
33 # looking for casper specifics options as kernel parameters
34 for x in $(cat /proc/cmdline); do
55 # sort of compatibility with netboot.h from linux docs
56 if [ -z "${NETBOOT}" ]; then
57 if [ "${ROOT}" == "/dev/nfs" ]; then
60 elif [ "${ROOT}" == "/dev/cifs" ]; then
68 if [ -d "$path/casper" ]; then
69 if [ "$(echo $path/casper/*.cloop)" != "$path/casper/*.cloop" ] ||
70 [ "$(echo $path/casper/*.squashfs)" != "$path/casper/*.squashfs" ] ||
71 [ "$(echo $path/casper/*.ext2)" != "$path/casper/*.ext2" ] ||
72 [ "$(echo $path/casper/*.dir)" != "$path/casper/*.dir" ]; then
82 for dev in "${sysblock}" "${sysblock}"/*; do
83 if [ -e "${dev}/dev" ]; then
90 get_backing_device() {
93 echo $(setup_loop "$1" "cloop" "/sys/block/cloop*")
96 echo $(setup_loop "$1" "loop" "/sys/block/loop*")
102 panic "Unrecognized casper filesystem: $1"
107 match_files_in_dir() {
108 # Does any files match pattern $1 ?
111 if [ "$(echo $pattern)" != "$pattern" ]; then
117 mount_images_in_directory() {
120 if match_files_in_dir "$directory/casper/*.cloop"; then
121 # Let's hope there's just one matching *.cloop... FIXME
122 setup_devmapper $(get_backing_device "$directory/casper/*.cloop") "$rootmnt"
123 elif match_files_in_dir "$directory/casper/*.squashfs" ||
124 match_files_in_dir "$directory/casper/*.ext2" ||
125 match_files_in_dir "$directory/casper/*.dir"; then
126 setup_unionfs "$directory/casper" "$rootmnt"
134 echo "/dev/$(udevinfo -q name -p ${sysdev} 2>/dev/null|| echo ${sysdev##*/})"
142 modprobe -qb "$module"
143 if [ -x /sbin/udevplug ]; then
149 for loopdev in $pattern; do
150 if [ "$(cat $loopdev/size)" -eq 0 ]; then
151 dev=$(sys2dev "${loopdev}")
152 losetup "$dev" "$fspath"
157 panic "No loop devices available"
161 #FIXME# one use of this function expects "unknown" another does not!
166 if [ "$FSTYPE" != "unknown" ]; then
170 /lib/udev/vol_id -t $1 2>/dev/null
179 COW_NAME="casper-cow"
181 BACKING_FILE_SIZE=$(blockdev --getsize "$backdev")
182 MAX_COW_SIZE=$(blockdev --getsize "$COW_DEVICE")
183 CHUNK_SIZE=8 # sectors
185 if [ -z "$COW_SIZE" -o "$COW_SIZE" -gt "$MAX_COW_SIZE" ]; then
186 COW_SIZE=$MAX_COW_SIZE
189 echo "0 $COW_SIZE linear $COW_DEVICE 0" | dmsetup create $COW_NAME
191 echo "0 $BACKING_FILE_SIZE snapshot $backdev /dev/mapper/$COW_NAME p $CHUNK_SIZE" | \
192 dmsetup create casper-snapshot
193 if [ "$(get_fstype $backdev)" = "unknown" ]; then
194 panic "Unknown file system type on $backdev"
196 mount -t $(get_fstype "$backdev") /dev/mapper/casper-snapshot $rootmnt || panic "Can not mount /dev/mapper/casper/snapshot on $rootmnt"
198 mkdir -p "$rootmnt/rofs"
199 echo "0 $BACKING_FILE_SIZE linear $backdev 0" | dmsetup create casper-backing
200 mount -t $(get_fstype "$backdev") /dev/mapper/casper-backing "$rootmnt/rofs"
205 if grep -q "^$device " /proc/mounts; then
206 grep "^$device " /proc/mounts | read d mountpoint rest
216 if [ ! -z "${2}" ] ; then
217 # This will enable future rampersistence, todo yet
221 copyto="${copyfrom}_swap"
225 size=$(du -ks ${copyfrom} | cut -f1)
226 size=$(expr ${size} + ${size}/20 ) # Fixme: 5% more to be sure
227 needed_space=$(expr ${size} * 1024)
228 freespace=$( expr $(awk '/MemFree/{print $2}' /proc/meminfo) + $( cat /proc/meminfo | grep Cached | head -n 1 | awk '/Cached/{print $2}' - ))
230 if [ ! ${freespace} -lt ${needed_space} ] ; then
231 [ "$quiet" != "y" ] && log_begin_msg "Not enough free memory to copy to ram"
232 [ "$quiet" != "y" ] && log_end_msg
235 [ "$quiet" != "y" ] && log_begin_msg "Copying live media to ram..."
237 mount -t tmpfs -o size=${size}k /dev/shm ${copyto}
238 cp -a ${copyfrom}/* ${copyto} # "cp -a" from busybox also copies hidden files
240 if [ "${moveit}" == "True" ]; then
241 mount -r -o move ${copyto} ${copyfrom}
244 [ "$quiet" != "y" ] && log_end_msg
250 cow_backing="/${pers_label}-backing"
251 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -v loop); do
252 for dev in $(subdevices "${sysblock}"); do
253 devname=$(sys2dev "${dev}")
254 if [ "$(/lib/udev/vol_id -l $devname 2>/dev/null)" = "${pers_label}" ]; then
257 elif [ "$(get_fstype ${devname})" = "vfat" ]; then
258 mkdir -p "${cow_backing}"
259 if where_is_mounted ${devname} > /dev/null; then
260 mount -o remount,rw ${devname} $(where_is_mounted ${devname}) || panic "Remounting failed"
261 mount -o bind $(where_is_mounted ${devname}) ${cow_backing} || panic "Cannot bind-mount"
263 mount -t $(get_fstype "${devname}") -o rw "${devname}" ${cow_backing} || panic "Cannot mount $devname on /cow-backing"
266 if [ -e "${cow_backing}/${pers_label}" ]; then
267 echo $(setup_loop "${cow_backing}/${pers_label}" "loop" "/sys/block/loop*")
270 umount ${cow_backing}
280 modprobe -q af_packet # For DHCP
282 ipconfig ${DEVICE} /tmp/net-${DEVICE}.conf
284 if [ "${NFSROOT}" = "auto" ]; then
285 NFSROOT=${ROOTSERVER}:${ROOTPATH}
288 [ "$quiet" != "y" ] && log_begin_msg "Trying netboot from ${NFSROOT}"
290 if [ "${NETBOOT}" != "nfs" ] && do_cifsmount ; then
292 elif do_nfsmount ; then
296 [ "$quiet" != "y" ] && log_end_msg
303 if [ -z "${NFSOPTS}" ]; then
307 [ "$quiet" != "y" ] && log_begin_msg "Trying nfsmount -o nolock -o ro ${NFSOPTS} ${NFSROOT} ${mountpoint}"
308 # FIXME: This for loop is an ugly HACK round an nfs bug
309 for i in 0 1 2 3 4 5 6 7 8 9 a b c d e f 10 11 12 13; do
310 nfsmount -o nolock -o ro ${NFSOPTS} "${NFSROOT}" "${mountpoint}" && rc=0 && break
318 if [ -x "/sbin/mount.cifs" ]; then
319 if [ -z "${NFSOPTS}" ]; then
320 CIFSOPTS="-ouser=root,password="
322 CIFSOPTS="${NFSOPTS}"
325 [ "$quiet" != "y" ] && log_begin_msg "Trying mount.cifs ${NFSROOT} ${mountpoint} ${CIFSOPTS}"
328 if mount.cifs "${NFSROOT}" "${mountpoint}" "${CIFSOPTS}" ; then
341 croot="" # Should really be /casper, but run-init doesn't handle
342 # mount-points in subdirectories at all
344 # Let's just mount the read-only file systems first
348 for image_type in "ext2" "squashfs" "dir" ; do
349 for image in "${image_directory}"/*."${image_type}"; do
350 imagename=$(basename "${image}")
351 if [ -d "${image}" ]; then
352 # it is a plain directory: do nothing
353 rofslist="${image} ${rofslist}"
354 rofsstring="${image}=ro:${rofsstring}"
355 elif [ -f "${image}" ]; then
356 backdev=$(get_backing_device "$image")
357 fstype=$(get_fstype "${backdev}")
358 if [ "${fstype}" = "unknown" ]; then
359 panic "Unknown file system type on ${backdev} (${image})"
361 mkdir -p "${croot}/${imagename}"
362 mount -t "${fstype}" -o ro "${backdev}" "${croot}/${imagename}" || panic "Can not mount $backdev ($image) on ${croot}/${imagename}" && rofsstring="${croot}/${imagename}=ro:${rofsstring}" && rofslist="${croot}/${imagename} ${rofslist}"
366 rofsstring=${rofsstring%:}
372 # Looking for "${root_persistence}" device or file
373 if [ ! -z "${PERSISTENT}" ]; then
374 cowprobe=$(find_cow_device "${root_persistence}")
375 if [ -b "${cowprobe}" ]; then
376 cowdevice=${cowprobe}
377 cow_fstype=$(get_fstype "${cowprobe}")
379 [ "$quiet" != "y" ] && log_begin_msg "Unable to find the persistent medium"
383 mount ${cowdevice} -t ${cow_fstype} -o rw /cow || panic "Can not mount $cowdevice on /cow"
385 mount -t unionfs -o dirs=/cow=rw:$rofsstring unionfs "$rootmnt" || panic "Unionfs mount failed"
387 for d in ${rofslist}; do
388 mkdir -p "${rootmnt}/casper/${d}"
389 mount -o bind "${d}" "${rootmnt}/casper/${d}"
391 *.dir) ;; # do nothing
396 # Adding other custom mounts
397 if [ ! -z "${PERSISTENT}" ]; then
398 homecow=$(find_cow_device "${home_persistence}" )
399 if [ -b "${homecow}" ]; then
400 mount ${homecow} -t $(get_fstype "${homecow}") -o rw "${rootmnt}/home"
402 [ "$quiet" != "y" ] && log_begin_msg "Unable to find the persistent home medium"
406 if [ ! -z "${SHOWCOW}" ]; then
407 mkdir -p "$rootmnt/cow"
408 mount -o bind /cow "$rootmnt/cow"
413 sysfs_path="${1#/sys}"
414 if /lib/udev/path_id "${sysfs_path}" | grep -Eq "ID_PATH=(usb|pci-[^-]*-usb)"; then
422 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -v loop | grep -v ram); do
423 devname=$(sys2dev "${sysblock}")
424 fstype=$(get_fstype "${devname}")
425 if /lib/udev/cdrom_id ${devname} > /dev/null; then
426 mount -t ${fstype} -o ro "$devname" $mountpoint || continue
427 if is_casper_path $mountpoint; then
433 elif is_usb_device "$sysblock"; then
434 for dev in $(subdevices "${sysblock}"); do
435 devname=$(sys2dev "${dev}")
436 fstype=$(get_fstype "${devname}")
439 mount -t ${fstype} -o ro "${devname}" $mountpoint || continue
440 if is_casper_path $mountpoint; then
449 elif [ "${fstype}" = "squashfs" || \
450 "${fstype}" = "ext2" ]; then
452 # This is an ugly hack situation, the block device has
453 # an image directly on it. It's hopefully
454 # casper, so take it and run with it.
456 ln -s "${devname}" "${devname}.${fstype}"
457 echo "${devname}.${fstype}"
463 set_usplash_timeout() {
464 if [ -x /sbin/usplash_write ]; then
465 /sbin/usplash_write "TIMEOUT 120"
476 [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/casper-premount"
477 run_scripts /scripts/casper-premount
478 [ "$quiet" != "y" ] && log_end_msg
480 # Needed here too because some things (*cough* udev *cough*)
481 # changes the timeout
485 if [ ! -z "${NETBOOT}" ]; then
486 if do_netmount ; then
487 livefs_root="${mountpoint}"
489 panic "Unable to find a the network rootfs live file system"
492 # Scan local devices for the image
493 for i in 0 1 2 3 4 5 6 7 8 9 a b c d e f 10 11 12 13; do
494 livefs_root=$(find_livefs)
495 if [ "${livefs_root}" ]; then
500 if [ "$?" -gt 0 ]; then
501 panic "Unable to find a medium containing a live file system"
504 if [ ! -z "${TORAM}" ]; then
505 copy_to_ram "${livefs_root}"
510 mount_images_in_directory "$livefs_root" "$rootmnt"
514 maybe_break casper-bottom
515 [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/casper-bottom"
517 run_scripts /scripts/casper-bottom
518 [ "$quiet" != "y" ] && log_end_msg
522 cp casper.log "${rootmnt}/var/log/"