From 21efeb67950882fd28ea5b44943fa8401102ad70 Mon Sep 17 00:00:00 2001 From: Balint Reczey Date: Fri, 21 Apr 2017 18:40:19 +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. --- debian/changelog | 5 +++++ live-build/functions | 15 ++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/debian/changelog b/debian/changelog index a8803db5..e24e9fed 100644 --- a/debian/changelog +++ b/debian/changelog @@ -5,6 +5,11 @@ livecd-rootfs (2.442) UNRELEASED; urgency=medium comparison prior to aa-series (LP: #1681548) * live-build/ubuntu-cpc/hooks/999-extras.binary: Exit on first failure + [Balint Reczey] + * sync before calling kpartx to let writing to loop devices finish + * Work around kpartx's nonzero exit due to "Device or resource busy" errors + which still permit kpartx to finally remove loop device (LP: #1684090) + -- Steve Langasek Thu, 13 Apr 2017 10:38:04 -0700 livecd-rootfs (2.441) zesty; urgency=medium diff --git a/live-build/functions b/live-build/functions index 5abdeea1..c72c59a2 100644 --- a/live-build/functions +++ b/live-build/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