3 ## live-build(7) - System Build Scripts
4 ## Copyright (C) 2006-2015 Daniel Baumann <mail@daniel-baumann.ch>
6 ## This program comes with ABSOLUTELY NO WARRANTY; for details see COPYING.
7 ## This is free software, and you are welcome to redistribute it
8 ## under certain conditions; see COPYING for details.
15 if [ "${ATTEMPT}" -gt 3 ]
17 Echo_error
"Failed to detach loop device '${DEVICE}'."
21 # Changes to block devices result in uevents which trigger rules which in
22 # turn access the loop device (ex. udisks-part-id, blkid) which can cause
23 # a race condition. We call 'udevadm settle' to help avoid this.
24 if [ -x "$(which udevadm 2>/dev/null)" ]
29 # Loop back devices aren't the most reliable when it comes to writes.
30 # We sleep and sync for good measure - better than build failure.
34 ${LB_LOSETUP} -d "${DEVICE}" || Lodetach "${DEVICE}" "$(expr ${ATTEMPT} + 1)"
43 ${LB_LOSETUP} --read-only "${DEVICE}" "${FILE}"
44 FDISK_OUT
="$(${LB_FDISK} -l -u ${DEVICE} 2>&1)"
47 LOOPDEVICE
="$(echo ${DEVICE}p${PARTITION})"
49 if [ "${PARTITION}" = "0" ]
51 Echo_message
"Mounting %s with offset 0" "${DEVICE}"
53 ${LB_LOSETUP} "${DEVICE}" "${FILE}"
55 SECTORS="$
(echo "$FDISK_OUT" |
sed -ne "s|^$LOOPDEVICE[ *]*\([0-9]*\).*|\1|p")"
56 OFFSET="$
(expr ${SECTORS} '*' 512)"
58 Echo_message "Mounting
%s with offset
%s
" "${DEVICE}" "${OFFSET}"
60 ${LB_LOSETUP} -o "${OFFSET}" "${DEVICE}" "${FILE}"
64 Calculate_partition_size
()
69 case "${FILESYSTEM}" in
78 echo $
(expr ${ORIGINAL_SIZE} + ${ORIGINAL_SIZE} \* ${PERCENT} / 100 + 1)