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" ]
37 # fstype misreports LUKS devices
40 /lib/udev/vol_id -t ${1} 2>/dev/null
46 if [ "${FSTYPE}" != "unknown" ]
52 /lib/udev/vol_id -t ${1} 2>/dev/null
59 if grep -q "^${device} " /proc/mounts
61 grep "^${device} " /proc/mounts | read d mountpoint rest
82 mounts="$(awk '{print $2}' /proc/mounts)"
83 testpath="$(busybox realpath ${testpath})"
87 if echo "${mounts}" | grep -qs "^${testpath}"
89 set -- $(echo "${mounts}" | grep "^${testpath}" | lastline)
93 testpath=$(dirname $testpath)
100 # Returns used/free fs kbytes + 5% more
101 # You could pass a block device as ${1} or the mount point as ${2}
107 if [ -z "${mountp}" ]
109 mountp=$(where_is_mounted "${dev}")
113 mountp="/mnt/tmp_fs_size"
116 mount -t $(get_fstype "${dev}") -o ro "${dev}" "${mountp}"
122 if [ "${used}" = "used" ]
124 size=$(du -ks ${mountp} | cut -f1)
125 size=$(expr ${size} + ${size} / 20 ) # FIXME: 5% more to be sure
128 size="$(df -k | grep -s ${mountp} | awk '{print $4}')"
131 if [ -n "${doumount}" ]
143 if [ -x /bin/loadkeys -a -r /etc/boottime.kmap.gz ]
145 loadkeys /etc/boottime.kmap.gz
155 local encryption=${5}
157 modprobe -q -b "${module}"
160 for loopdev in ${pattern}
162 if [ "$(cat ${loopdev}/size)" -eq 0 ]
164 dev=$(sys2dev "${loopdev}")
167 if [ 0 -lt "${offset}" ]
169 options="${options} -o ${offset}"
172 if [ -z "${encryption}" ]
174 losetup ${options} "${dev}" "${fspath}"
176 # Loop AES encryption
181 echo -n "Enter passphrase for ${fspath}: " >&6
183 echo "${passphrase}" > /tmp/passphrase
184 exec 9</tmp/passphrase
185 /sbin/losetup ${options} -e "${encryption}" -p 9 "${dev}" "${fspath}"
188 rm -f /tmp/passphrase
190 if [ 0 -eq ${error} ]
196 echo -n "Something went wrong... Retry? [YES/no] " >&6
199 if [ 'no' = "${answer}" ]
212 panic "No loop devices available"
221 if where_is_mounted ${dev} > /dev/null
223 mount -o remount,"${opts}" ${dev} $(where_is_mounted ${dev}) || panic "Remounting failed"
224 mount -o bind $(where_is_mounted ${dev}) ${mountp} || panic "Cannot bind-mount"
226 mount -t $(get_fstype "${dev}") -o "${opts}" "${dev}" "${mountp}" || panic "Cannot mount ${dev} on ${mountp}"
233 cow_backing="/${pers_label}-backing"
235 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -v loop)
237 for dev in $(subdevices "${sysblock}")
239 devname=$(sys2dev "${dev}")
241 if [ "$(/lib/udev/vol_id -l ${devname} 2>/dev/null)" = "${pers_label}" ]
245 elif [ "$(get_fstype ${devname})" = "vfat" ]
247 # FIXME: all supported block devices should be scanned
248 mkdir -p "${cow_backing}"
249 try_mount "${devname}" "${cow_backing}" "rw"
251 if [ -e "${cow_backing}/${pers_label}" ]
253 echo $(setup_loop "${cow_backing}/${pers_label}" "loop" "/sys/block/loop*")
256 umount ${cow_backing}
265 # return the first of ${filenames} found on vfat and ext2/ext3 devices
266 # FIXME: merge with above function
269 snap_backing="/snap-backing"
271 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -v loop)
273 for dev in $(subdevices "${sysblock}")
275 devname=$(sys2dev "${dev}")
276 devfstype="$(get_fstype ${devname})"
278 if [ "${devfstype}" = "vfat" ] || [ "${devfstype}" = "ext2" ] || [ "${devfstype}" = "ext3" ] || [ "${devfstype}" = "jffs2" ]
280 # FIXME: all supported block devices should be scanned
281 mkdir -p "${snap_backing}"
282 try_mount "${devname}" "${snap_backing}" "ro"
284 for filename in ${filenames}
286 if [ -e "${snap_backing}/${filename}" ]
288 echo "${devname} ${snap_backing} ${filename}"
293 umount ${snap_backing}
303 for adaptor in /sys/class/net/*
305 status="$(cat ${adaptor}/iflink)"
307 if [ "${status}" -eq 2 ]
309 mac="$(cat ${adaptor}/address)"
310 mac="$(echo ${mac} | sed 's/:/-/g' | tr '[a-z]' '[A-Z]')"
320 if [ -x /sbin/cryptsetup ]
322 /sbin/cryptsetup isLuks "${devname}" 2>/dev/null