Skip to content

Commit

Permalink
Improve cleanup of loop devices
Browse files Browse the repository at this point in the history
kpartx (sometimes) does not cleanup the loop devices when deleting the
partition devmappings. This is a known bug, see Debian Bug #891077.

This is change is a possible workaround for that issue.

Now aborting grml-debootstrap is possible without leaving unneded loop
devices behind.
  • Loading branch information
jkirk committed Nov 14, 2018
1 parent 3eede4f commit 33d0e7f
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion grml-debootstrap
Expand Up @@ -298,7 +298,13 @@ cleanup() {

if [ -n "${ORIG_TARGET}" ] ; then
einfo "Removing loopback mount of file ${ORIG_TARGET}."
kpartx -d "${ORIG_TARGET}" ; eend $?
kpartx -d "${ORIG_TARGET}"
# Workaround for a bug in kpartx which doesn't clean up properly,
# see Debian Bug #891077 and Github-PR grml/grml-debootstrap#112
if dmsetup ls | grep -q "^${LOOP_PART} "; then
kpartx -d "/dev/${LOOP_DISK}" >/dev/null
fi
eend $?
fi
}

Expand Down Expand Up @@ -1432,6 +1438,7 @@ prepare_vm() {
# hopefully this always works as expected
LOOP_PART="${DEVINFO##add map }" # 'loop0p1 (254:5): 0 20477 linear 7:0 3'
LOOP_PART="${LOOP_PART// */}" # 'loop0p1'
LOOP_DISK="${LOOP_PART%p*}" # 'loop0'
export TARGET="/dev/mapper/$LOOP_PART" # '/dev/mapper/loop1p1'

if [ -z "$TARGET" ] ; then
Expand Down Expand Up @@ -1516,6 +1523,11 @@ fi
try_umount 3 "${MNTPOINT}"/dev
umount "${MNTPOINT}"
kpartx -d "${ORIG_TARGET}" >/dev/null
# Workaround for a bug in kpartx which doesn't clean up properly,
# see Debian Bug #891077 and Github-PR grml/grml-debootstrap#112
if dmsetup ls | grep -q "^${LOOP_PART} "; then
kpartx -d "/dev/${LOOP_DISK}" >/dev/null
fi
}
# }}}

Expand Down

0 comments on commit 33d0e7f

Please sign in to comment.