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

« Newer Snippets
Older Snippets »
Showing 1-2 of 2 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'

use qemu on ubuntu linux

you must install qemu first ... run this :
sudo apt-get install qemu

then create a virtual filesystem (to simulate a hdd) (1000000 = 10go), under your home directory
dd of=hd.img bs=1024 seek=1000000 count=0

put a bootable cd (or an "iso-file") in your cd drive (win2k, xp, linux live-cd, ...), and run
qemu -hda /home/[your_name]/hd.img -cdrom /dev/hdd -boot d -m 512 -user-net

option -hda = the virtual disk to use (~/hd.img)
option -m = memory to use (512 mo).
option -cdrom = cd-drive (/dev/hdd for me) (or an iso file)
option -boot = which drive to boot (d as the cdrom)
option -user-net : net user mode (see http://fabrice.bellard.free.fr/qemu/qemu-doc.html#SEC21)

and it's run like a charm ...impressive
« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS