Chapter 14. Qemu

Table of Contents

1. Network settings
2. Running Qemu to test a new kernel
3. Running VM as deamon with VNC
4. Running VMs with TAP network
5. Running Qemu with ncurses library
6. Ultimate Qemu script with VIRTIO
7. Kernel configuration

1. Network settings

First, create a bridge device. Edit the script bridge.sh:

#!/usr/bin/ksh

# Configure a bridge device to use with qemu

# Bridged interface
if=eth0

# Bridge name
bridge=br0

# Bridge network
address=192.168.1.7
netmask=255.255.255.0
gateway=192.168.1.1
broadcast=192.168.1.255

case $1 in
  start)
    print "Configure $bridge bridge..."
    brctl addbr $bridge

    print "Add $if on $bridge..."
    brctl addif $bridge $if

    print "Activating promiscuous mode on $if..."
    ip addr flush dev $if
    ip link set $if promisc on
    ip link set up dev $if

    print "IP address on $bridge..."
    ip addr add $address/$netmask broadcast $broadcast dev $bridge 
    ip link set $bridge up

    print "Set default route..."
    ip route add default via $gateway
  ;;
  stop)
    ip link set $bridge down
    brctl delbr $bridge
    ip addr flush dev $if
    ip link set $if promisc off
    ip link set down dev $if
  ;;
  *)
    print -u2 "usage: $0 start|stop"
    exit 1
  ;;
esac

exit 0
        

Run the script to create the bridge:

./bridge.sh start

Then, edit the script that will add the qemu tap device on the bridge (/etc/qemu-ifup):

#!/usr/bin/ksh

tap=$1

bridge=br0

# put the $tap interface up
ip link set up dev $tap

# adding $tap to bridge interface $bridge...
brctl addif $bridge $tap

exit 0
        

You can now run qemu with tap network interfaces.