The use of getopts was leading to conflicts between this script's short options and qemu's long options. For example -serial was getting interpreted as -s -- erial which is not very helpful.