Improve check for identifying underlying block device
authorMichael Prokop <mika@grml.org>
Thu, 4 Jun 2015 07:56:22 +0000 (09:56 +0200)
committerMichael Prokop <mika@grml.org>
Thu, 4 Jun 2015 07:56:22 +0000 (09:56 +0200)
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

index ca4172b..a3db195 100755 (executable)
@@ -995,10 +995,19 @@ mkfs() {
 
     # make sure /dev/disk/by-uuid/... is up2date, otherwise grub
     # will fail to detect the uuid in the chroot
 
     # 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}"
       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 :-/
     fi
     # give the system 2 seconds, otherwise we might run into
     # race conditions :-/