1
diff --git a/lib/functions/image/partitioning.sh b/lib/functions/image/partitioning.sh
index a638410af..c12fe63a3 100644
--- a/lib/functions/image/partitioning.sh
+++ b/lib/functions/image/partitioning.sh
@@ -255,19 +255,41 @@ function prepare_partitions() {
        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
+       # First setup of the loop device
+       LOOP=$(losetup --show --partscan --find "${SDCARD}".raw) || exit_with_error "Unable to find free loop device"
+       display_alert "Allocated loop device (first setup)" "LOOP=${LOOP}" "debug"
+       ##
+       ## Additional mock device creation to force refresh of loop;
+       ## exclusively for Docker
+       display_alert "Checking if CONTAINER_COMPAT bool- " "$CONTAINER_COMPAT" "warn"
+
+       if [[ $CONTAINER_COMPAT == yes ]] then
+               display_alert "partprobe 1 targeting, then deleting" ${LOOP}
+               partprobe "${LOOP}"
+               sleep 1
+               losetup -d ${LOOP}
+               device=$(sudo losetup --show -f -P "${SDCARD}".raw) || { echo "Failed to setup loop device N" >&2; exit 1; }
+               display_alert "partprobe recreated device, targeting" ${LOOP}
+               partprobe
+               sleep 2
+               #check_devblock "$device"
+               dummy_device=$(sudo losetup --show -f -P "${SDCARD}".raw) || { echo "Failed to setup loop device N+1" >&2; exit 1; }
+               display_alert "partprobe 2 targeting all - $LOOP $dummy_device"
+               partprobe
+               sleep 1
+               #check_devblock "$dummy_device"
+               losetup -d "${dummy_device}"
+       fi
 
        display_alert "Running partprobe" "${LOOP}" "debug"
        run_host_command_logged partprobe "${LOOP}"
-
        display_alert "Checking again after partprobe" "${LOOP}" "debug"
        check_loop_device "${LOOP}" # check again, now it has to have a size! otherwise wait.
 
+       # loop device was grabbed here, unlock
+       flock -u $FD
+
        # stage: create fs, mount partitions, create fstab
        rm -f $SDCARD/etc/fstab

For immediate assistance, please email our customer support: [email protected]

Download RAW File