This script shows how you might generate a whole virtual machine, or a disk image for a virtual machine, starting with a tarball that contains the content for the machine.

The usage is:

tar2vm.sh input.tar.gz output.img 100M

where (for example) 100M is the size of the output disk image. You have to specify a size that is large enough to contain all the contents of the tarball, but not too large that there is too much wasted space (unless you want to give the VM extra working space of course).