Actually, much of the time I don't use AQemu. I usually do it with bash scripts. Here is an example of one I use. It doesn't do the nice thing of reading the parameters from a file. There are some bash scripts I have that do use separate configuration files, but they're usually geared to some of my specialized setups.
This one starts a VM in a nice SDL window. Sorry, there's not much more documentation than the variable names. I edited out my own particular instance and path names. This VM instance starts without a bootloader, so here you can see an example of that.
Note that I have the VM images in a separate LVM partition mounted at /var/kvm. You can suit yourself.
Code: Select all
#!/bin/bash
# Start [fill in your host name here] on KVM
SERVER_NAME=[fill in a name]
#PIDFILE=/var/run/kvm/if_I_want_a_pid_file.pid
SMP='cores=2'
KERNEL=/var/kvm/myhost/boot/vmlinuz-gentoo-virtio
KERNEL_PARMS='root=/dev/vda5 fbcon=scrollback:128k video=vesafb vga=0x317 res=1280x1024 clock=pit'
NIC_MODEL=virtio
TAPNAME=tap_myhost
MACADDR=12:34:56:78:90:12
NET=( "tap,model=virtio,macaddr=${MACADDR},helper=/usr/libexec/qemu-bridge-helper" )
DRIVE=( 'if=virtio,file=/var/kvm/myhost/main.img' )
VGA=cirrus
SOUNDHW=hda
QEMU_AUDIO_DRV=alsa
#VNC=:1
#USBDEVICE=tablet
#CONSOLE='-curses'
#SCREEN_SESSION=vm_console
MONITOR=telnet::60001,server,nowait
ECHO_COMMAND=1
# You should not need to adjust these two:
KVM_EXEC='/usr/bin/qemu-system-x86_64 -enable-kvm'
SCREEN_EXEC=/usr/bin/screen
#
## END OF CONFIGURATION ##
#
NIC_MODEL="${NIC_MODEL:-virtio}"
CMD="$KVM_EXEC -name $SERVER_NAME"
for i in $(seq 0 $((${#DRIVE[@]} - 1)))
do
CMD="$CMD -drive ${DRIVE[$i]}"
done
for i in $(seq 0 $((${#NET[@]} - 1)))
do
setup="${NET[$i]}"
hw_side=nic,vlan=$i
sw_side="${setup%%,*},vlan=$i"
setup="${setup#*,}"
while [ -n "$setup" ]; do
pair="${setup%%,*}"
setup="${setup:${#pair} + 1}"
var="${pair%%=*}"
if [ 'macaddr' = "$var" -o 'model' = "$var" \
-o 'name' = "$var" -o 'addr' = "$var" ]; then
hw_side="$hw_side,$pair"
else
sw_side="$sw_side,$pair"
fi
done
CMD="$CMD -net $hw_side -net $sw_side"
done
if [ -n "$KERNEL" ]; then
CMD="$CMD -kernel $KERNEL"
if [ -n "$KERNEL_PARMS" ]; then
CMD="$CMD -append "'\"'${KERNEL_PARMS}'\"'
fi
fi
if [ -n "$PIDFILE" ]; then
CMD="$CMD -pidfile $PIDFILE"
piddir=`dirname "$PIDFILE"`
if [ ! -d "$piddir" ]; then
mkdir -p "$piddir"
fi
fi
if [ -n "$SMP" ]; then
CMD="$CMD -smp $SMP"
fi
if [ -n "$SOUNDHW" ]; then
CMD="$CMD -soundhw "'\"'${SOUNDHW}'\"'
fi
if [ -n "$QEMU_AUDIO_DRV" ]; then
# Grumble, grumble: they need this passed in the environment
CMD="QEMU_AUDIO_DRV='$QEMU_AUDIO_DRV' $CMD"
fi
if [ -n "$VGA" ]; then
CMD="$CMD -vga $VGA"
fi
if [ -n "$CONSOLE" ]; then
CMD="$CMD $CONSOLE"
fi
if [ -n "$MONITOR" ]; then
CMD="$CMD -monitor $MONITOR"
fi
if [ -n "$VNC" ]; then
CMD="$CMD -vnc $VNC"
fi
if [ -n "$USBDEVICE" ]; then
CMD="$CMD -usbdevice $USBDEVICE"
fi
if [ -n "$SCREEN_SESSION" ]; then
CMD="$SCREEN_EXEC -d -m -S "$SCREEN_SESSION" $CMD"
fi
if [ "$ECHO_COMMAND" -ne 0 ]; then
echo $CMD
fi
eval $(eval "echo $CMD")
I hope you can get some good stuff out of it.