1 ## live-initramfs helper functions, used by live-initramfs on boot and by live-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
114 if [ -x /bin/loadkeys -a -r /etc/boottime.kmap.gz ]; then
115 loadkeys /etc/boottime.kmap.gz
126 modprobe ${MP_QUIET} -b "$module"
129 for loopdev in $pattern; do
130 if [ "$(cat $loopdev/size)" -eq 0 ]; then
131 dev=$(sys2dev "${loopdev}")
133 if [ 0 -lt "${offset}" ]; then
134 options="${options} -o ${offset}"
136 if [ -z "${encryption}" ]; then
137 losetup ${options} "${dev}" "${fspath}"
139 # Loop AES encryption
142 echo -n "Enter passphrase for ${fspath}: " >&6
144 echo "${passphrase}" > /tmp/passphrase
145 exec 9</tmp/passphrase
146 /sbin/losetup ${options} -e "${encryption}" -p 9 "${dev}" "${fspath}"
149 rm -f /tmp/passphrase
150 if [ 0 -eq ${error} ]; then
154 echo -n "Something went wrong... Retry? [YES/no] " >&6
156 if [ 'no' = "${answer}" ]; then
166 panic "No loop devices available"
175 if where_is_mounted ${dev} > /dev/null; then
176 mount -o remount,"${opts}" ${dev} $(where_is_mounted ${dev}) || panic "Remounting failed"
177 mount -o bind $(where_is_mounted ${dev}) ${mountp} || panic "Cannot bind-mount"
179 mount -t $(get_fstype "${dev}") -o "${opts}" "${dev}" "${mountp}" || panic "Cannot mount ${dev} on ${mountp}"
185 cow_backing="/${pers_label}-backing"
186 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -v loop); do
187 for dev in $(subdevices "${sysblock}"); do
188 devname=$(sys2dev "${dev}")
189 if [ "$(/lib/udev/vol_id -l $devname 2>/dev/null)" = "${pers_label}" ]; then
192 elif [ "$(get_fstype ${devname})" = "vfat" ]; then # FIXME: all supported block devices should be scanned
193 mkdir -p "${cow_backing}"
194 try_mount "${devname}" "${cow_backing}" "rw"
195 if [ -e "${cow_backing}/${pers_label}" ]; then
196 echo $(setup_loop "${cow_backing}/${pers_label}" "loop" "/sys/block/loop*")
199 umount ${cow_backing}
207 # return the first of $filenames found on vfat and ext2/ext3 devices
208 # FIXME: merge with above function
211 snap_backing="/snap-backing"
212 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -v loop); do
213 for dev in $(subdevices "${sysblock}"); do
214 devname=$(sys2dev "${dev}")
215 devfstype="$(get_fstype ${devname})"
216 if [ "${devfstype}" = "vfat" ] || [ "${devfstype}" = "ext2" ] || [ "${devfstype}" = "ext3" ]; then # FIXME: all supported block devices should be scanned
217 mkdir -p "${snap_backing}"
218 try_mount "${devname}" "${snap_backing}" "ro"
219 for filename in ${filenames}; do
220 if [ -e "${snap_backing}/${filename}" ]; then
221 echo "${devname} ${snap_backing} ${filename}"
225 umount ${snap_backing}