From 7772883381759f47e8d1bfb95ea9de660e92bd87 Mon Sep 17 00:00:00 2001 From: zador-blood-stained Date: Wed, 14 Dec 2016 15:17:13 +0300 Subject: [PATCH] Improve reliability of image creation in build-all --- debootstrap-ng.sh | 10 +++++++++- general.sh | 4 ++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/debootstrap-ng.sh b/debootstrap-ng.sh index a9a7be069..1ed382886 100644 --- a/debootstrap-ng.sh +++ b/debootstrap-ng.sh @@ -374,14 +374,22 @@ prepare_partitions() fi # stage: mount image - # TODO: Needs mknod here in Docker? + # lock access to loop devices + exec {FD}>/var/lock/armbian-debootstrap-losetup + flock --verbose -x $FD | tee -a $DEST/debug/output.log + LOOP=$(losetup -f) [[ -z $LOOP ]] && exit_with_error "Unable to find free loop device" # NOTE: losetup -P option is not available in Trusty [[ $CONTAINER_COMPAT == yes && ! -e $LOOP ]] && mknod -m0660 $LOOP b 7 ${LOOP//\/dev\/loop} > /dev/null + # TODO: Needs mknod here in Docker? losetup $LOOP $CACHEDIR/${SDCARD}.raw + + # loop device was grabbed here, unlock + flock -u $FD + partprobe $LOOP # stage: create fs, mount partitions, create fstab diff --git a/general.sh b/general.sh index 3f0019b26..69054603c 100644 --- a/general.sh +++ b/general.sh @@ -91,6 +91,10 @@ exit_with_error() display_alert "Process terminated" "" "info" # TODO: execute run_after_build here? overlayfs_wrapper "cleanup" + # unlock loop device access in case of starvation + exec {FD}>/var/lock/armbian-debootstrap-losetup + losetup -u $FD + exit -1 }