3 # =============================================================================
8 # =============================================================================
11 # Make sure you have the rights to run SUDO. Otherwise, this script will not
13 # =============================================================================
15 ###############################################################################
17 ###############################################################################
19 # Directory where VDE and QEMU are installed
20 # Only needed when not in path or when you want to override
21 #VDEROOT="/usr/local/bin/"
22 #QEMUROOT="/usr/local/bin/"
24 # The network info for tun0 (private interface)
26 PRIVATE_NETMASK="255.255.255.0"
28 # The network info for tun1 (public interface)
29 PUBLIC_IP="172.20.0.1"
30 PUBLIC_NETMASK="255.255.0.0"
32 # The default memory size
35 # The default #CPUS size
38 # By default do not specify the disk, cdrom, floppy, or boot
47 # If VDE is off, use tap/tun by default. Otherwise use ``user''.
51 # Which QEMU executable to use
52 #QEMUEXE="qemu-system_x86_64"
57 ###############################################################################
59 # Please, DO NOT modify anything below this line, unless you know what you are
61 ###############################################################################
64 function network_set {
65 if [[ ! -z ${NETWORK_SET} ]]; then
66 echo "Don't mix -u, -v, -t. Use only one"
71 function image_check {
73 if [[ ! -w ${IMG} ]]; then
74 echo "The disk image '${IMG}' doesn't exist or not writtable"
79 function kill_or_start_vde {
80 # For good measure, let's kill all the existing vde_switch(es)
81 if [[ -S /tmp/private.ctl && -S /tmp/public.ctl ]]; then
82 echo -n "Existing public and private switches found. Kill them?(yes or no) "
85 if [[ ${KILLTHEM} == "yes" ]]; then
87 elif [[ ${KILLTHEM} == "no" ]]; then
88 echo "You are exposing weakness ..."
95 function create_switches {
96 sudo killall -9 vde_switch
97 echo "Creating new sockets ..."
98 # Create the private switch
99 sudo ${VDEROOT}vde_switch -tap tun0 \
100 -sock /tmp/private.ctl -daemon
101 # Create the public switch
102 sudo ${VDEROOT}vde_switch -tap tun1 \
103 -sock /tmp/public.ctl -daemon
104 # Correct the permissions
105 sudo chmod 666 /tmp/private.ctl
106 sudo chmod 666 /tmp/public.ctl
107 # Setting up network info
108 sudo ifconfig tun0 ${PRIVATE_IP} netmask ${PRIVATE_NETMASK}
109 sudo ifconfig tun1 ${PUBLIC_IP} netmask ${PUBLIC_NETMASK}
110 # Turn on ip forwarding and set up IPTABLE
111 sudo sysctl -w net.ipv4.ip_forward=1
112 # Disable IPTABLES first
113 sudo /etc/init.d/iptables stop
114 # XXX Define some rules.
115 sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
116 sudo /etc/init.d/iptables save
117 sudo /etc/init.d/iptables start
120 ###############################################################################
122 ###############################################################################
125 echo `basename $0` "file"
126 echo " start qemu with file as hard disk 0 image"
128 echo " Boot on floppy (a), hard disk (c) or CD-ROM (d). Hard disk boot is the default."
130 echo " Use file as CD-ROM image. You can use the host CD-ROM by using /dev/cdrom as filename."
132 echo " Use file as fda floppy disk image. You can use the host floppy by using /dev/fd0 as filename."
134 echo " Set virtual RAM size to megs megabytes. Default is ${MEGS} MB."
136 echo " Set the number of CPUs. Default is ${CPUS} MB."
137 echo "-n [user|tap|vde]"
138 echo " vde == VDE based networking. (default = ON)"
139 echo " tap == tun/tap networking. (default = OFF)"
140 echo " user == user mode stack for networking. (default = OFF)"
142 echo " Set the mac address of the nic to specified mac"
144 echo " load vm snapshot"
146 echo " Multihome this machine"
148 echo " serial console"
152 MAC="52:54:00:12:34:56"
155 while getopts "b:c:f:l:m:n:s:hp:ox" opt ; do
175 [ "${TYPE}" != "${OPTARG}" ] && NETWORK_SET="yes"
201 shift $(($OPTIND - 1))
203 if [ -z "$DISK1" ]; then
215 if [ ! -z "${CDROM}" -a ! -z "${DISK4}" ]; then
216 echo "canot specify cdrom and 4th ide drive (${DISK4})"
220 echo "Checking if the kqemu module is loaded ..."
221 module=$(lsmod | grep kqemu | awk '{print $1}')
223 if [[ ${module} == "" ]]; then
224 echo "Loading kqemu module ... "
226 [[ $? != 0 ]] && exit 1
228 elif [[ ${module} == "kqemu" ]]; then
229 echo "kqemu already loaded. Continue ..."
232 if [ ! -c /dev/kqemu ] ; then
233 mknod /dev/kqemu c 250 0
237 QEMU_CMD="${QEMUROOT}${QEMUEXE} ${GRAPHIC} -m ${MEGS} -smp ${CPUS}"
238 [ ! -z "${SNAPSHOT}" ] && QEMU_CMD="${QEMU_CMD} -loadvm ${SNAPSHOT}"
239 [ ! -z "${FLOPPY}" ] && QEMU_CMD="${QEMU_CMD} -fda ${FLOPPY}"
240 [ ! -z "${CDROM}" ] && QEMU_CMD="${QEMU_CMD} -cdrom ${CDROM}"
241 [ ! -z "${BOOT}" ] && QEMU_CMD="${QEMU_CMD} -boot ${BOOT}"
243 [ ! -z "${DISK1}" ] && QEMU_CMD="${QEMU_CMD} -hda ${DISK1}"
244 [ ! -z "${DISK2}" ] && QEMU_CMD="${QEMU_CMD} -hdb ${DISK2}"
245 [ ! -z "${CDROM}" -a ! -z "${DISK3}" ] && QEMU_CMD="${QEMU_CMD} -hdd ${DISK3}"
246 [ -z "${CDROM}" -a ! -z "${DISK3}" ] && QEMU_CMD="${QEMU_CMD} -hdc ${DISK3}"
250 QEMU_CMD="${VDEROOT}vdeq ${QEMU_CMD}"
251 echo "Running with VDE ..."
253 QEMU_CMD="${QEMU_CMD} -net nic,vlan=0,macaddr=${MAC}"
254 QEMU_CMD="${QEMU_CMD} -net vde,vlan=0,sock=/tmp/private.ctl"
255 if [ "${MULTIHOMED}" == "yes" ]; then
256 QEMU_CMD="${QEMU_CMD} -net nic,vlan=1"
257 QEMU_CMD="${QEMU_CMD} -net vde,vlan=1,sock=/tmp/public.ctl"
261 echo "still have to fix code -- mef"
265 QEMU_CMD="${QEMU_CMD} -net nic -net user"
268 echo "invalid networking type"
272 # Executing frontend.
274 if [ -z "${GRAPHIC}" ]; then