Modify os scripts to mount file disks correctly
authorManuel Franceschini <manuel.franceschini@gmail.com>
Mon, 30 Jun 2008 14:58:51 +0000 (14:58 +0000)
committerManuel Franceschini <manuel.franceschini@gmail.com>
Mon, 30 Jun 2008 14:58:51 +0000 (14:58 +0000)
This patch adds a conditional statement before mounting the with -b
given device to detect if it is a block device or a regular file. In the
former case it mounts it regularly, in the latter it tries to mount it
via loopback device.

Reviewed-by: iustinp

create
import
rename

diff --git a/create b/create
index 9bede89..562fa7d 100755 (executable)
--- a/create
+++ b/create
@@ -54,7 +54,14 @@ mkswap $swapdev
 mke2fs -Fjq $blockdev
 TMPDIR=`mktemp -d` || exit 1
 trap "umount $TMPDIR; rmdir $TMPDIR" EXIT
-mount $blockdev $TMPDIR
+
+# If it's not a block device try to mount it via loopback device.
+# This is needed for file disks.
+MOUNT_OPTIONS=""
+if [ ! -b $blockdev ]; then
+  MOUNT_OPTIONS="$MOUNT_OPTIONS -o loop"
+fi
+mount $MOUNT_OPTIONS $blockdev $TMPDIR
 
 # remove the cache file if it's old (> 2 weeks) and writable by the owner (the
 # default due to the standard umask)
diff --git a/import b/import
index 2803756..a287644 100755 (executable)
--- a/import
+++ b/import
@@ -48,7 +48,15 @@ mkswap $swapdev
 mke2fs -Fjq $blockdev
 TMPDIR=`mktemp -d` || exit 1
 trap "umount $TMPDIR; rmdir $TMPDIR" EXIT
-mount $blockdev $TMPDIR
+
+# If it's not a block device try to mount it via loopback device.
+# This is needed for file disks.
+MOUNT_OPTIONS=""
+if [ ! -b $blockdev ]; then
+  MOUNT_OPTIONS="$MOUNT_OPTIONS -o loop"
+fi
+mount $MOUNT_OPTIONS $blockdev $TMPDIR
+
 ( cd $TMPDIR; restore -r -y -f - )
 rm -f $TMPDIR/etc/udev/rules.d/z25_persistent-net.rules
 umount $TMPDIR
diff --git a/rename b/rename
index 9c13ddd..66c5409 100755 (executable)
--- a/rename
+++ b/rename
@@ -48,7 +48,14 @@ fi
 
 TMPDIR=`mktemp -d` || exit 1
 trap "umount $TMPDIR; rmdir $TMPDIR" EXIT
-mount $blockdev $TMPDIR
+
+# If it's not a block device try to mount it via loopback device.
+# This is needed for file disks.
+MOUNT_OPTIONS=""
+if [ ! -b $blockdev ]; then
+  MOUNT_OPTIONS="$MOUNT_OPTIONS -o loop"
+fi
+mount $MOUNT_OPTIONS $blockdev $TMPDIR
 
 HNAME="$TMPDIR/etc/hostname"
 MNAME="$TMPDIR/etc/mailname"