Qemu and other emulators

From Lazarus wiki
Revision as of 20:33, 14 May 2011 by MarkMLl (talk | contribs) (More detail)
Jump to navigationJump to search

This note covers setting up Qemu on an x86-based development system running Linux. This allows native (rather than cross) development tools to be run, which can be useful where the target system has performance/resource issues (e.g. some ARM systems), is not run natively due to company policy (older versions of Microsoft Windows) or is quite simply unavailable at a reasonable price (e.g. SGI MIPS systems). It also briefly mentions User Mode Linux and the Hercules emulator for IBM zSeries mainframes, it does not consider x86-on-x86 virtualisation systems such as VMware.

The Host System

In the current case, the host is a Compaq rack-mount server running at around 3GHz. It has two internal drive cages, the first is connected to a RAID controller and is used for the host operating system and tools, the second is connected to a SCSI controller and contains 6x discs each of which is used for a different guest system.

The host IP address is 192.168.1.22 and the system is named pye-dev-07, the default gateway and name server are on 192.168.1.1. Guest systems are on the 192.168.22.x subnet and are named pye-dev-07a (192.168.22.16), pye-dev-07b (192.168.22.17) and so on, they have their own gateway 192.168.22.1 which is known to the site router and firewalls.

The host operating system is Debian "Squeeze", the host normally runs headless and may be accessed by SSH, X using XDMCP, or VNC. The display manager is gdm since this has a better XDMCP than the alternatives, however in practice graphical login is most often handled by VNC.

The following guests are implemented:

pye-dev-07a
Debian on ARM (big-endian) using Qemu
pye-dev-07b
Debian on ARM (little-endian, armel) using Qemu
pye-dev-07c
Debian on MIPS (little-endian, mipsel) using Qemu
pye-dev-07d
Slackware 13.37 using User Mode Linux
pye-dev-07e
Windows 2K using Qemu
pye-dev-07f
Debian on zSeries using the Hercules emulator

In general, multiple guests can run simultaneously although this has not been exhaustively tested recently.

In the case of Linux the guest systems are each installed on an 18Gb disc, in the case of Windows a 38Gb disc is used. Each disc is assigned a label using e2label (arm, armel and so on), so that the startup script can mount it by name irrespective of which drive cage slot it's in.

Debian Guest using Qemu

Select a suitable Debian mirror and version, for example

 http://ftp.de.debian.org/debian/dists/squeeze/main/...

Fetch a kernel and initrd image for Debian Squeeze, as below.

For ARM (big-endian):

For ARM (little-endian):

For MIPS (little-endian):

.../main/installer-mipsel/current/images/malta/netboot/vmlinux-2.6.32-5-4kc-malta
.../main/installer-mipsel/current/images/malta/netboot/initrd.gz

Copy these to the disc reserved for the guest, e.g. /export/mipsel.

Create a filesystem for Qemu:

# qemu-img create -f qcow mipsel_hda.img 16G

Start Qemu, telling it what kernel, initrd and filesystem to use:

For ARM (big-endian):

For ARM (little-endian):

For MIPS (little-endian):

# qemu-system-mipsel -M malta -kernel vmlinux-2.6.32-5-4kc-malta -initrd initrd.gz \
-hda mipsel_hda.img -append "root=/dev/ram console=ttyS0" -nographic

Install the guest operating system as usual. Don't worry if it tells you it's not installing a loader- it's not needed.

Boot the operating system and set network addresses etc. Use 192.168.22.16 or similar, with a gateway of 192.168.22.1.

For ARM (big-endian):

For ARM (little-endian):

For MIPS (little-endian):

# qemu-system-mipsel -M malta -kernel vmlinux-2.6.32-5-4kc-malta \
-hda mipsel_hda.img -append "root=/dev/sda1 console=ttyS0" -nographic

Finally, you should be able to boot the operating system with an operational network. This relies on having /etc/qemu-ifup and /etc/qemu-ifdown files (see below), and passes additional parameters to them in shell variables. In outline:

For ARM (big-endian):

For ARM (little-endian):

For MIPS (little-endian):

# qemu-system-mipsel -M malta -m 256 -hda mipsel_hda.img \
-kernel vmlinux-2.6.32-5-4kc-malta \
-append 'root=/dev/sda1 console=ttyS0' -nographic \
-net nic,macaddr=00:16:3e:00:00:02 -net tap,ifname=tun2

Windows 2K Guest using Qemu

Common Qemu startup, ifup and ifdown scripts

These files are used by Qemu irrespective of whether the guest is running Linux or Windows.

First startup (e.g. /export/C):


Second startup for ARM (big-endian):

Second startup for ARM (little-endian):


Second startup for MIPS (little-endian):

# Routine startup of a Qemu guest relies on (the host) running /etc/qemu-ifup
# to condition ARP, forwarding etc.
QEMU_ID=2
QEMU='qemu-system-mipsel -M malta'
QEMU_RAM='-m 256'
QEMU_HD='-hda mipsel_hda.img'
QEMU_CD=
QEMU_BOOT="-kernel vmlinux-2.6.32-5-4kc-malta -append 'root=/dev/sda1 console=ttyS0'"
# QEMU_MONITOR='-monitor stdio -nographic'
QEMU_MONITOR='-nographic'
QEMU_VGA=
VNC_ID=$(($QEMU_ID+1))
# QEMU_VNC="-vnc :$VNC_ID -k en-gb"
QEMU_VNC=
QEMU_NET="-net nic,macaddr=00:16:3e:00:00:0$QEMU_ID -net tap,ifname=tun$QEMU_ID"
QEMU_GUEST_IP_ADDRESS=192.168.22.18
QEMU_GUEST_IP_GATEWAY=192.168.22.1
QEMU_HOST_GATEWAY_IF=eth1
export QEMU_GUEST_IP_ADDRESS QEMU_GUEST_IP_GATEWAY QEMU_HOST_GATEWAY_IF
echo \* $QEMU $QEMU_RAM $QEMU_HD $QEMU_CD $QEMU_BOOT \
       $QEMU_MONITOR $QEMU_VGA $QEMU_NET $QEMU_VNC
screen -S QEMU_$QEMU_ID \
sh -c "$QEMU $QEMU_RAM $QEMU_HD $QEMU_CD $QEMU_BOOT \
       $QEMU_MONITOR $QEMU_VGA $QEMU_NET $QEMU_VNC"
cd ..

/etc/ifup:




/etc/ifdown:




In actual fact, these operations were cribbed from User Mode Linux (below) where they are embedded inside a host library.

Slackware Guest using User Mode Linux

Debian Guest using Hercules