https://wiki.tudos.org/ikiw/api.php?action=feedcontributions&user=Benjamin&feedformat=atomTUDOS-Wiki - User contributions [en]2024-03-29T10:22:54ZUser contributionsMediaWiki 1.41.0https://wiki.tudos.org/ikiw/index.php?title=QEmu&diff=266QEmu2011-07-15T12:50:59Z<p>Benjamin: /* TFTP server */</p>
<hr />
<div>[http://fabrice.bellard.free.fr/qemu/ Qemu] is a PC emulator that can be<br />
used instead of a real PC to test your L4 applications. In order to boot<br />
something with Qemu we have to create a bootable device as we would for a real<br />
PC. You can, for instance, create a CD image to boot or you use a tftp server<br />
to load your binaries.<br />
<br />
The instructions specified here are for Qemu version 0.9.0. Other versions are<br />
mentioned explicitly.<br />
<br />
<br />
===CD image===<br />
<br />
Follow the instructions to [[CD image|create a CD image]] of your software. Once you<br />
obtained the image you can use it as the emulators CD drive (''-cdrom'') and<br />
tell Qemu to boot from it (''-boot d'').<br />
<br />
The full command line would be:<br />
<br />
qemu -cdrom /path/to/your/cd-image.iso -boot d<br />
<br />
===TFTP server===<br />
<br />
One of the nice feature of Qemu is its built-in TFTP server. The advantage of<br />
using a TFTP server to boot your software is that you do not have to recreate<br />
the CD image if something changes. You simple replace the binary to use.<br />
<br />
If you want to use the built-in TFTP server specify the ''-tftp'' Option. Of<br />
course this only enable the TFTP server in Qemu--a boot image is still<br />
required. The easiest way is to cat the stage1 and stage2 of [[GRUB|Grub]] together<br />
into one image. You can use the two files from you local installation of [[GRUB|Grub]]<br />
in ''/usr/lib/grub/i386-pc/''.<br />
<br />
cat /usr/lib/grub/i386-pc/stage1 /usr/lib/grub/i386-pc/stage2 > grub_disk<br />
<br />
You may, of course, use your own version [[GRUB|Grub]] instead of the installed.<br />
<br />
Now, you use the created ''grub_disk'' as boot image of qemu and the ''-tftp''<br />
Option to tell the Qemu TFTP Server where to look for files (in this case in<br />
the root directory):<br />
<br />
qemu -fda grub_disk -tftp /<br />
<br />
The Qemu will boot a [[GRUB|Grub]] with a command line where you may load your<br />
configuration file ([[menu.lst]]) for Grub. If you want to directly boot <br />
this configuration file whenever you boot Grub,<br />
simply open the created ''grub_disk'' in an editor, search for the string<br />
'''(nd)/tftp/menu.lst''' and replace it with the location of your<br />
configuration file. (For Grub version 0.97-os.6 the string is at offset<br />
0x41c.) Do '''not''' insert your string but overwrite the existing string.<br />
There are enough zeros after the string that can be overwritten.<br />
<br />
===PXE boot===<br />
<br />
With recent versions of Qemu (currently only snapshots after February 19th<br />
2007), you may also boot over the network using PXE. You will need a PXE Grub<br />
stage2. After you obtained the recent Qemu and the PXE Grub you can boot Qemu<br />
with:<br />
<br />
qemu -tftp / -bootp /usr/lib/grub/i386-pc/pxegrub -boot n<br />
<br />
Again you can modify the ''pxegrub'' binary to directly boot your preferred<br />
[[menu.lst]]. (For Grub version 0.97-os.6 the string is at offset 0x61c.)<br />
<br />
====Note for ubuntu users:====<br />
<br />
If you are using ubuntu as your host OS, you may don't have the pxe binaries installed.<br />
If so, you may want to download them from the svn repository:<br />
<br />
wget -O pxe-ne2k_pci.bin http://svn.savannah.gnu.org/viewvc/*checkout*/trunk/pc-bios/pxe-ne2k_pci.bin?root=qemu<br />
wget -O pxe-rtl8139.bin http://svn.savannah.gnu.org/viewvc/*checkout*/trunk/pc-bios/pxe-rtl8139.bin?root=qemu<br />
wget -O pxe-e1000.bin http://svn.savannah.gnu.org/viewvc/*checkout*/trunk/pc-bios/pxe-e1000.bin?root=qemu<br />
sudo mv pxe*.bin /ush/share/qemu/<br />
<br />
===Useful options===<br />
<br />
L4 software print lots of useful information on the serial line which can be<br />
helpful when debugging. To interact with the serial console of Qemu use the<br />
option ''-serial'':<br />
<br />
qemu ... -serial stdio<br />
<br />
You may also want to modify the amount of memory Qemu uses with the ''-m''<br />
option (here 256 MB):<br />
<br />
qemu ... -m 256<br />
<br />
<br />
===Network configuration===<br />
<br />
Here comes a (bit more complex) Qemu sample configuration (a bit Debian/Ubuntu specific) which demonstrates one of its network facilities. Let's assume<br />
the following configuration: you got a physical network interface (eth1) in your host pc which you want to connect to your guest OS.<br />
Furthermore, you still want to be able to use Qemu's built-in tftp server. This can be achieved by using a software bridge (bridged networking).<br />
*create a configuration for the software bridge (e.g. in <tt>/etc/network/interfaces</tt>):<br />
<br />
auto br0<br />
iface br0 inet static<br />
address 192.168.1.1<br />
network 192.168.1.0 <br />
netmask 255.255.255.0<br />
bridge_ports eth1<br />
bridge_fd 9 <br />
bridge_hello 2 <br />
bridge_maxage 12 <br />
bridge_stp off<br />
<br />
This creates a bridge called br0 and automatically adds interface eth1 to that bridge (seconds interface comes later). The addresses should differ from your normal network configuration (e.g. <tt>eth0</tt>).<br />
<br />
* adopt the sudo config file (e.g. <tt>/etc/sudoers</tt>)<br />
<br />
# Cmnd alias specification<br />
Cmnd_Alias QEMU=/sbin/ifconfig, \<br />
/sbin/modprobe, \<br />
/usr/sbin/brctl<br />
# User privilege specification<br />
root ALL=(ALL) ALL<br />
# Members of the admin group may gain root privileges<br />
%admin ALL=(ALL) ALL<br />
$username$ ALL=NOPASSWD: QEMU<br />
<br />
* now adopt your qemu-ifup script (e.g. <tt>/etc/qemu-ifup</tt>)<br />
<br />
#!/bin/sh<br />
echo "Executing /etc/qemu-ifup"<br />
echo "Bringing up $1 for bridged mode..."<br />
sudo /sbin/ifconfig $1 0.0.0.0 promisc up<br />
echo "Adding $1 to br0..."<br />
sudo /usr/sbin/brctl addif br0 $1<br />
<br />
This scripts gets called by Qemu and dynamically adds the tun interface to the bridge.<br />
<br />
* now, starting Qemu with the following command should give the guest OS access to eth1 as well as to the internal tftp-server<br />
<br />
qemu -serial stdio -m 256 -tftp /l4/ -bootp /tftp/pxegrub -boot n -net user -net nic,model=rtl8139,macaddr=00:11:22:33:44:55 -net tap,ifname=qtap0</div>Benjamin