2 # live-initramfs helper functions, used by live-initramfs on boot and by live-snapshot
4 if [ ! -x "/bin/fstype" ]
6 # klibc not in path -> not in initramfs
7 export PATH="${PATH}:/usr/lib/klibc/bin"
13 echo "/dev/$(udevinfo -q name -p ${sysdev} 2>/dev/null|| echo ${sysdev##*/})"
21 for dev in "${sysblock}" "${sysblock}"/*
23 if [ -e "${dev}/dev" ]
39 if [ "${FSTYPE}" != "unknown" ]
45 /lib/udev/vol_id -t ${1} 2>/dev/null
52 if grep -q "^${device} " /proc/mounts
54 grep "^${device} " /proc/mounts | read d mountpoint rest
75 mounts="$(awk '{print $2}' /proc/mounts)"
76 testpath="$(busybox realpath ${testpath})"
80 if echo "${mounts}" | grep -qs "^${testpath}"
82 set -- $(echo "${mounts}" | grep "^${testpath}" | lastline)
86 testpath=$(dirname $testpath)
93 # Returns used/free fs kbytes + 5% more
94 # You could pass a block device as ${1} or the mount point as ${2}
100 if [ -z "${mountp}" ]
102 mountp=$(where_is_mounted "${dev}")
106 mountp="/mnt/tmp_fs_size"
109 mount -t $(get_fstype "${dev}") -o ro "${dev}" "${mountp}"
115 if [ "${used}" = "used" ]
117 size=$(du -ks ${mountp} | cut -f1)
118 size=$(expr ${size} + ${size} / 20 ) # FIXME: 5% more to be sure
121 size="$(df -k | grep -s ${mountp} | awk '{print $4}')"
124 if [ -n "${doumount}" ]
136 if [ -x /bin/loadkeys -a -r /etc/boottime.kmap.gz ]
138 loadkeys /etc/boottime.kmap.gz
148 local encryption=${5}
150 modprobe -q -b "${module}"
153 for loopdev in ${pattern}
155 if [ "$(cat ${loopdev}/size)" -eq 0 ]
157 dev=$(sys2dev "${loopdev}")
160 if [ 0 -lt "${offset}" ]
162 options="${options} -o ${offset}"
165 if [ -z "${encryption}" ]
167 losetup ${options} "${dev}" "${fspath}"
169 # Loop AES encryption
174 echo -n "Enter passphrase for ${fspath}: " >&6
176 echo "${passphrase}" > /tmp/passphrase
177 exec 9</tmp/passphrase
178 /sbin/losetup ${options} -e "${encryption}" -p 9 "${dev}" "${fspath}"
181 rm -f /tmp/passphrase
183 if [ 0 -eq ${error} ]
189 echo -n "Something went wrong... Retry? [YES/no] " >&6
192 if [ 'no' = "${answer}" ]
205 panic "No loop devices available"
214 if where_is_mounted ${dev} > /dev/null
216 mount -o remount,"${opts}" ${dev} $(where_is_mounted ${dev}) || panic "Remounting failed"
217 mount -o bind $(where_is_mounted ${dev}) ${mountp} || panic "Cannot bind-mount"
219 mount -t $(get_fstype "${dev}") -o "${opts}" "${dev}" "${mountp}" || panic "Cannot mount ${dev} on ${mountp}"
226 cow_backing="/${pers_label}-backing"
228 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -v loop)
230 for dev in $(subdevices "${sysblock}")
232 devname=$(sys2dev "${dev}")
234 if [ "$(/lib/udev/vol_id -l ${devname} 2>/dev/null)" = "${pers_label}" ]
238 elif [ "$(get_fstype ${devname})" = "vfat" ]
240 # FIXME: all supported block devices should be scanned
241 mkdir -p "${cow_backing}"
242 try_mount "${devname}" "${cow_backing}" "rw"
244 if [ -e "${cow_backing}/${pers_label}" ]
246 echo $(setup_loop "${cow_backing}/${pers_label}" "loop" "/sys/block/loop*")
249 umount ${cow_backing}
258 # return the first of ${filenames} found on vfat and ext2/ext3 devices
259 # FIXME: merge with above function
262 snap_backing="/snap-backing"
264 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -v loop)
266 for dev in $(subdevices "${sysblock}")
268 devname=$(sys2dev "${dev}")
269 devfstype="$(get_fstype ${devname})"
271 if [ "${devfstype}" = "vfat" ] || [ "${devfstype}" = "ext2" ] || [ "${devfstype}" = "ext3" ]
273 # FIXME: all supported block devices should be scanned
274 mkdir -p "${snap_backing}"
275 try_mount "${devname}" "${snap_backing}" "ro"
277 for filename in ${filenames}
279 if [ -e "${snap_backing}/${filename}" ]
281 echo "${devname} ${snap_backing} ${filename}"
286 umount ${snap_backing}