I want to create a virtual disc (VMDK) using shell script on Debian. I use Java ProcessBuilder
for executing following batches:
Script 1:
dd if=/dev/zero bs=1G count=0 seek=4 of=disc
echo n.p.1...p.w.|sed 's/\./\n/g'|fdisk disc
kpartx -av disc
mkfs.ext3 /dev/mapper/loop0p1
mount /dev/mapper/loop0p1 /mnt/tmp
Script 2:
umount /mnt/tmp
kpartx -dv disc
qemu-img convert -f raw -O vmdk disc new-disc.vmdk
But I have problem in script 1 with line
mkfs.ext3 /dev/mapper/loop0p1
once it works fine - filesystem is successfully created, disc is mounted... but each second time the script ends with error code 1, but with no message. These two results are changing exact periodically.
I have the same result if I use Java ProcessBuilder
for each command. Once it works, second time it does not.
If I wait between commands
kpartx -av disc
and
mkfs.ext3 /dev/mapper/loop0p1
it works always properly. "I wait" means I use
sleep 1
in shell,
Thread.sleep(1000);
in java or I put breakpoint onto exec line and resume run manually. If I run batches manually from command prompt, it also works fine.
Does anyone have any idea why am I getting this behaviour?