1 ## Casper helper functions, used by casper on boot and by casper-snapshot
3 if [ "${BUILD_SYSTEM}" == "Ubuntu" ]; then
9 if [ ! -x "/bin/fstype" ]; then
10 # klibc not in path -> not in initramfs
11 export PATH="${PATH}:/usr/lib/klibc/bin"
16 echo "/dev/$(udevinfo -q name -p ${sysdev} 2>/dev/null|| echo ${sysdev##*/})"
22 for dev in "${sysblock}" "${sysblock}"/*; do
23 if [ -e "${dev}/dev" ]; then
34 if [ "$FSTYPE" != "unknown" ]; then
38 /lib/udev/vol_id -t $1 2>/dev/null
43 if grep -q "^$device " /proc/mounts; then
44 grep "^$device " /proc/mounts | read d mountpoint rest
61 mounts="$(awk '{print $2}' /proc/mounts)"
62 testpath="$(busybox realpath ${testpath})"
65 if echo "${mounts}" | grep -qs "^${testpath}" ; then
66 set -- `echo "${mounts}" | grep "^${testpath}" | lastline`
70 testpath=`dirname $testpath`
77 # Returns used/free fs kbytes + 5% more
78 # You could pass a block device as $1 or the mount point as $2
84 if [ -z "${mountp}" ]; then
85 mountp=$(where_is_mounted "${dev}")
86 if [ "$?" -gt 0 ]; then
87 mountp="/mnt/tmp_fs_size"
89 mount -t $(get_fstype "${dev}") -o ro "${dev}" "${mountp}"
94 if [ "${used}" = "used" ]; then
95 size=$(du -ks ${mountp} | cut -f1)
96 size=$(expr ${size} + ${size} / 20 ) # FIXME: 5% more to be sure
99 size="$(df -k | grep -s ${mountp} | awk '{print $4}')"
102 if [ -n "${doumount}" ]; then
115 modprobe "${MP_QUIET}" -b "$module"
118 for loopdev in $pattern; do
119 if [ "$(cat $loopdev/size)" -eq 0 ]; then
120 dev=$(sys2dev "${loopdev}")
121 if [ -n "$offset" ]; then
122 losetup -o "$offset" "$dev" "$fspath"
124 losetup "$dev" "$fspath"
130 panic "No loop devices available"
139 if where_is_mounted ${dev} > /dev/null; then
140 mount -o remount,"${opts}" ${dev} $(where_is_mounted ${dev}) || panic "Remounting failed"
141 mount -o bind $(where_is_mounted ${dev}) ${mountp} || panic "Cannot bind-mount"
143 mount -t $(get_fstype "${dev}") -o "${opts}" "${dev}" "${mountp}" || panic "Cannot mount ${dev} on ${mountp}"
149 cow_backing="/${pers_label}-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 if [ "$(/lib/udev/vol_id -l $devname 2>/dev/null)" = "${pers_label}" ]; then
156 elif [ "$(get_fstype ${devname})" = "vfat" ]; then # FIXME: all supported block devices should be scanned
157 mkdir -p "${cow_backing}"
158 try_mount "${devname}" "${cow_backing}" "rw"
159 if [ -e "${cow_backing}/${pers_label}" ]; then
160 echo $(setup_loop "${cow_backing}/${pers_label}" "loop" "/sys/block/loop*")
163 umount ${cow_backing}
171 # return the first of $filenames found on vfat and ext2 devices
172 # FIXME: merge with above function
175 snap_backing="/snap-backing"
176 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -v loop); do
177 for dev in $(subdevices "${sysblock}"); do
178 devname=$(sys2dev "${dev}")
179 devfstype="$(get_fstype ${devname})"
180 if [ "${devfstype}" = "vfat" ] || [ "${devfstype}" = "ext2" ] ; then # FIXME: all supported block devices should be scanned
181 mkdir -p "${snap_backing}"
182 try_mount "${devname}" "${snap_backing}" "ro"
183 for filename in ${filenames}; do
184 if [ -e "${snap_backing}/${filename}" ]; then
185 echo "${devname} ${snap_backing} ${filename}"
189 umount ${snap_backing}