Skip to content

Commit

Permalink
next try
Browse files Browse the repository at this point in the history
  • Loading branch information
swissiety committed Dec 20, 2024
1 parent 4f5a330 commit 6c401f2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
6 changes: 4 additions & 2 deletions lib/functions/image/loop.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ function check_loop_device_internal() {
if [[ $CONTAINER_COMPAT == yes && -b "/tmp/${device}" ]]; then
display_alert "Creating device node" "${device}"
run_host_command_logged mknod -m0660 "${device}" b "0x$(stat -c '%t' "/tmp/${device}")" "0x$(stat -c '%T' "/tmp/${device}")"
wait_for_disk_sync
if [[ ! -b "${device}" ]]; then # try again after creating node
return 1 # fail, it will be retried, and should exist on next retry.
else
Expand Down Expand Up @@ -106,7 +107,6 @@ function write_uboot_to_loop_image() {

# This exists to prevent silly failures; sometimes the user is inspecting the directory outside of build, etc.
function free_loop_device_insistent() {
wait_for_disk_sync
display_alert "Freeing loop device" "${1}"
do_with_retries 10 free_loop_device_retried "${1}"
}
Expand All @@ -115,5 +115,7 @@ function free_loop_device_retried() {
if [[ ${RETRY_RUNS} -gt 1 ]]; then
display_alert "Freeing loop device (try ${RETRY_RUNS})" "${1}"
fi
losetup -d "${1}"
# check if the device (still) exists / needs to be freed
[[ ! -f "${1}" ]] && return 0;
losetup -d "${1}" || (display_alert "losetup -d ${1} - return code:" "$?"; return 1)
}
10 changes: 8 additions & 2 deletions lib/functions/image/partitioning.sh
Original file line number Diff line number Diff line change
Expand Up @@ -252,15 +252,21 @@ function prepare_partitions() {

# stage: mount image
# lock access to loop devices
if [[ -z $LOOP ]]; then
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
run_host_command_logged losetup "${LOOP}" || true

losetup --partscan "${LOOP}" ${SDCARD}.raw

run_host_command_logged losetup "${LOOP}" || true

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

0 comments on commit 6c401f2

Please sign in to comment.