1 ## Casper helper functions, used by casper on boot and by casper-snapshot
3 if [ "${BUILD_SYSTEM}" == "Ubuntu" ]; then
11 echo "/dev/$(udevinfo -q name -p ${sysdev} 2>/dev/null|| echo ${sysdev##*/})"
17 for dev in "${sysblock}" "${sysblock}"/*; do
18 if [ -e "${dev}/dev" ]; then
27 if grep -q "^$device " /proc/mounts; then
28 grep "^$device " /proc/mounts | read d mountpoint rest
45 mounts="$(awk '{print $2}' /proc/mounts)"
46 testpath="$(busybox realpath ${testpath})"
49 if echo "${mounts}" | grep -qs "^${testpath}" ; then
50 set -- `echo "${mounts}" | grep "^${testpath}" | lastline`
54 testpath=`dirname $testpath`
61 # Returns used fs kbytes + 5% more
62 # You could pass a block device as $1 or the mount point as $2
67 if [ -z "${mountp}" ]; then
68 mountp=$(where_is_mounted "${dev}")
69 if [ "$?" -gt 0 ]; then
70 mountp=/mnt/tmp_fs_size
72 mount -t $(get_fstype "${dev}") -o ro "${dev}" "${mountp}"
77 size=$(du -ks ${mountp} | cut -f1)
78 size=$(expr ${size} + ${size}/20 ) # FIXME: 5% more to be sure
79 needed_space=$(expr ${size} * 1024)
81 if [ ! -z "${doumount}" ]; then
85 echo "${needed_space}"
93 modprobe "${MP_QUIET}" -b "$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"
113 if where_is_mounted ${dev} > /dev/null; then
114 mount -o remount,"${opts}" ${dev} $(where_is_mounted ${dev}) || panic "Remounting failed"
115 mount -o bind $(where_is_mounted ${dev}) ${mountp} || panic "Cannot bind-mount"
117 mount -t $(get_fstype "${dev}") -o "${opts}" "${dev}" "${mountp}" || panic "Cannot mount ${dev} on ${mountp}"
123 cow_backing="/${pers_label}-backing"
124 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -v loop); do
125 for dev in $(subdevices "${sysblock}"); do
126 devname=$(sys2dev "${dev}")
127 if [ "$(/lib/udev/vol_id -l $devname 2>/dev/null)" = "${pers_label}" ]; then
130 elif [ "$(get_fstype ${devname})" = "vfat" ]; then # FIXME: all supported block devices should be scanned
131 mkdir -p "${cow_backing}"
132 try_mount "${devname}" "${cow_backing}" "rw"
133 if [ -e "${cow_backing}/${pers_label}" ]; then
134 echo $(setup_loop "${cow_backing}/${pers_label}" "loop" "/sys/block/loop*")
137 umount ${cow_backing}
145 # return the first of $filenames found on vfat and ext2 devices
146 # FIXME: merge with above function
149 snap_backing="/snap-backing"
150 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -v loop); do
151 for dev in $(subdevices "${sysblock}"); do
152 devname=$(sys2dev "${dev}")
153 devfstype="$(get_fstype ${devname})"
154 if [ "${devfstype}" = "vfat" ] || [ "${devfstype}" = "ext2" ] ; then # FIXME: all supported block devices should be scanned
155 mkdir -p "${snap_backing}"
156 try_mount "${devname}" "${snap_backing}" "ro"
157 for filename in ${filenames}; do
158 if [ -e "${snap_backing}/${filename}" ]; then
159 echo "${devname} ${snap_backing} ${filename}"
163 umount ${snap_backing}