1 ## Casper helper functions, used by casper on boot and by casper-snapshot
3 if [ "${BUILD_SYSTEM}" = "Ubuntu" ]; then
5 elif [ "${BUILD_SYSTEM}" = "Debian" ]; then
11 if [ ! -x "/bin/fstype" ]; then
12 # klibc not in path -> not in initramfs
13 export PATH="${PATH}:/usr/lib/klibc/bin"
18 echo "/dev/$(udevinfo -q name -p ${sysdev} 2>/dev/null|| echo ${sysdev##*/})"
24 for dev in "${sysblock}" "${sysblock}"/*; do
25 if [ -e "${dev}/dev" ]; then
36 if [ "$FSTYPE" != "unknown" ]; then
40 /lib/udev/vol_id -t $1 2>/dev/null
45 if grep -q "^$device " /proc/mounts; then
46 grep "^$device " /proc/mounts | read d mountpoint rest
63 mounts="$(awk '{print $2}' /proc/mounts)"
64 testpath="$(busybox realpath ${testpath})"
67 if echo "${mounts}" | grep -qs "^${testpath}" ; then
68 set -- `echo "${mounts}" | grep "^${testpath}" | lastline`
72 testpath=`dirname $testpath`
79 # Returns used/free fs kbytes + 5% more
80 # You could pass a block device as $1 or the mount point as $2
86 if [ -z "${mountp}" ]; then
87 mountp=$(where_is_mounted "${dev}")
88 if [ "$?" -gt 0 ]; then
89 mountp="/mnt/tmp_fs_size"
91 mount -t $(get_fstype "${dev}") -o ro "${dev}" "${mountp}"
96 if [ "${used}" = "used" ]; then
97 size=$(du -ks ${mountp} | cut -f1)
98 size=$(expr ${size} + ${size} / 20 ) # FIXME: 5% more to be sure
101 size="$(df -k | grep -s ${mountp} | awk '{print $4}')"
104 if [ -n "${doumount}" ]; then
117 modprobe ${MP_QUIET} -b "$module"
120 for loopdev in $pattern; do
121 if [ "$(cat $loopdev/size)" -eq 0 ]; then
122 dev=$(sys2dev "${loopdev}")
123 if [ -n "$offset" ]; then
124 losetup -o "$offset" "$dev" "$fspath"
126 losetup "$dev" "$fspath"
132 panic "No loop devices available"
141 if where_is_mounted ${dev} > /dev/null; then
142 mount -o remount,"${opts}" ${dev} $(where_is_mounted ${dev}) || panic "Remounting failed"
143 mount -o bind $(where_is_mounted ${dev}) ${mountp} || panic "Cannot bind-mount"
145 mount -t $(get_fstype "${dev}") -o "${opts}" "${dev}" "${mountp}" || panic "Cannot mount ${dev} on ${mountp}"
151 cow_backing="/${pers_label}-backing"
152 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -v loop); do
153 for dev in $(subdevices "${sysblock}"); do
154 devname=$(sys2dev "${dev}")
155 if [ "$(/lib/udev/vol_id -l $devname 2>/dev/null)" = "${pers_label}" ]; then
158 elif [ "$(get_fstype ${devname})" = "vfat" ]; then # FIXME: all supported block devices should be scanned
159 mkdir -p "${cow_backing}"
160 try_mount "${devname}" "${cow_backing}" "rw"
161 if [ -e "${cow_backing}/${pers_label}" ]; then
162 echo $(setup_loop "${cow_backing}/${pers_label}" "loop" "/sys/block/loop*")
165 umount ${cow_backing}
173 # return the first of $filenames found on vfat and ext2 devices
174 # FIXME: merge with above function
177 snap_backing="/snap-backing"
178 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -v loop); do
179 for dev in $(subdevices "${sysblock}"); do
180 devname=$(sys2dev "${dev}")
181 devfstype="$(get_fstype ${devname})"
182 if [ "${devfstype}" = "vfat" ] || [ "${devfstype}" = "ext2" ] ; then # FIXME: all supported block devices should be scanned
183 mkdir -p "${snap_backing}"
184 try_mount "${devname}" "${snap_backing}" "ro"
185 for filename in ${filenames}; do
186 if [ -e "${snap_backing}/${filename}" ]; then
187 echo "${devname} ${snap_backing} ${filename}"
191 umount ${snap_backing}