Skip to content

Loop devices are not removed because grep fails #345

@tabletseeker

Description

@tabletseeker

grep in dmsetup ls | grep -q "^${LOOP_PART} " fails because of this space ^${LOOP_PART} "

if dmsetup ls | grep -q "^${LOOP_PART} "; then

  if [ -n "${ORIG_TARGET}" ] ; then
    einfo "Removing loopback mount of file ${ORIG_TARGET}."
    kpartx -d "${ORIG_TARGET}" || eend $?
    # 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 || eend $?
    fi
  fi
++ printf ' %s*%s Removing loopback mount of file /home/user/test.img.\n' '' ''
 * Removing loopback mount of file /home/user/test.img.
++ LAST_E_CMD=einfon
++ return 0
++ return 0
++ kpartx -d /home/user/test.img
++ dmsetup ls
++ grep -q '^loop2p3 '
++ '[' -n 1 ']'
++ EXIT=1
++ '[' -n '' ']'
++ exit 1

Removing the space allows grep to work correctly and kpartx -d "/dev/${LOOP_DISK}" to be executed.

    if dmsetup ls | grep -q "^${LOOP_PART}"; then
      kpartx -d "/dev/${LOOP_DISK}" >/dev/null || eend $?
    fi

Test with /dev/loop2

dmsetup ls | grep '^loop2p3'; echo $?
loop2p3	(252:8)
0

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions