Building QEMU for Linux

来源:互联网 发布:台式机网络接口灯不亮 编辑:程序博客网 时间:2024/06/05 05:34

Building QEMU for Linux

Most Linux distributions already provide binary packages for QEMU (or KVM).

Usually they also include all packages which are needed to compile QEMU for Linux. The default installation of most distributions will not include everything, so you have to install some additional packages before you can build QEMU.

Fedora Linux / Debian GNU Linux / Ubuntu Linux / Linux Mint

Fedora, Debian and Debian based or similar distributions normally include compiler and compilation tools (gcc, make, ...) in their default installation.

Required additional packages

  • git (30 MiB), version manager
  • glib2.0-dev (9 MiB), this automatically includes zlib1g-dev
  • libfdt-devel

For Ubuntu LTS Trusty (and maybe other Debian based distributions), all required additional packages can be installed like this:

sudo apt-get install git libglib2.0-dev libfdt-dev libpixman-1-dev zlib1g-dev

Recommended additional packages

  • git-email, used for sending patches
  • libsdl1.2-dev (23 MiB), needed for the SDL based graphical user interface
  • gtk2-devel, for a simple UI instead of VNC
  • vte-devel, for access to QEMU monitor and serial/console devices via the GTK interface

The above list is far from being complete. For maximum code coverage, as many QEMU features as possible should be enabled. When running configure, you should get many lines with "yes" and only a few with "no".

For Ubuntu Trusty (and maybe other Debian based distributions), all recommended additional packages for maximum code coverage can be installed like this:

sudo apt-get install git-emailsudo apt-get install libaio-dev libbluetooth-dev libbrlapi-dev libbz2-devsudo apt-get install libcap-dev libcap-ng-dev libcurl4-gnutls-dev libgtk-3-devsudo apt-get install libibverbs-dev libjpeg8-dev libncurses5-dev libnuma-devsudo apt-get install librbd-dev librdmacm-devsudo apt-get install libsasl2-dev libsdl1.2-dev libseccomp-dev libsnappy-dev libssh2-1-devsudo apt-get install libvde-dev libvdeplug-dev libvte-2.90-dev libxen-dev liblzo2-devsudo apt-get install valgrind xfslibs-dev 

Newer versions of Debian / Ubuntu might also try these additional packages:

sudo apt-get install libnfs-dev libiscsi-dev

Those packages also exist in Ubuntu Trusty, but they are too old for QEMU.

Getting the source code

If you want the latest code, follow the development of the code, work with several versions or maybe even contribute to the code, you will need a local copy of the QEMU code repository which is managed using git.

Get the code like this:

git clone git://git.qemu-project.org/qemu.git

The resulting directory qemu is your QEMU root directory.

Simple build and test

QEMU supports builds in this directory (not recommended) or in an extra directory (out-of-tree builds, recommended). There can be any number of out-of-tree builds, so if you plan to make cross builds, debug and release builds, out-of-tree builds are what you need.

Here is my typical build scenario:

# Switch to the QEMU root directory.cd qemu# Prepare a native debug build.mkdir -p bin/debug/nativecd bin/debug/native# Configure QEMU and start the build.../../../configure --enable-debugmake# Return to the QEMU root directory.cd ../../..

Now let's start a simple test:

bin/debug/native/x86_64-softmmu/qemu-system-x86_64 -L pc-bios

This test runs the QEMU system emulation which boots a PC BIOS.

Simple build and test with KVM

This example will show an in-tree build.

# Switch to the QEMU root directorycd qemu# Configure QEMU for x86_64 only - faster build./configure --target-list=x86_64-softmmu --enable-debug# Build in parallel - my system has 4 CPUsmake -j4

Getting ready to install a guest OS in a VM:

# Create a disk for the VM./qemu-img create -f qcow2 test.qcow2 16G# Download an install ISO - I have Fedora 20ls -la Fedora-Live-Desktop-x86_64-20-1.iso-rwxr-xr-x. 1 xxxxx xxxxx 999292928 May  4 16:32

Run QEMU with KVM enabled (w/o VNC):

If you have gtk2-devel installed, this will launch a simple UI and you can install your OS.

x86_64-softmmu/qemu-system-x86_64 -m 1024 -enable-kvm \-drive if=virtio,file=test.qcow2,cache=none \-cdrom Fedora-Live-Desktop-x86_64-20-1.iso

Run QEMU with KVM enabled (with VNC):

If you you prefer VNC, try this:

x86_64-softmmu/qemu-system-x86_64 -m 1024 -enable-kvm \-drive if=virtio,file=test.qcow2,cache=none \-cdrom Fedora-Live-Desktop-x86_64-20-1.iso \-vnc :1

Connect using your favorite VNC viewer to localhost:1 and install your OS.

Building                                                                          

========                                                                                                                                                            

QEMU ismulti-platform software intended to be buildable on all modern            

Linux platforms,OS-X, Win32 (via the Mingw64 toolchain) and a variety            

of other UNIXtargets. The simple steps to build QEMU are: 

  mkdir build                                                                     

  cd build                                                                        

  ../configure

   (../configure --prefix=$(pwd)/myusr --target-list=x86_64-softmmu--enable-debug --enable-kvm --disable-xen --disable-bsd-user --enable-usb-redir--enable-libusb    --enable-spice --audio-drv-list=alsa --with-system-pixman--enable-tpm --enable-vnc-sasl)                                                                    

  make 


0 0
原创粉丝点击