2

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?

J. Chomel
  • 8,193
  • 15
  • 41
  • 69
Daphnis
  • 437
  • 1
  • 5
  • 14
  • Maybe it's not `/dev/mapper/loop0p1` but something else every second time? Try turning on verbose mode and see if something helpful is printed `mkfs.ext3 -v /dev/mapper/loop0p1` or execute the command manually, maybe you're voiding stderr in your script and hide the messages – zapl Jun 09 '16 at 17:44
  • Thank you for response, actually I did not say one thing properly. If I run scripts above using `ProcessBuilder`, I get this weird behaviour - once OK, once not. But if I run it from the command prompt everything works fine. (I edit original question). And I am not able to get any output when I run batch using `ProcessBuilder`. – Daphnis Jun 10 '16 at 09:07
  • You should be able to do http://stackoverflow.com/questions/16134864/processbuilder-redirected-to-standard-output to see the output – zapl Jun 10 '16 at 09:18
  • Thank you for ideas. I spent too much time by trying to get some usable output but I was not able. Nevertheless my (not nice) solution is to put some wait code between these two commands. Namely between `kpartx -av ...` and `mount ...` command and also between `umonut ...` and `kpartx -dv ...`. This waiting solved my occasional errors. – Daphnis Aug 01 '16 at 12:15

0 Answers0