From 20d7483fe03d38aaae11840912afd3aad60a078f Mon Sep 17 00:00:00 2001 From: Balint Reczey Date: Thu, 11 May 2017 16:17:13 +0200 Subject: [PATCH] Work around kpartx's nonzero exit due to "Device or resource busy" errors which still permit kpartx to finally remove loop device (LP: #1684090). Also sync before calling kpartx to let writing to loop devices finish. --- live-build/ubuntu-cpc/functions | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/live-build/ubuntu-cpc/functions b/live-build/ubuntu-cpc/functions index 6b2d69a0..7ed46906 100644 --- a/live-build/ubuntu-cpc/functions +++ b/live-build/ubuntu-cpc/functions @@ -11,9 +11,22 @@ backing_img= apt-get -qqy install dosfstools gdisk clean_loops() { + local kpartx_ret + local kpartx_stdout if [ -n "${backing_img}" ]; then - kpartx -v -d "${backing_img}" + # sync before removing loop to avoid "Device or resource busy" errors + sync + kpartx_ret="" + kpartx_stdout=$(kpartx -v -d "${backing_img}") || kpartx_ret=$? + echo "$kpartx_stdout" + if [ -n "$kpartx_ret" ]; then + if echo "$kpartx_stdout" | grep -q "loop deleted: "; then + echo "Suppressing kpartx returning error (#860894)" + else + exit $kpartx_ret + fi + fi unset backing_img fi