From: Guido Trotter Date: Mon, 26 Jan 2009 12:19:31 +0000 (+0000) Subject: Use losetup rather than -o loop X-Git-Tag: v0.6~2 X-Git-Url: http://git.equinoxoli.org/?p=ext%2Finstance-debootstrap.git;a=commitdiff_plain;h=4382575861c628a3c7ce42eece16fadb5b92c32a Use losetup rather than -o loop If the device we're given is actually a file, rather than just mounting it with the -o loop option, we'll explicitely losetup it to a device, and losetup -d (detach) it at the end. This allows us to do more actions on the target device (for example partition it, if needed). Reviewed-by: iustinp --- diff --git a/create.in b/create.in index 7840789..cbe3ae4 100755 --- a/create.in +++ b/create.in @@ -62,6 +62,14 @@ CACHE_FILE="$CACHE_DIR/cache-${SUITE}-${DPKG_ARCH}.tar" . common.sh +# If the target device is not a real block device we'll first losetup it. +# This is needed for file disks. +if [ ! -b $blockdev ]; then + ORIGINAL_BLOCKDEV=$blockdev + blockdev=$(losetup -sf $blockdev) + CLEANUP+=("losetup -d $blockdev") +fi + mke2fs -Fjq $blockdev root_uuid=$($VOL_ID -u $blockdev ) if [ -n "$swapdev" ]; then @@ -72,13 +80,7 @@ fi TMPDIR=`mktemp -d` || exit 1 CLEANUP+=("rmdir $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 +mount $blockdev $TMPDIR CLEANUP+=("umount $TMPDIR") # remove the cache file if it's old (> 2 weeks) and writable by the owner (the