summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xexport-image/prerun.sh32
-rwxr-xr-xexport-noobs/prerun.sh32
-rw-r--r--scripts/common20
3 files changed, 20 insertions, 64 deletions
diff --git a/export-image/prerun.sh b/export-image/prerun.sh
index 145d61e..c3412c2 100755
--- a/export-image/prerun.sh
+++ b/export-image/prerun.sh
@@ -33,41 +33,21 @@ if [ "${NO_PRERUN_QCOW2}" = "0" ]; then
parted --script "${IMG_FILE}" unit B mkpart primary fat32 "${BOOT_PART_START}" "$((BOOT_PART_START + BOOT_PART_SIZE - 1))"
parted --script "${IMG_FILE}" unit B mkpart primary ext4 "${ROOT_PART_START}" "$((ROOT_PART_START + ROOT_PART_SIZE - 1))"
- PARTED_OUT=$(parted -sm "${IMG_FILE}" unit b print)
- BOOT_OFFSET=$(echo "$PARTED_OUT" | grep -e '^1:' | cut -d':' -f 2 | tr -d B)
- BOOT_LENGTH=$(echo "$PARTED_OUT" | grep -e '^1:' | cut -d':' -f 4 | tr -d B)
-
- ROOT_OFFSET=$(echo "$PARTED_OUT" | grep -e '^2:' | cut -d':' -f 2 | tr -d B)
- ROOT_LENGTH=$(echo "$PARTED_OUT" | grep -e '^2:' | cut -d':' -f 4 | tr -d B)
-
- echo "Mounting BOOT_DEV..."
- cnt=0
- until BOOT_DEV=$(losetup --show -f -o "${BOOT_OFFSET}" --sizelimit "${BOOT_LENGTH}" "${IMG_FILE}"); do
- if [ $cnt -lt 5 ]; then
- cnt=$((cnt + 1))
- echo "Error in losetup for BOOT_DEV. Retrying..."
- sleep 5
- else
- echo "ERROR: losetup for BOOT_DEV failed; exiting"
- exit 1
- fi
- done
-
- echo "Mounting ROOT_DEV..."
+ echo "Creating loop device..."
cnt=0
- until ROOT_DEV=$(losetup --show -f -o "${ROOT_OFFSET}" --sizelimit "${ROOT_LENGTH}" "${IMG_FILE}"); do
+ until LOOP_DEV="$(losetup --show --find --partscan "$IMG_FILE")"; do
if [ $cnt -lt 5 ]; then
cnt=$((cnt + 1))
- echo "Error in losetup for ROOT_DEV. Retrying..."
+ echo "Error in losetup. Retrying..."
sleep 5
else
- echo "ERROR: losetup for ROOT_DEV failed; exiting"
+ echo "ERROR: losetup failed; exiting"
exit 1
fi
done
- echo "/boot: offset $BOOT_OFFSET, length $BOOT_LENGTH"
- echo "/: offset $ROOT_OFFSET, length $ROOT_LENGTH"
+ BOOT_DEV="${LOOP_DEV}p1"
+ ROOT_DEV="${LOOP_DEV}p2"
ROOT_FEATURES="^huge_file"
for FEATURE in 64bit; do
diff --git a/export-noobs/prerun.sh b/export-noobs/prerun.sh
index 97dd094..3858c66 100755
--- a/export-noobs/prerun.sh
+++ b/export-noobs/prerun.sh
@@ -9,41 +9,21 @@ unmount_image "${IMG_FILE}"
rm -rf "${NOOBS_DIR}"
-PARTED_OUT=$(parted -sm "${IMG_FILE}" unit b print)
-BOOT_OFFSET=$(echo "$PARTED_OUT" | grep -e '^1:' | cut -d':' -f 2 | tr -d B)
-BOOT_LENGTH=$(echo "$PARTED_OUT" | grep -e '^1:' | cut -d':' -f 4 | tr -d B)
-
-ROOT_OFFSET=$(echo "$PARTED_OUT" | grep -e '^2:' | cut -d':' -f 2 | tr -d B)
-ROOT_LENGTH=$(echo "$PARTED_OUT" | grep -e '^2:' | cut -d':' -f 4 | tr -d B)
-
-echo "Mounting BOOT_DEV..."
-cnt=0
-until BOOT_DEV=$(losetup --show -f -o "${BOOT_OFFSET}" --sizelimit "${BOOT_LENGTH}" "${IMG_FILE}"); do
- if [ $cnt -lt 5 ]; then
- cnt=$((cnt + 1))
- echo "Error in losetup for BOOT_DEV. Retrying..."
- sleep 5
- else
- echo "ERROR: losetup for BOOT_DEV failed; exiting"
- exit 1
- fi
-done
-
-echo "Mounting ROOT_DEV..."
+echo "Creating loop device..."
cnt=0
-until ROOT_DEV=$(losetup --show -f -o "${ROOT_OFFSET}" --sizelimit "${ROOT_LENGTH}" "${IMG_FILE}"); do
+until LOOP_DEV="$(losetup --show --find --partscan "$IMG_FILE")"; do
if [ $cnt -lt 5 ]; then
cnt=$((cnt + 1))
- echo "Error in losetup for ROOT_DEV. Retrying..."
+ echo "Error in losetup. Retrying..."
sleep 5
else
- echo "ERROR: losetup for ROOT_DEV failed; exiting"
+ echo "ERROR: losetup failed; exiting"
exit 1
fi
done
-echo "/boot: offset $BOOT_OFFSET, length $BOOT_LENGTH"
-echo "/: offset $ROOT_OFFSET, length $ROOT_LENGTH"
+BOOT_DEV="${LOOP_DEV}p1"
+ROOT_DEV="${LOOP_DEV}p2"
mkdir -p "${STAGE_WORK_DIR}/rootfs"
mkdir -p "${NOOBS_DIR}"
diff --git a/scripts/common b/scripts/common
index 42e4f8a..1bb68a2 100644
--- a/scripts/common
+++ b/scripts/common
@@ -58,19 +58,15 @@ export -f unmount
unmount_image(){
sync
sleep 1
- local LOOP_DEVICES
- LOOP_DEVICES=$(losetup --list | grep "$(basename "${1}")" | cut -f1 -d' ')
- for LOOP_DEV in ${LOOP_DEVICES}; do
- if [ -n "${LOOP_DEV}" ]; then
- local MOUNTED_DIR
- MOUNTED_DIR=$(mount | grep "$(basename "${LOOP_DEV}")" | head -n 1 | cut -f 3 -d ' ')
- if [ -n "${MOUNTED_DIR}" ] && [ "${MOUNTED_DIR}" != "/" ]; then
- unmount "$(dirname "${MOUNTED_DIR}")"
+ LOOP_DEVICE=$(losetup --list | grep "$1" | cut -f1 -d' ')
+ if [ -n "$LOOP_DEVICE" ]; then
+ for part in "$LOOP_DEVICE"p*; do
+ if DIR=$(findmnt -n -o target -S "$part"); then
+ unmount "$DIR"
fi
- sleep 1
- losetup -d "${LOOP_DEV}"
- fi
- done
+ done
+ losetup -d "$LOOP_DEVICE"
+ fi
}
export -f unmount_image