Qemu

From ConShell
(Redirected from Qemu Tips)
Jump to navigation Jump to search

QEMU is a popular open source machine emulator and virtualizer.

It is a decent alternative to VMware's products. It is also used as a component of hardware virtualization (HVM) in Xen.

It can emulate AMD64 (aka x86_64 or EM64T) without actually having that hardware. In general terms, it enables software development and packaging for other platforms.

Quick start

To begin working with qemu, install the packages for your operating system (see Qemu on Ubuntu for example).

Everything that follows is based on running Qemu on a Linux/UNIX host.

Now create a ~/qemu working folder.

cd ~
mkdir qemu
cd qemu/

Now create the virtual disk file with qemu-img.

qemu-img create -f qcow some-os.img 10G
Formatting 'some-os.img', fmt=qcow, size=10485760 kB

So now you have a 10G virtual disk in a file called some-os.img. Although the virtual disk can expand to 10G, it will only use what is needed to hold the data inside, so it starts very small.

-rw-r--r-- 1 mdf mdf 41008 2007-11-04 07:16 some-os.img

Now assuming you have some O/S installation CD or .iso lying around you can install that O/S.

So if you have a CD installation disc in /dev/hdc, the command you would run is:

qemu -cdrom /dev/scd0 -boot d some-os.img

Else if you have an .iso file for installation, the same function would be:

qemu -cdrom installer.iso -boot d some-os.img

Installing Windows 98

I'm installing Windows 98SE which needs a minimum of about 2G  for practical usage (this gives enough room to install the OS and a handful of applications).
qemu-img create -f qcow win98se.img 2G

OK, fire up qemu with the Win98SE installation cd in the CDROM drive (/dev/scd0).

qemu  -cdrom /dev/scd0 -boot d -m 128 win98se.img

Now shutdown and start with sound enabled and cdrom accessible

qemu -cdrom /dev/scd0 -m 128 -localtime -full-screen -enable-audio win98se.img

Networking

Newer versions of Qemu appear to have a number of different/new networking options via the -net flag. To emulate the old behavior I use these options:

sudo qemu -net nic -net tap ...rest of option...

This results in the host having a tap0 network interface created. tap0 Link encap:Ethernet HWaddr 00:FF:FF:2C:13:4B

         inet addr:172.20.0.1  Bcast:172.20.255.255  Mask:255.255.0.0
         inet6 addr: fe80::2ff:ffff:fe2c:134b/64 Scope:Link
         UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
         RX packets:6 errors:0 dropped:0 overruns:0 frame:0
         TX packets:33 errors:0 dropped:0 overruns:0 carrier:0
         collisions:0 txqueuelen:500 
         RX bytes:2052 (2.0 KB)  TX bytes:12236 (11.9 KB)

On the guest (FreeBSD) an ed0 device is detected, and it can (presumably) be assigned a static IP in the range of 172.20.0.2-255.

If no -net options are specified, then by default a DHCP server will be started (on the host). For example, my recently booted guest was assigned 10.0.2.15/24 as it's IP address, with a default gateway of 10.0.2.2. Also the name server 10.0.2.3 appears in /etc/resolv.conf. Both the gateway and the nameserver are provided by the Qemu host. However I could not ping past the host even after the following commands were run (on the host)...

iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
echo "1" >/proc/sys/net/ipv4/ip_forward

Related Items