If something else on the system is using loopback devices, then the
device that's free at the call to `losetup -f` may not be free in the
following call to try to use it. Instead, find and use the first free
loopback device in a single call to losetup.
Signed-off-by: Will Thompson <wjt@endlessm.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
mkdir -p "$MNTPOINTRO"
for i in $(range 0 $((NDEVICES-1)) 1); do
dd if=/dev/zero of="$FSIMAGEP${i}.img" count=1 bs=1 seek=$((DISKSIZE-1)) &> /dev/null
- LODEVICE="$(losetup -f)"
+ LODEVICE=$(losetup --find --show "$FSIMAGEP${i}.img")
LODEVICES="$LODEVICES $LODEVICE"
- losetup "$LODEVICE" "$FSIMAGEP${i}.img"
if test "$i" = 0; then
MOUNTDEVICE="$LODEVICE"
fi