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" ]
34 # FIXME: do something better like the scan of supported filesystems
38 vfat|iso9660|udf|ext2|ext3|ntfs|jffs2)
51 # fstype misreports LUKS devices
54 /lib/udev/vol_id -t ${1} 2>/dev/null
60 if [ "${FSTYPE}" != "unknown" ]
66 /lib/udev/vol_id -t ${1} 2>/dev/null
73 if grep -q "^${device} " /proc/mounts
75 grep "^${device} " /proc/mounts | read d mountpoint rest
96 mounts="$(awk '{print $2}' /proc/mounts)"
97 testpath="$(busybox realpath ${testpath})"
101 if echo "${mounts}" | grep -qs "^${testpath}"
103 set -- $(echo "${mounts}" | grep "^${testpath}" | lastline)
107 testpath=$(dirname $testpath)
114 # Returns used/free fs kbytes + 5% more
115 # You could pass a block device as ${1} or the mount point as ${2}
121 if [ -z "${mountp}" ]
123 mountp=$(where_is_mounted "${dev}")
127 mountp="/mnt/tmp_fs_size"
130 mount -t $(get_fstype "${dev}") -o ro "${dev}" "${mountp}"
136 if [ "${used}" = "used" ]
138 size=$(du -ks ${mountp} | cut -f1)
139 size=$(expr ${size} + ${size} / 20 ) # FIXME: 5% more to be sure
142 size="$(df -k | grep -s ${mountp} | awk '{print $4}')"
145 if [ -n "${doumount}" ]
157 if [ -x /bin/loadkeys -a -r /etc/boottime.kmap.gz ]
159 loadkeys /etc/boottime.kmap.gz
169 local encryption=${5}
171 modprobe -q -b "${module}"
174 for loopdev in ${pattern}
176 if [ "$(cat ${loopdev}/size)" -eq 0 ]
178 dev=$(sys2dev "${loopdev}")
181 if [ 0 -lt "${offset}" ]
183 options="${options} -o ${offset}"
186 if [ -z "${encryption}" ]
188 losetup ${options} "${dev}" "${fspath}"
190 # Loop AES encryption
195 echo -n "Enter passphrase for root filesystem: " >&6
197 echo "${passphrase}" > /tmp/passphrase
199 exec 9</tmp/passphrase
200 /sbin/losetup ${options} -e "${encryption}" -p 9 "${dev}" "${fspath}"
203 rm -f /tmp/passphrase
205 if [ 0 -eq ${error} ]
212 echo -n "There was an error decrypting the root filesystem ... Retry? [Y/n] " >&6
215 if [ "$(echo "${answer}" | cut -b1 | tr A-Z a-z)" = "n" ]
228 panic "No loop devices available"
237 if where_is_mounted ${dev} > /dev/null
239 mount -o remount,"${opts}" ${dev} $(where_is_mounted ${dev}) || panic "Remounting failed"
240 mount -o bind $(where_is_mounted ${dev}) ${mountp} || panic "Cannot bind-mount"
242 mount -t $(get_fstype "${dev}") -o "${opts}" "${dev}" "${mountp}" || panic "Cannot mount ${dev} on ${mountp}"
249 cow_backing="/${pers_label}-backing"
251 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -v loop | grep -v ram | grep -v fd)
253 for dev in $(subdevices "${sysblock}")
255 devname=$(sys2dev "${dev}")
257 if [ "$(/lib/udev/vol_id -l ${devname} 2>/dev/null)" = "${pers_label}" ]
263 case "$(get_fstype ${devname})" in
264 vfat|ext2|ext3|jffs2)
265 mkdir -p "${cow_backing}"
266 try_mount "${devname}" "${cow_backing}" "rw"
268 if [ -f "${cow_backing}/${pers_label}" ]
270 echo $(setup_loop "${cow_backing}/${pers_label}" "loop" "/sys/block/loop*")
273 umount ${cow_backing}
285 # return the first of ${filenames} found on vfat and ext2/ext3 devices
286 # FIXME: merge with above function
289 snap_backing="/snap-backing"
291 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -v loop | grep -v ram | grep -v fd)
293 for dev in $(subdevices "${sysblock}")
295 devname=$(sys2dev "${dev}")
296 devfstype="$(get_fstype ${devname})"
298 if is_supported_fs ${devfstype}
300 mkdir -p "${snap_backing}"
301 try_mount "${devname}" "${snap_backing}" "ro"
303 for filename in ${filenames}
305 if [ -f "${snap_backing}/${filename}" ]
307 echo "${devname} ${snap_backing} ${filename}"
312 umount ${snap_backing}
322 for adaptor in /sys/class/net/*
324 status="$(cat ${adaptor}/iflink)"
326 if [ "${status}" -eq 2 ]
328 mac="$(cat ${adaptor}/address)"
329 mac="$(echo ${mac} | sed 's/:/-/g' | tr '[a-z]' '[A-Z]')"
339 if [ -x /sbin/cryptsetup ]
341 /sbin/cryptsetup isLuks "${devname}" 2>/dev/null || ret=${?}