Qemu processor, howto create virtual machine with qemu

In the need to make a virtual machine, like what we see with vmware.
there are a magic tool named qemu, it ‘s a free processor emulator created by
Fabrice Bellar.
well, to setup a new machine you have to prepare a partition image named linux.img,
in this example with 1024MB.

$ qemu-img create -f qcow linux.img 1G
place your distribution cd on your media and type :
$ qemu -boot d -cdrom /dev/cdrom -hda linux.img
After completing the system operating installation you can boot from the hard disk image.
$ qemu -hda linux.img -boot c

The example above don’t setup the network.
So, we can do it as following

$ qemu -hda linux.img -net nic -net tap -boot c

create a bash script with this contenent and make it executable.

#!/usr/bin/sudo -s
set -e
tunctl -u username -t tap0
ifconfig tap0 172.20.0.1 up

export LAN=tap0
export WAN=eth0
iptables -A FORWARD -i ${LAN} -s 172.20.0.0/255.255.255.0 -j ACCEPT
iptables -A FORWARD -i ${WAN} -d 172.20.0.0/255.255.255.0 -j ACCEPT
iptables -t nat -A POSTROUTING -o ${WAN} -j MASQUERADE

echo 1 > /proc/sys/net/ipv4/ip_forward
for f in /proc/sys/net/ipv4/conf/*/rp_filter ; do echo 1 > $f ; done

run it and enjoy !

Qemu processor, howto create virtual machine with qemu

3 thoughts on “Qemu processor, howto create virtual machine with qemu

  1. satria says:

    how to connect OS “ubuntu 9:10” as the host, with Qemu as a guest.?
    I can not connect from the host to geust, how to connect?
    I use Samba to connect the host to the guest.

    the answer to my email please
    thanks.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s