Chinaunix首页 | 论坛 | 博客
  • 博客访问: 384287
  • 博文数量: 81
  • 博客积分: 1290
  • 博客等级: 中尉
  • 技术积分: 821
  • 用 户 组: 普通用户
  • 注册时间: 2011-07-17 07:48
个人简介

Just do IT.

文章分类

全部博文(81)

分类: 虚拟化

2017-03-14 22:22:51

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-email
sudo apt-get install libaio-dev libbluetooth-dev libbrlapi-dev libbz2-dev
sudo apt-get install libcap-dev libcap-ng-dev libcurl4-gnutls-dev libgtk-3-dev
sudo apt-get install libibverbs-dev libjpeg8-dev libncurses5-dev libnuma-dev
sudo apt-get install librbd-dev librdmacm-dev
sudo apt-get install libsasl2-dev libsdl1.2-dev libseccomp-dev libsnappy-dev libssh2-1-dev
sudo apt-get install libvde-dev libvdeplug-dev libvte-2.90-dev libxen-dev liblzo2-dev
sudo 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 .

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/native
cd bin/debug/native
# Configure QEMU and start the build.
../../../configure --enable-debug
make
# 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 directory
cd qemu
# Configure QEMU for x86_64 only - faster build
./configure --target-list=x86_64-softmmu --enable-debug
# Build in parallel - my system has 4 CPUs
make -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 20
ls -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 

阅读(1996) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~