Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

James Robertson http://www.r0bertson.co.uk

« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS 

Launch Windows XP with Qemu

This code worked under Ubuntu Server 7.4, using Qemu and a Windows XP image file.

# Starts up QEmu with various options

# Variables
set -o errexit
SOUND="-soundhw es1370"
MEMORY="-m 330"
TIME="-localtime"
IMGPATH="/mnt/data/virtual/xp"
IMG=$1
USERID=`whoami`

# need to make sure we have read/write access to the  device at /dev/net/tun
echo "Using sudo too to setup /dev/net/tun..."
sudo chown root:$USERID /dev/net/tun
sudo chmod g+rw /dev/net/tun
# now be sure that IP forwarding and masquerading are good to go
echo "Need root password to setup IP forwarding..."
su -c "echo '1' > /proc/sys/net/ipv4/ip_forward"
echo "Done being root..."
sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

# Create tap interface so that the script /etc/qemu-ifup can bridge it
# before qemu starts
echo "Using sudo to setup the tap interface..."
IFACE=`sudo tunctl -b -u $USERID`

NET="-net nic,vlan=0 -net tap,vlan=0,ifname=$IFACE,script=/etc/qemu-ifup"

# QEmu start
qemu ${SOUND} ${TIME} ${MEMORY} ${IMG} ${NET} -usb


# QEmu has stopped - no longer using tap interface
sudo tunctl -d $IFACE &> /dev/null

# user no longer needs read/write on /dev/net/tun
sudo chown root:root /dev/net/tun



after script execution I run this 'sudo ifconfig tap0 192.168.1.6'
when the script is finished I run this 'sudo tunctl -d tap0'
« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS