Skip to content

Commit

Permalink
Fix handling loop devices
Browse files Browse the repository at this point in the history
  • Loading branch information
igorpecovnik committed Jan 8, 2025
1 parent ef0a4a3 commit 5cc3e2e
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions lib/functions/image/partitioning.sh
Original file line number Diff line number Diff line change
Expand Up @@ -245,26 +245,22 @@ function prepare_partitions() {
echo "${partition_script_output}" | run_host_command_logged sfdisk "${SDCARD}".raw || exit_with_error "Partitioning failed!"
fi

declare -g LOOP
call_extension_method "post_create_partitions" <<- 'POST_CREATE_PARTITIONS'
*called after all partitions are created, but not yet formatted*
POST_CREATE_PARTITIONS

# stage: mount image
# lock access to loop devices
if [[ -z $LOOP ]]; then
exec {FD}> /var/lock/armbian-debootstrap-losetup
flock -x $FD

LOOP=$(losetup -f)
[[ -z $LOOP ]] && exit_with_error "Unable to find free loop device"
display_alert "Allocated loop device" "LOOP=${LOOP}"
check_loop_device "${LOOP}"
losetup $LOOP ${SDCARD}.raw

# loop device was grabbed here, unlock
flock -u $FD
fi
exec {FD}> /var/lock/armbian-debootstrap-losetup
flock -x $FD

declare -g LOOP
#--partscan is using to force the kernel for scaning partition table in preventing of partprobe errors
LOOP=$(losetup --show --partscan --find "${SDCARD}".raw) || exit_with_error "Unable to find free loop device"
display_alert "Allocated loop device" "LOOP=${LOOP}"

# loop device was grabbed here, unlock
flock -u $FD

display_alert "Running partprobe" "${LOOP}" "debug"
run_host_command_logged partprobe "${LOOP}"
Expand Down

0 comments on commit 5cc3e2e

Please sign in to comment.