Skip to content

Commit 1519e8e

Browse files
committed
Fix #46
1 parent 9f2220b commit 1519e8e

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

src/common.sh

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,14 @@ function unpack() {
130130
fi
131131
}
132132

133+
function detach_all_loopback(){
134+
# Cleans up mounted loopback devices from the image name
135+
# NOTE: it might need a better way to grep for the image name, its might clash with other builds
136+
for img in $(losetup | grep $1 | awk '{ print $1 }' ); do
137+
losetup -d $img
138+
done
139+
}
140+
133141
function mount_image() {
134142
image_path=$1
135143
root_partition=$2
@@ -145,6 +153,8 @@ function mount_image() {
145153
echo "Mounting image $image_path on $mount_path, offset for boot partition is $boot_offset, offset for root partition is $root_offset"
146154

147155
# mount root and boot partition
156+
157+
detach_all_loopback $image_path
148158
sudo mount -o loop,offset=$root_offset $image_path $mount_path/
149159
if [[ "$boot_partition" != "$root_partition" ]]; then
150160
sudo mount -o loop,offset=$boot_offset,sizelimit=$( expr $root_offset - $boot_offset ) $image_path $mount_path/boot
@@ -237,7 +247,7 @@ $start
237247
p
238248
w
239249
FDISK
240-
250+
detach_all_loopback $image
241251
LODEV=$(losetup -f --show -o $offset $image)
242252
trap 'losetup -d $LODEV' EXIT
243253

0 commit comments

Comments
 (0)