User Tools

Site Tools


doc:howto:qemu

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
doc:howto:qemu [2013/01/20 06:23]
hhm arm: examples
doc:howto:qemu [2015/06/27 10:25] (current)
vbmithr
Line 1: Line 1:
 ====== OpenWrt in QEMU ====== ====== OpenWrt in QEMU ======
 +
 +QEMU is an an open source processor emulator (and virtualizer).
 This document descripes howto run the OpenWrt x86 port in QEMU. This document descripes howto run the OpenWrt x86 port in QEMU.
   * [[toh:​qemu:​qemu]] an example setup   * [[toh:​qemu:​qemu]] an example setup
Line 5: Line 7:
 It is mixed descriptions from windows and linux, so please read through all of it before starting. It is mixed descriptions from windows and linux, so please read through all of it before starting.
  
-===== Ubuntu Linux version ===== +:!: Choosing different emulation settings can affect performance greatly.
-Confirmed to work on Ubuntu 10.10 both x86_64 and x86+
  
-* Install ​qemu-kvm and kvm-pxe+Example: 30s iperf-s@openwrt(qemu running on host) to host
  
-| sudo apt-get install qemu-kvm kvm-pxe |+<​code>​ 
 +ne2k_pci:​0.0-31.3 sec  14.6 MBytes ​ 3.92 Mbits/sec 
 +pcnet: 0.0-30.0 sec  2.38 GBytes ​  682 Mbits/sec 
 +e1000: 0.0-30.0 sec  6.23 GBytes ​ 1.79 Gbits/sec 
 +vmxnet3: 0.0-30.0 sec  8.67 GBytes ​ 2.48 Gbits/sec 
 +virtio-net-pci: ​ 0.0-30.0 sec  44.6 GBytes ​ 12.8 Gbits/sec 
 +</​code>​
  
-* Download an openwrt image of your choise.+===== Getting QEMU =====
  
-| sudo su - +Qemu runs on many different systems.
-  mkdir -p /​var/​lib/​libvirt/​images +
-  cd /​var/​lib/​libvirt/​images +
-  http://​downloads.openwrt.org/​backfire/​10.03/​x86/​openwrt-x86-ext2.image.gz +
-  gunzip openwrt-x86-ext2.image.gz +
-|+
  
-Before starting it under qemu/kvm. I had to set a network driver model to make a network interface appear in OpenWrt.+==== Ubuntu Linux ====
  
-| model=ne2k_pci |+Many Linux Distributions like Debian, Ubuntu, Suse, Fedora provide a qemu package in their package repositories.
  
-Start the image+Example for Debian 7 (Wheezy)
-sudo su +<​code>​ 
-  ​cd ​/var/​lib/​libvirt/​images +sudo apt-get install qemu 
-  qemu -net nic,​model=ne2k_pci -hda openwrt-x86-ext2.image +</code>
-|+
  
-You should now get a "​terminal like" (vnc) window popup which shows the boot of OpenWrt.+:!: Qemu is rapidly developing so features, syntax might change between versions.
  
-Good luck!+==== Windows version ====
  
-===== Windows version ===== + ​The ​[[http://wiki.qemu.org/Links|QEMU Wiki Links]] page provides you with several unoffical download links of Windows builds.
-QEMU is an an open source processor emulator (and virtualizer). Start  +
-at [[http://www.qemu.org/download.html|QEMU download page]] which should  +
-have a link where [[http://​www.h7.dion.ne.jp/​~qemu-win/​|QEMU prebuild binaries  +
-for Windows]]. You can also find other (newer) ​builds ​of QEMU for Windows  +
-by googlling. In this example download the  +
-[[http://​www.h6.dion.ne.jp/​~kazuw/​qemu-win/​qemu-0.9.0-windows.zip|qemu-0.9.0-windows.zip]]  +
-and unzip to a directory.+
  
-Download OpenWrt raw image (ex. [[http://​downloads.openwrt.org/​kamikaze/​8.09.1/​x86/​openwrt-x86-ext2.image|kamikaze/​8.09.1/​x86/​]]) and copy the raw image into the qemu directory. 
  
-Run QEMU by using following command: +===== OpenWrt in QEMU ARM ====== 
-| <​code>​ +The "​[[https://dev.openwrt.org/wiki/​realview|realview]]"​ platform is meant for use with QEMU for emulating an ARM system. This platform might not be available ​in the standard downloads (it isn't at time of writing), but it currently appears when building from scratch.
-C:\qemu-0.9.0-windows>​qemu.exe -L . -hda openwrt-x86-ext2.image +
-</code> ​| +
-Which shall result ​in a command window as shown below:+
  
-{{:​inbox:​openwrtqemu1.png?​600|Start ​QEMU with OpenWrt}}+As of QEMU 1.1.2, use the following on the command line to get it booting:
  
-QEMU may issue warning message as following:​ +  qemu-system-arm -M realview-eb-mpcore -kernel openwrt-realview-vmlinux.elf -net nic -net user -nographic
-| <​code>​ +
-Could not open '​\\.\kqemu' ​QEMU acceleration layer not activated +
-</​code>​ | +
-You may correct this warning by installing KQEMU driver which provides  +
-better performance for the VM, but this is not as relevant to OpenWrt.+
  
-Upon execution of the above command new window shall appear with booting OpenWrt:+Basically, use the generated image as the `-kernel` parameter.
  
-{{:inbox:openwrtqemu2.png?600|OpenWrt boot up}}+FIXME Trunkkernel image does not boot; initramfs image works 
 +FIXME Trunkuntested: use SD card with rootfs, NFS rootfs, NBD rootfs 
 +FIXME Trunk: no sound, pcibus, usb emulation in qemu possible?
  
-And in several seconds ​OpenWrt ​VM shall be up and running:+===== OpenWrt ​in QEMU MIPS ====== 
 +The "​[[https://​dev.openwrt.org/​wiki/​malta|malta]]"​ platform is meant for use with QEMU for emulating a MIPS system.
  
-{{:inbox:openwrtqemu3.png?​600|OpenWrt running in QEMU}}+:!Use QEMU >= 2.2 
  
  
-====== OpenWrt in QEMU ARM ====== +depending on the malta variant 
-The "​[[https://​dev.openwrt.org/wiki/​realview|realview]]"​ platform is meant for use with QEMU for emulating an ARM system. This platform might not be available in the standard downloads (it isn't at time of writing), but it currently appears when building from scratch.+<​code>​ 
 +qemu-system-mipsel -kernel ​openwrt-malta-le-vmlinux-initramfs.elf -nographic -m 256 
 +</code>
  
-As of QEMU 1.1.2, use the following on the command line to get it booting:+===== OpenWrt in QEMU X86-64 =====
  
-  qemu-system-arm -M realview-eb-mpcore -kernel openwrt-realview-vmlinux.elf -net nic -net user -nographic+The x86-64 target has support for ESXI images by default. 
 +Booting the VMDK / VDI images might not work with newer qemu versions.
  
-Basically, use the generated image as the `-kernel` parameter.+:!: IMG/​VDI/​VMDK with "-hda" switch do not work with qemu 2.x .
  
-====== ​OpenWrt in QEMU MIPS ====== +pc-q35-2.0 / q35 emulates a different machine.  
-The "[[https://dev.openwrt.org/​wiki/​malta|malta]]"​ platform ​is meant for use with QEMU for emulating ​MIPS system.+With new syntax (no -hda , -net) the IMG / VDI / VMDK works here. 
 + 
 +Features: 
 + 
 +  * 2 HDDs (1 openwrt image, 1 data) 
 +  * 1 drive per bus, 6 bus available (until ide.5) 
 +  * 2 Network cards : 1 bridged to host (need higher permission) and 1 "​user"​ (default, NAT 10.x.x.x) 
 + 
 +Some emulated network cards might have performance issues. 
 + 
 +<​code>​ 
 +qemu-system-x86_64 \ 
 +-enable-kvm \ 
 +-M pc-q35-2.0 \ 
 +-drive file=openwrt-x86_64-combined-ext4.vdi,​id=d0,if=none \ 
 +-device ide-hd,​drive=d0,bus=ide.0 \ 
 +-drive file=data.qcow2,​id=d1,if=none \ 
 +-device ide-hd,​drive=d1,bus=ide.1 \ 
 +-soundhw ac97 \ 
 +-netdev bridge,br=virbr0,id=hn0 \ 
 +-device e1000,​netdev=hn0,​id=nic1 \ 
 +-netdev user,id=hn1 \ 
 +-device e1000,​netdev=hn1,​id=nic2 
 + 
 +qemu-system-x86_64 -M q35 -drive file=openwrt-x86_64-combined-ext4.img,​id=d0,​if=none,​bus=0,​unit=0 -device ide-hd,​drive=d0,​bus=ide.0 
 +</​code>​ 
 + 
 +===== Experiences:​ openwrt virtualized using debian, qemu/kvm and a lex twitter system with intel atom d525 and chipset ich8m  ====== 
 +Normally openwrt works on most of the hardware mentioned in the table of hardware 
 +(search in this wiki), and also on most o0f the hardware that support ​[[inbox:doc:​openwrt_x86|intel x86 ISA]] or  
 +''​gog.is/site:wiki.openwrt.org ​x86''​ in the address bar. 
 + 
 +Anyway some embedded x86 board have particular hardware that is not always well supported 
 +by the openwrt platform, even if all the ''​kmod''​ packages are included in the basic image. 
 +One of this x86 compatible hardware family are systems based on intel atom and chipset 
 +ich8m (maybe also others), like the Lex twitter system 3I525U. 
 + 
 +On that system openwrt is able to run but, for example, is not able to 
 +manage really well the possibility of having two wan connections with 
 +different metric. The request will be always routed to the interface with 
 +higher metric also using ''​ping -I <​wan2_interface>​ 8.8.8.8''​. Moreover software 
 +like ''​Nmap''​ will fail to be bind to certain interfaces. 
 +Someone with more knowledge could explain why this happens but as workaround 
 +one can use a more complete linux system (for example debian) as base and then virtualize  
 +(''​gog.is/site:wiki.openwrt.org virtualization OR qemu OR kvm OR hypervisor''​ in the address bar) 
 +openwrt, that in the end requires really a little resources most of the time, 
 +or one can assign plenty of resources because at the end the base system ​is quite powerful. 
 + 
 +==== Prepare debian (7.1 in the test) for virtualization ==== 
 +Debian was installed on a 2Gb cf card through a usb stick and netinstaller,​ 
 +having only the basic system utilities and ssh utilities. 1.1Gb of space were used, 600mb free and the rest swap. 
 + 
 +Install the following packages: ''​apt-get install qemu-kvm bridge-utils libvirt-bin virtinst''​ 
 +  * Qemu-kvm for qemu and kvm additional software components. 
 +  * bridge-utils for managing bridges in debian 
 +  * libvirt-bin for additional virtualization packages 
 +  * virtinst for handy virtualization management 
 +   
 +Then, if you don't want to use any user but just work with root (the 
 +objective is: let run openwrt on the twitter system, not having ​well 
 +setup debian ​system): 
 +  * Change /​etc/​libvirt/​qemu.conf uncommenting user/group to work as root. 
 +  * restart /​etc/​init.d/​libvirt* entries. 
 +   
 +Then we have to prepare the network. Modify ''/​etc/​network/​interfaces''​ a follows (adapt according to your needs) 
 +<​file>​ 
 +auto br0 br1 br2 br3 
 + 
 +iface br0 inet dhcp 
 +  bridge_ports eth0 
 +   
 +iface br1 inet dhcp 
 +  bridge_ports eth1 
 +   
 +iface br2 inet dhcp 
 +  bridge_ports eth2 
 +   
 +iface br3 inet dhcp 
 +  bridge_ports eth3 
 +</​file>​ 
 + 
 +The bridges ( https://​wiki.debian.org/​BridgeNetworkConnections ) are helpful because they allows different network adapters,  
 +real or virtual ( [[doc:​networking:​network.interfaces]] to exchange data (as the word '​bridge'​ suggests) 
 +and not only, because the bridge will have a certain mac address but also the virtual interfaces attached to it 
 +can have different mac addresses. Here the marvels of the linux networking system have to be explained by someone 
 +with more knowledge. 
 + 
 +==== Virtualization proper ==== 
 + 
 +Then we need to create our virtual machine. The additional packages, apart from 
 +qemu, will help here. We can issue the following command, using the x86 generic image 
 +placed in the folder ''/​root/​openwrt_kvm/'':​ 
 +<​file>​ 
 +virt-install --name=openwrt --ram=256 --vcpus=1 --os-type=linux --disk path=/​root/​openwrt_kvm/​openwrt-x86-generic-combined-ext4.img,​bus=ide --network bridge=br0,​model=e1000 --import 
 +# be careful to the model, e1000 let's openwrt recognize the interface. 
 +# http://​manpages.ubuntu.com/​manpages/​lucid/​man1/​virt-install.1.html 
 +</​file>​ 
 + 
 +If you want to interact with the system from command line, use ''​virsh''​. 
 +For example to force the shutdown of a virtual machine ''​virsh destroy openwrt''​ 
 +or to delete the virtual machine (but not the disk file) ''​virsh undefine openwrt''​. 
 + 
 +For having multiple interfaces 
 +<​file>​ 
 +virt-install --name=openwrt --ram=256 --vcpus=1 --os-type=linux --disk path=/​root/​openwrt_kvm/​openwrt-x86-generic-combined-ext4.img,​bus=ide \ 
 +   ​--network bridge=br0,​model=e1000 --network bridge=br3,​model=e1000 --import 
 +</​file>​ 
 +Remember that the console requires ''​ctrl+5''​ to exit (german keyboard). 
 + 
 +To mark a virtual machine for the autostart, type: ''​virsh autostart openwrt''​.
doc/howto/qemu.1358659382.txt.bz2 · Last modified: 2013/01/20 06:23 by hhm