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
114 modprobe "${MP_QUIET}" -b "$module"
117 for loopdev in $pattern; do
118 if [ "$(cat $loopdev/size)" -eq 0 ]; then
119 dev=$(sys2dev "${loopdev}")
120 losetup "$dev" "$fspath"
125 panic "No loop devices available"
134 if where_is_mounted ${dev} > /dev/null; then
135 mount -o remount,"${opts}" ${dev} $(where_is_mounted ${dev}) || panic "Remounting failed"
136 mount -o bind $(where_is_mounted ${dev}) ${mountp} || panic "Cannot bind-mount"
138 mount -t $(get_fstype "${dev}") -o "${opts}" "${dev}" "${mountp}" || panic "Cannot mount ${dev} on ${mountp}"
144 cow_backing="/${pers_label}-backing"
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)" = "${pers_label}" ]; then
151 elif [ "$(get_fstype ${devname})" = "vfat" ]; then # FIXME: all supported block devices should be scanned
152 mkdir -p "${cow_backing}"
153 try_mount "${devname}" "${cow_backing}" "rw"
154 if [ -e "${cow_backing}/${pers_label}" ]; then
155 echo $(setup_loop "${cow_backing}/${pers_label}" "loop" "/sys/block/loop*")
158 umount ${cow_backing}
166 # return the first of $filenames found on vfat and ext2 devices
167 # FIXME: merge with above function
170 snap_backing="/snap-backing"
171 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -v loop); do
172 for dev in $(subdevices "${sysblock}"); do
173 devname=$(sys2dev "${dev}")
174 devfstype="$(get_fstype ${devname})"
175 if [ "${devfstype}" = "vfat" ] || [ "${devfstype}" = "ext2" ] ; then # FIXME: all supported block devices should be scanned
176 mkdir -p "${snap_backing}"
177 try_mount "${devname}" "${snap_backing}" "ro"
178 for filename in ${filenames}; do
179 if [ -e "${snap_backing}/${filename}" ]; then
180 echo "${devname} ${snap_backing} ${filename}"
184 umount ${snap_backing}