Working on an Amazon EC2 AMI for the Maemo SDK (scratchbox on Ubuntu)

I'll get into why I want to create this Amazon EC2 AMI thing later, but I thought I'd get information out there on a problem I'm having. Tve did a nice write-up on RightScale on bundling-up an ubuntu EC2 instance. This is a really helpful write-up, but I get a shell script error and a hang when I try to bundle my Ubuntu image.

root@domU-...:~# ec2-bundle-vol -d /mnt -k ~root/pk-....pem -c ~root/cert-....pem -u ...
Copying / into the image file /mnt/image...
1+0 records in
1+0 records out
1048576 bytes (1.0 MB) copied, 0.003492 seconds, 300 MB/s
mke2fs 1.39 (29-May-2006)
warning: 256 blocks unused.

Bundling image file...
sh: Syntax error: Bad substitution
The script keeps running. I don't know Ruby well, but the script seems to be stuck in a shell call to 'openssl'. This seems to occur in bundle.rb line 51. It looks like the 'tar' call on line 57 that is meant to feed the pipe being read by the running 'openssl' died, but I don't see where the "Bad substitution" might be.

Tve didn't have a place to make a comment on the blog entry. Time to debug...

Quick update on when I canceled the process (need to think if this confirms or denies what I was thinking):
sh: Syntax error: Bad substitution
sh: cannot open /tmp/bundleimage-pipe1: Interrupted system call
error executing tar -chS -C /mnt image | tee /tmp/bundleimage-pipe1 |gzip | openssl enc -e -aes-128-cbc -K ... -iv ... > /mnt/image.tar.gz.enc; for i in ${PIPESTATUS[@]}; do [ $i == 0 ] || exit $i; done, exit status code 2
ec2-bundle-vol failed
...need to take a break and get back to my real work.

Update #2: The problem turned out to be assumption in Amazon's Ruby script that 'bash' would be the shell executed by default. The answer was within a script found on the Amazon developer's forum. I've created my first image and I'll be hosting my script using Google's open source code repository when it is done at http://code.google.com/p/maemo-sdk-image/.


  1. Hi ,
    I am experiencing the "syntax error: bad subsitution" error when I use ec2-bundle-vol on ubuntu fiesty. In your post you were saying that you found the problem to be that the ruby script was assuming that the default shell is bash ... I checked and my shell is bash (echo $SHELL, or ps -fu root tell me that bash is running...)...so I am kinda lost.

    Could you please tell me how you solved the problem?

    Thanks in advance!

  2. Your personal shell may be 'bash', but Ruby will create a new shell. The shell script I published uses patches available on the Amazon forums. You can look at http://maemo-sdk-image.googlecode.com/svn/trunk/build_maemo_ami.sh in function patch-ubuntu. When the Ruby script calls the 'tar' program, the patch gets it to do that under a 'bash' shell.

    Let me know if this helps you.

  3. Hi jadon,

    thanks a lot for the reply! I looked at the link you provided, and I have solved the problem. Here is what I did...

    I replaced the lines in /usr/lib/site_ruby/aes/amiutil/bundle.rb

    tar -chS -C #{File::dirname( image_file )} #{File::basename( image_file )} | \
    "/bin/bash -c 'tar -chS -C #{File::dirname( image_file )} #{File::basename( image_file )} | \\


    for i in ${PIPESTATUS[@]}; do [ $i == 0 ] || exit $i; done"
    # for i in ${PIPESTATUS[@]}; do [ $i == 0 ] || exit $i; done' "

    and now it works!

    thanks once again