From 3814da0657651b293b7e3ef81ef581ca493e1f7d Mon Sep 17 00:00:00 2001 From: Michael Prokop Date: Thu, 4 Jun 2015 09:56:22 +0200 Subject: [PATCH] Improve check for identifying underlying block device There's no point in trying to read the partition table for e.g. /dev/loop if we get /dev/loop0. Fixes #42 @ github Closes: #771192 --- grml-debootstrap | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/grml-debootstrap b/grml-debootstrap index ca4172b..a3db195 100755 --- a/grml-debootstrap +++ b/grml-debootstrap @@ -995,10 +995,19 @@ mkfs() { # make sure /dev/disk/by-uuid/... is up2date, otherwise grub # will fail to detect the uuid in the chroot - if echo "$TARGET" | grep -q "/dev/md" ; then + if [ -n "$VIRTUAL" ] ; then + einfo "Virtual environment doesn't require blockdev --rereadpt, skipping therefore" + elif echo "$TARGET" | grep -q "/dev/md" ; then blockdev --rereadpt "${TARGET}" - elif ! [ -n "$VIRTUAL" ] ; then - blockdev --rereadpt "${TARGET%%[0-9]*}" + else + # if we deploy to /dev/sdX# then let's see if /dev/sdX exists + local main_device="${TARGET%%[0-9]*}" + # sanity check to not try to e.g. access /dev/loop if we get /dev/loop0 + if [ -f "/sys/block/$(basename ${main_device})/$(basename ${TARGET})/dev" ] ; then + blockdev --rereadpt "$main_device" + else + einfo "No underlying block device for $TARGET identified, skipping blockdev --rereadpt." + fi fi # give the system 2 seconds, otherwise we might run into # race conditions :-/ -- 2.1.4