Compiling QEMU 2.x

A couple of weeks ago I decided to compile QEMU from source, so I could experiment with the latest version rather than the default version included with the current version of Debian.

Actually compiling QEMU is quite straight forward, once you have all the prerequisites installed, but you will need about 1.5 GB of free disk space..

To install the additional packages you need to be running as superuser.

$ su
Password: 

OR

$ sudo -i
Password:

# apt-get install gcc libc6-dev --no-install-recommends
Reading package lists... Done
Building dependency tree       
Reading state information... Done
libc6-dev is already the newest version.
The following extra packages will be installed:
  gcc-4.7 libitm1
Suggested packages:
  gcc-multilib manpages-dev autoconf automake1.9 libtool flex
  bison gdb gcc-doc gcc-4.7-multilib libmudflap0-4.7-dev
  gcc-4.7-doc gcc-4.7-locales libgcc1-dbg libgomp1-dbg
  libitm1-dbg libquadmath0-dbg libmudflap0-dbg libcloog-ppl0
  libppl-c2 libppl7 binutils-gold
The following NEW packages will be installed:
  gcc gcc-4.7 libitm1
0 upgraded, 3 newly installed, 0 to remove and 0 not upgraded.
Need to get 8,308 kB of archives.
After this operation, 18.0 MB of additional disk space will be used.
Do you want to continue [Y/n]? 
  :
  :
  :
Setting up libitm1:i386 (4.7.2-5) ...
Setting up gcc-4.7 (4.7.2-5) ...
Setting up gcc (4:4.7.2-1) ...

# apt-get install pkg-config --no-install-recommends
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following NEW packages will be installed:
  pkg-config
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 58.7 kB of archives.
  :
  :
  :
Setting up pkg-config (0.26-1) ...

# apt-get install bridge-utils uml-utilities --no-install-recommends
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Suggested packages:
  user-mode-linux
The following NEW packages will be installed:
  bridge-utils uml-utilities
0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
Need to get 0 B/99.5 kB of archives.
After this operation, 380 kB of additional disk space will be used.
  :
  :
  :
Setting up bridge-utils (1.5-6) ...
Setting up uml-utilities (20070815-1.3) ...
[ ok ] Starting User-mode networking switch: uml_switch.

# apt-get install zlib1g-dev --no-install-recommends
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following NEW packages will be installed:
  zlib1g-dev
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 212 kB of archives.
After this operation, 416 kB of additional disk space will be used.
Do you want to continue [Y/n]? 
  :
  :
  :
Setting up zlib1g-dev:i386 (1:1.2.7.dfsg-13) ...

# apt-get install libglib2.0-dev --no-install-recommends
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following extra packages will be installed:
  libpcre3-dev libpcrecpp0
Suggested packages:
  libglib2.0-doc
The following NEW packages will be installed:
  libglib2.0-dev libpcre3-dev libpcrecpp0
0 upgraded, 3 newly installed, 0 to remove and 0 not upgraded.
Need to get 2,497 kB of archives.
After this operation, 8,220 kB of additional disk space will be
used.
Do you want to continue [Y/n]?  
  :
  :
  :
Setting up libpcrecpp0:i386 (1:8.30-5) ...
Setting up libpcre3-dev (1:8.30-5) ...
Setting up libglib2.0-dev (2.33.12+really2.32.4-5) ...

# apt-get install autoconf --no-install-recommends
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following extra packages will be installed:
  m4
Suggested packages:
  autoconf2.13 autoconf-archive gnu-standards autoconf-doc libtool
  gettext
Recommended packages:
  automake automaken
The following NEW packages will be installed:
  autoconf m4
0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
Need to get 0 B/845 kB of archives.
After this operation, 2,323 kB of additional disk space will be
used.
Do you want to continue [Y/n]? 
  :
  :
  :
Setting up m4 (1.4.16-3) ...
Setting up autoconf (2.69-1) ...

# apt-get install automake --no-install-recommends
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following extra packages will be installed:
  autotools-dev
The following NEW packages will be installed:
  automake autotools-dev
0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
Need to get 680 kB of archives.
After this operation, 1,754 kB of additional disk space will be
used.
Do you want to continue [Y/n]? 
  :
  :
  :
Setting up autotools-dev (20120608.1) ...
Setting up automake (1:1.11.6-1) ...
update-alternatives: using /usr/bin/automake-1.11 to provide 
  /usr/bin/automake (automake) in auto mode

# apt-get install libtool --no-install-recommends
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following extra packages will be installed:
  file
Suggested packages:
  libtool-doc gfortran fortran95-compiler gcj
Recommended packages:
  libltdl-dev
The following NEW packages will be installed:
  file libtool
0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
Need to get 673 kB of archives.
After this operation, 1,522 kB of additional disk space will be
used.
Do you want to continue [Y/n]? 
  :
  :
  :
Setting up file (5.11-2+deb7u2) ...
Setting up libtool (2.4.2-1.1) ...

You will also want the SDL libraries.

# apt-get install libsdl1.2-dev --no-install-recommends
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following extra packages will be installed:
  libasound2-dev libavahi-client-dev libavahi-common-dev
  libcaca-dev libdbus-1-dev libdirectfb-dev libdirectfb-extra
  libfreetype6-dev libgl1-mesa-dev libglu1-mesa
  libglu1-mesa-dev libjpeg8-dev libpng12-dev libpthread-stubs0
  libpthread-stubs0-dev libpulse-dev libsdl1.2debian
  libslang2-dev libts-dev libx11-dev libxau-dev libxcb1-dev
  libxdmcp-dev libxext-dev mesa-common-dev x11proto-core-dev
  x11proto-input-dev x11proto-kb-dev x11proto-xext-dev
  xorg-sgml-doctools xtrans-dev
Suggested packages:
  libasound2-doc libxcb-doc libxext-doc
Recommended packages:
  libx11-doc
The following NEW packages will be installed:
  libasound2-dev libavahi-client-dev libavahi-common-dev
  libcaca-dev libdbus-1-dev libdirectfb-dev libdirectfb-extra
  libfreetype6-dev libgl1-mesa-dev libglu1-mesa
  libglu1-mesa-dev libjpeg8-dev libpng12-dev libpthread-stubs0
  libpthread-stubs0-dev libpulse-dev libsdl1.2-dev
  libsdl1.2debian libslang2-dev libts-dev libx11-dev libxau-dev
  libxcb1-dev libxdmcp-dev libxext-dev mesa-common-dev
  x11proto-core-dev x11proto-input-dev x11proto-kb-dev
  x11proto-xext-dev xorg-sgml-doctools xtrans-dev
0 upgraded, 32 newly installed, 0 to remove and 0 not upgraded.
Need to get 9,062 kB of archives.
After this operation, 28.6 MB of additional disk space will be used.
Do you want to continue [Y/n]? 
  :
  :
  :
Setting up libsdl1.2-dev (1.2.15-5) ...

# 

We don’t need to be a super user to build QEMU so exit.

# exit

To build QEMU itself we need to download the source code (The latest version was 2.0.0 when this post was written).

$ wget -c http://wiki.qemu-project.org/download/qemu-2.0.0.tar.bz2

Then extract the source files from the archive, this will create a new directory called qemu-2.0.0 .

$ tar -xvpf qemu-2.0.0.tar.bz2
qemu-2.0.0/
qemu-2.0.0/aio-win32.c
qemu-2.0.0/qemu-tech.texi
  :
  :
  :
qemu-2.0.0/target-sh4/cpu.c
qemu-2.0.0/target-sh4/README.sh4
qemu-2.0.0/target-sh4/cpu.h
$

Change the current directory to the new folder you just created.

$ cd qemu-2.0.0

To compile everything simply run configure followed by make, then go and get a fresh cup, and even on a fast machine you will probably have more than enough time to allow you to start by roasting your own beans…

$ ./configure 
No C++ compiler available; disabling C++ specific optional code
Disabling libtool due to broken toolchain support
Install prefix    /usr/local
BIOS directory    /usr/local/share/qemu
binary directory  /usr/local/bin
library directory /usr/local/lib
module directory  /usr/local/lib/qemu
  :
  :
  :
Quorum            no
lzo support       no
snappy support    no
$ make
  GEN   aarch64-softmmu/config-devices.mak
  GEN   alpha-softmmu/config-devices.mak
  GEN   arm-softmmu/config-devices.mak
  GEN   cris-softmmu/config-devices.mak
  GEN   i386-softmmu/config-devices.mak
  :
  :
  :
  :
  :
  LINK  x86_64-linux-user/qemu-x86_64
  CPP   optionrom/multiboot.asm
  AS    optionrom/multiboot.o
  Building optionrom/multiboot.img
  Building optionrom/multiboot.raw
  Signing optionrom/multiboot.bin
  CPP   optionrom/linuxboot.asm
  AS    optionrom/linuxboot.o
  Building optionrom/linuxboot.img
  Building optionrom/linuxboot.raw
  Signing optionrom/linuxboot.bin
  CPP   optionrom/kvmvapic.asm
  AS    optionrom/kvmvapic.o
  Building optionrom/kvmvapic.img
  Building optionrom/kvmvapic.raw
  Signing optionrom/kvmvapic.bin
$

It is proabably better to just compile the emulators you want, I also prefer not to use VNC but to use the graphical console instead (which is why I installed the SDL libraries).

$ ./configure --target-list=i386-softmmu --disable-vnc --enable-sdl
No C++ compiler available; disabling C++ specific optional code
Install prefix    /usr/local
BIOS directory    /usr/local/share/qemu
binary directory  /usr/local/bin
library directory /usr/local/lib
  :
  :
SDL support       yes
  :
  :
  :
Quorum            no
lzo support       no
snappy support    no
$ make
  GEN   i386-softmmu/config-devices.mak
  GEN   config-all-devices.mak
  GEN   config-host.h
  :
  :
  :
  Building optionrom/kvmvapic.img
  Building optionrom/kvmvapic.raw
  Signing optionrom/kvmvapic.bin
$

And that’s all there is to it, providing you have all the prerequisites installed it should just compile…

You could just run the executables from a folder in your own home directory but to install QEMU in /usr/local/bin you need to be running as superuser again.

$ su
Password: 

OR

$ sudo -i
Password:

First we need a couple more packages, then we can just tell the make script to install the binaries we just built.

# apt-get install bison flex --no-install-recommends
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following extra packages will be installed:
  libbison-dev
Suggested packages:
  bison-doc build-essential
The following NEW packages will be installed:
  bison flex libbison-dev
0 upgraded, 3 newly installed, 0 to remove and 0 not upgraded.
Need to get 1,277 kB of archives.
After this operation, 3,119 kB of additional disk space will be used.
Do you want to continue [Y/n]? 
  :
  :
  :
Setting up bison (1:2.5.dfsg-2.1) ...

# make install
  :
  :
  :
install -m 755 qemu-system-i386 "/usr/local/bin"
strip "/usr/local/bin/qemu-system-i386"
# 

Having installed QEMU I then needed to install Debian wheezy.

This entry was posted in Debian, Linux and tagged . Bookmark the permalink.

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.