2 # live-initramfs helper functions, used by live-initramfs on boot and by live-snapshot
4 if [ "${BUILD_SYSTEM}" = "Ubuntu" ]
7 elif [ "${BUILD_SYSTEM}" = "Debian" ]
14 if [ ! -x "/bin/fstype" ]
16 # klibc not in path -> not in initramfs
17 export PATH="${PATH}:/usr/lib/klibc/bin"
23 echo "/dev/$(udevinfo -q name -p ${sysdev} 2>/dev/null|| echo ${sysdev##*/})"
31 for dev in "${sysblock}" "${sysblock}"/*
33 if [ -e "${dev}/dev" ]
49 if [ "${FSTYPE}" != "unknown" ]
55 /lib/udev/vol_id -t ${1} 2>/dev/null
62 if grep -q "^${device} " /proc/mounts
64 grep "^${device} " /proc/mounts | read d mountpoint rest
85 mounts="$(awk '{print $2}' /proc/mounts)"
86 testpath="$(busybox realpath ${testpath})"
90 if echo "${mounts}" | grep -qs "^${testpath}"
92 set -- $(echo "${mounts}" | grep "^${testpath}" | lastline)
96 testpath=$(dirname $testpath)
103 # Returns used/free fs kbytes + 5% more
104 # You could pass a block device as ${1} or the mount point as ${2}
110 if [ -z "${mountp}" ]
112 mountp=$(where_is_mounted "${dev}")
116 mountp="/mnt/tmp_fs_size"
119 mount -t $(get_fstype "${dev}") -o ro "${dev}" "${mountp}"
125 if [ "${used}" = "used" ]
127 size=$(du -ks ${mountp} | cut -f1)
128 size=$(expr ${size} + ${size} / 20 ) # FIXME: 5% more to be sure
131 size="$(df -k | grep -s ${mountp} | awk '{print $4}')"
134 if [ -n "${doumount}" ]
146 if [ -x /bin/loadkeys -a -r /etc/boottime.kmap.gz ]
148 loadkeys /etc/boottime.kmap.gz
158 local encryption=${5}
160 modprobe ${MP_QUIET} -b "${module}"
163 for loopdev in ${pattern}
165 if [ "$(cat ${loopdev}/size)" -eq 0 ]
167 dev=$(sys2dev "${loopdev}")
170 if [ 0 -lt "${offset}" ]
172 options="${options} -o ${offset}"
175 if [ -z "${encryption}" ]
177 losetup ${options} "${dev}" "${fspath}"
179 # Loop AES encryption
184 echo -n "Enter passphrase for ${fspath}: " >&6
186 echo "${passphrase}" > /tmp/passphrase
187 exec 9</tmp/passphrase
188 /sbin/losetup ${options} -e "${encryption}" -p 9 "${dev}" "${fspath}"
191 rm -f /tmp/passphrase
193 if [ 0 -eq ${error} ]
199 echo -n "Something went wrong... Retry? [YES/no] " >&6
202 if [ 'no' = "${answer}" ]
215 panic "No loop devices available"
224 if where_is_mounted ${dev} > /dev/null
226 mount -o remount,"${opts}" ${dev} $(where_is_mounted ${dev}) || panic "Remounting failed"
227 mount -o bind $(where_is_mounted ${dev}) ${mountp} || panic "Cannot bind-mount"
229 mount -t $(get_fstype "${dev}") -o "${opts}" "${dev}" "${mountp}" || panic "Cannot mount ${dev} on ${mountp}"
236 cow_backing="/${pers_label}-backing"
238 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -v loop)
240 for dev in $(subdevices "${sysblock}")
242 devname=$(sys2dev "${dev}")
244 if [ "$(/lib/udev/vol_id -l ${devname} 2>/dev/null)" = "${pers_label}" ]
248 elif [ "$(get_fstype ${devname})" = "vfat" ]
250 # FIXME: all supported block devices should be scanned
251 mkdir -p "${cow_backing}"
252 try_mount "${devname}" "${cow_backing}" "rw"
254 if [ -e "${cow_backing}/${pers_label}" ]
256 echo $(setup_loop "${cow_backing}/${pers_label}" "loop" "/sys/block/loop*")
259 umount ${cow_backing}
268 # return the first of ${filenames} found on vfat and ext2/ext3 devices
269 # FIXME: merge with above function
272 snap_backing="/snap-backing"
274 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -v loop)
276 for dev in $(subdevices "${sysblock}")
278 devname=$(sys2dev "${dev}")
279 devfstype="$(get_fstype ${devname})"
281 if [ "${devfstype}" = "vfat" ] || [ "${devfstype}" = "ext2" ] || [ "${devfstype}" = "ext3" ]
283 # FIXME: all supported block devices should be scanned
284 mkdir -p "${snap_backing}"
285 try_mount "${devname}" "${snap_backing}" "ro"
287 for filename in ${filenames}
289 if [ -e "${snap_backing}/${filename}" ]
291 echo "${devname} ${snap_backing} ${filename}"
296 umount ${snap_backing}