4. Running VMs with TAP network

And without VNC:

#!/usr/bin/ksh

root=$(cd $(dirname $(readlink -f $0))/..; pwd)

vm_name=$(basename $0 .sh)

img=$root/vmdisk/$vm_name.img

pidfile=$root/vmdisk/$vm_name.pid

qemu=/usr/kvm/bin/qemu-system-x86_64

mac=$(print $vm_name | md5sum | \
  sed 's/^\(..\)\(..\)\(..\)\(..\).*$/52:54:\1:\2:\3:\4/')

[ ! -f "$img" ] && qemu-img create $img 10G

case $1 in
  install)
    $qemu -boot d -hda $img \
      -cdrom $root/iso/wakes-alpha1-001-i386.iso
  ;;
  start)
    $qemu -boot c -hda $img -pidfile $pidfile \
      -net nic,vlan=0,macaddr=$mac \
      -net tap,vlan=0,ifname=$vm_name,script=/etc/qemu-ifup 
  ;;
  stop)
    kill $(cat $pidfile)
    rm $pidfile
  ;;
  *)
    print -u2 "usage: $0 install|start|stop"
    exit 1
  ;;
esac

exit 0