Installing QEMU on Ubuntu 16.04

These are my experiences from installing QEMU from source, on Ubuntu 16.04.1.

Starting from the QEMU main page, I navigated to the download page. I downloaded using the command

wget http://wiki.qemu-project.org/download/qemu-2.7.0-rc2.tar.bz2

I unpacked the file using

tar xvjf qemu-2.7.0-rc2.tar.bz2

Changing directory as

cd qemu-2.7.0-rc2

I could then do the configuration, using the command

./configure --target-list=i386-softmmu,arm-softmmu,x86_64-softmmu --disable-vnc --enable-sdl

This, however, resulted in an error, as

qemu-2.7.0-rc2$ ./configure --target-list=i386-softmmu,arm-softmmu,x86_64-softmmu --disable-vnc --enable-sdl

ERROR: zlib check failed
Make sure to have the zlib libs and headers installed.

The zlib libs and headers were then installed, using the command

sudo apt-get install zlib1g-dev

Trying the configure command again resulted in

qemu-2.7.0-rc2$ ./configure --target-list=i386-softmmu,arm-softmmu,x86_64-softmmu --disable-vnc --enable-sdl

ERROR: User requested feature sdl
configure was not able to find it.
Install SDL devel

which was solved using the installation command

sudo apt-get install libsdl2-dev

Now the configure command went through!

But make failed!

qemu-2.7.0-rc2$ make
GEN i386-softmmu/config-devices.mak.tmp
GEN i386-softmmu/config-devices.mak
GEN arm-softmmu/config-devices.mak.tmp
GEN arm-softmmu/config-devices.mak
GEN x86_64-softmmu/config-devices.mak.tmp
GEN x86_64-softmmu/config-devices.mak
GEN config-all-devices.mak
GEN config-host.h
(cd /home/ola/qemu/qemu-2.7.0-rc2/pixman; autoreconf -v --install)
/bin/sh: 1: autoreconf: not found
Makefile:213: recipe for target '/home/ola/qemu/qemu-2.7.0-rc2/pixman/configure' failed
make: *** [/home/ola/qemu/qemu-2.7.0-rc2/pixman/configure] Error 127

So it was time for

sudo apt-get install autoconf

Here I remembered having used apt instead of apt-get, when I did an installation of another program, so I consulted this page about apt vs apt-get.

I tried

sudo apt install autoconf

which worked fine.

Running make now gave another error, as

qemu-2.7.0-rc2$ make
(cd /home/ola/qemu/qemu-2.7.0-rc2/pixman; autoreconf -v --install)
autoreconf: Entering directory `.'
autoreconf: configure.ac: not using Gettext
autoreconf: running: aclocal
autoreconf: configure.ac: tracing
autoreconf: configure.ac: not using Libtool
autoreconf: running: /usr/bin/autoconf
configure.ac:75: error: possibly undefined macro: AC_PROG_LIBTOOL
If this token and others are legitimate, please use m4_pattern_allow.
See the Autoconf documentation.
autoreconf: /usr/bin/autoconf failed with exit status: 1
Makefile:213: recipe for target '/home/ola/qemu/qemu-2.7.0-rc2/pixman/configure' failed
make: *** [/home/ola/qemu/qemu-2.7.0-rc2/pixman/configure] Error 1
make: *** Deleting file '/home/ola/qemu/qemu-2.7.0-rc2/pixman/configure'

which led me to install libtool, as

sudo apt install libtool

And now make started to build things – and it seemed to have succeeded!

I then did

sudo make install

which, since the configure command included x86 as well as ARM as targets, we should be able to run Linux for x86 and for ARM on our newly installed QEMU.

Doing some search, and looking at this page about booting a raw disk image in QEMU, led me to commands for obtaining and unpacking a Linux image for x86, as

cd ..
mkdir i386
cd i386/
wget http://wiki.qemu.org/download/linux-0.2.img.bz2
bunzip2 linux-0.2.img.bz2

QEMU could then be started, with this Linux image as the chosen software, as

qemu-system-i386 -drive format=raw,file=linux-0.2.img

For ARM, I did

cd ..
mkdir arm
cd arm
wget http://wiki.qemu.org/download/arm-test-0.2.tar.gz
tar zxvf arm-test-0.2.tar.gz

I could then run QEMU, with the downloaded ARM Linux as software, by doing

cd arm-test/
qemu-system-arm -machine integratorcp -kernel zImage.integrator -initrd arm_root.img -nographic -append "console=ttyAMA0"

For this example, I used Ctrl-A followed by x, to exit the QEMU simulation.

Advertisements

Installing QEMU on Mac OS X El Capitan

QEMU is an open source computer emulator. Here I describe how I installed QEMU on Mac OS X El Capitan.

My goal was to learn more about building QEMU, and to boot Linux on QEMU, and to check if there were differences in the installation compared to when doing it on Mac OS X Yosemite.

I downloaded and unpacked QEMU 2.5.0 (this was the latest stable release at the date I did the download), by doing

wget http://wiki.qemu-project.org/download/qemu-2.5.0.tar.bz2
tar xvjf qemu-2.5.0.tar.bz2
cd qemu-2.5.0

Then, based on my earlier experiences, I used the configure command

./configure --enable-cocoa --target-list=i386-softmmu,arm-softmmu,x86_64-softmmu --disable-vnc

and it succeeded! Here I took advantage of my previous installation of rudix, and the use of rudix for installing glib, which I did using the command

sudo rudix install glib

This installation of glib prevented an error printout

ERROR: glib-2.22 gthread-2.0 is required to compile QEMU

The next step is building, which I did by simply typing make, but that did not succeed.

There were warnings, but also errors. I searched using google, using the error printout as search terms. This led me to this page with advice, which told me to add make targets, resulting in lines like

region_test_OBJECTS = region-test.$(OBJEXT) utils.$(OBJEXT)

and

scaling_helpers_test_OBJECTS = scaling-helpers-test.$(OBJEXT) utils.$(OBJEXT)

in the file

./pixman/test/Makefile

where the targets utils.$(OBJEXT) were added by me.

The errors went away, resulting in a successful build. Again, I was helped by my earlier experiences, where I learned how to prevent link errors by installing gettext using rudix, as

sudo rudix install gettext

I could then do make install to install my new QEMU.

Now I wanted to boot Linux! I looked at the QEMU Testing page, and decided to download and unpack a Linux image for ARM by doing

wget http://wiki.qemu.org/download/arm-test-0.2.tar.gz
tar zxvf arm-test-0.2.tar.gz

A Linux boot could then be done, by starting QEMU with the downloaded Linux image as argument, as

cd arm-test
qemu-system-arm -machine integratorcp -kernel zImage.integrator -initrd arm_root.img -nographic -append "console=ttyAMA0"

When done, QEMU can be shut down by doing Ctrl-A x.

Installing QEMU on Mac OS X Yosemite

QEMU is an open source computer emulator. Here I describe how I installed QEMU on Mac OS X Yosemite.

My goal was to learn more about building QEMU, and to boot Linux on QEMU.

I downloaded and unpacked QEMU 2.3.0 (this was the latest stable release at the date I did the download), by doing

wget http://wiki.qemu-project.org/download/qemu-2.3.0.tar.bz2
tar xvjf qemu-2.3.0.tar.bz2
cd qemu-2.3.0

Then, based on my earlier experiences, I used the configure command

./configure --enable-cocoa --target-list=i386-softmmu,arm-softmmu,x86_64-softmmu --disable-vnc

This command generated an error, telling me that

ERROR: glib-2.22 gthread-2.0 is required to compile QEMU

I tried my previous approach, where I installed the required glib version using sudo port install. I used the command

sudo port install glib-2.2

which resulted in

Warning: port definitions are more than two weeks old, consider using selfupdate
Error: Port glib-2.2 not found

I followed this advice, and did

sudo port selfupdate

but that led me into new troubles, with error messages telling me that my Xcode Command Line Tools were most likely not installed. I tried to install these tools but without luck

I was about to give up when I stumbled upon rudix. This turned out to be an attractive solution! I read at the rudix page that I should do

sudo python rudix.py install rudix

Then, from the rudix glib page, I learned that I should do

sudo rudix install glib

I did as told, and now the configure command

./configure --enable-cocoa --target-list=i386-softmmu,arm-softmmu,x86_64-softmmu --disable-vnc

succeeded. I followed it up by building, using make, but that did not succeed.

I looked at the build errors, which led me to this page with advice, which told me to add make targets, resulting in lines like

scaling_helpers_test_OBJECTS = scaling-helpers-test.$(OBJEXT) utils.$(OBJEXT)

in the file

./pixman/test/Makefile

where the last target had to be added by me. A similar change, in the same Makefile, was required, and resulted in the modified line

region_test_OBJECTS = region-test.$(OBJEXT) utils.$(OBJEXT)

The errors went away, but a new link error remained. The error printout was

LINK qemu-ga
ld: library not found for -lintl
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [qemu-ga] Error 1

I found this page with advice on how to solve it using brew (which was not applicable to my problem).

However, since I now had my rudix package, I chose instead to do

sudo rudix install gettext

This resulted in a successful build, and I could then also do make install to install my new QEMU.

Now I wanted to boot Linux! I looked at the QEMU Testing page, and decided to download and unpack a Linux image by doing

wget http://wiki.qemu.org/download/linux-0.2.img.bz2
bzip2 -d linux-0.2.img.bz2

A Linux boot could then be done, by starting QEMU with the downloaded Linux image as argument, as

qemu-system-i386 -hda linux-0.2.img

Installing QEMU

QEMU is an open source computer emulator. Here I describe how I installed QEMU on Linux and on Mac Mountain Lion.

My goal was to create a simulator for machines with ARM architecture and for machines with x86 architecture.

Updates to this post

  • July 15, 2013 – changed the section on Ubuntu Linux to cover QEMU 1.5.1 instead of QEMU 1.2.0.

Ubuntu Linux

Starting from the QEMU home page I navigated to the download page. From there I downloaded the file

qemu-1.5.1.tar.bz2

I unpacked the file, and navigated to the directory created during the unpacking, using the commands

tar xvjf qemu-1.5.1.tar.bz2
cd qemu-1.5.1

As a preparation, I needed to update my Ubuntu 13.04 installation. It turned out that the following installations were needed:

sudo apt-get install zlib1g-dev
sudo apt-get install libglib2.0
sudo apt-get install autoconf
sudo apt-get install libtool
sudo apt-get install libsdl-console
sudo apt-get install libsdl-console-dev

I could then configure QEMU, using the command

./configure --target-list=i386-softmmu,arm-softmmu,x86_64-softmmu --disable-vnc --enable-sdl

I could then build and install, using

make
sudo make install

I could then use QEMU, for simulation of an ARM computer, e.g. as

qemu-system-arm -M realview-pb-a8 -nographic -kernel prog_arm_rpb_a8.elf

and simulation of an x86 computer, e.g. as

qemu-system-x86_64 -kernel prog_x86_grub_target.elf

Problems encountered – I had some trouble before realizing which packages to add to Ubuntu in order to get QEMU to build. The first thing that happened was that the configure command failed, with

ERROR: zlib check failed
Make sure to have the zlib libs and headers installed.

which, after some searching, led me to install zlib as

sudo apt-get install zlib1g-dev

Then I got a message I recognized from my installation of QEMU on Mac, saying that

ERROR: glib-2.12 required to compile QEMU

which, again after some searching, led to the installation of glib as

sudo apt-get install libglib2.0

Configure was now happy but make was not. The make command gave an error, as

(cd /home/ola/Downloads/qemu-1.5.1/pixman; autoreconf -v --install)
/bin/sh: autoreconf: command not found
make: *** [/home/ola/Downloads/qemu-1.5.1/pixman/configure] Error 127

Trying the command autoreconf, as

ola@ola-Aspire-S3-391:~/Downloads/qemu-1.5.1$ autoreconf
The program 'autoreconf' can be found in the following packages:
* autoconf

led to the installation of autoconf, as

sudo apt-get install autoconf

An error telling me to install libtool then appeared, as

../../lib/autoconf/general.m4:2678: AC_LINK_IFELSE is expanded from...
configure.ac:552: the top level
configure.ac:75: error: possibly undefined macro: AC_PROG_LIBTOOL
If this token and others are legitimate, please use m4_pattern_allow.
See the Autoconf documentation.
autoreconf: /usr/bin/autoconf failed with exit status: 1
make: *** [/home/ola/Downloads/qemu-1.5.1/pixman/configure] Error 1
make: *** Deleting file `/home/ola/Downloads/qemu-1.5.1/pixman/configure'

which, by help from Erik Rull, led me to the installation of libtool, as

sudo apt-get install libtool

Now everything built, and I could also do an installation of QEMU, as

sudo make install

The ARM simulation worked fine, but there was no screen in the x86 simulation. I guessed that I needed also SDL for this purpose, and after the installation of sdl, as

sudo apt-get install libsdl-console
sudo apt-get install libsdl-console-dev

I could see a console, and the long-awaited “Hello, world”-message from my program.

Linux

I downloaded and unpacked QEMU in the same way as described above for Ubuntu Linux.

Then, since I was not root on the machine, I used the configure command

./configure --prefix=/nobackup/local/prog/qemu --target-list=i386-softmmu,arm-softmmu,x86_64-softmmu --disable-vnc

followed by commands for build and installation, as

make
make install

I also added the following changes

export PATH=/nobackup/local/prog/qemu/bin:$PATH

to my setup script, where I also set up other environment variables.

I could then use QEMU, for simulation of an ARM computer, e.g. as

qemu-system-arm -M realview-pb-a8 -nographic -kernel prog_arm_rpb_a8.bin

Mac Mountain Lion

I downloaded and unpacked QEMU 1.2.0 in the same way as described above for Ubuntu Linux.

Then, based on information from Ruben Schade, I used the configure command

./configure --enable-cocoa --target-list=i386-softmmu,arm-softmmu,x86_64-softmmu --disable-vnc

This command generated an error, telling me that “glib-2.12” was “required to compile QEMU”. I searched for this error, and after having read at this MacPorts-related page, I ended up doing

sudo port install glib-2.12
sudo port selfupdate
sudo port upgrade outdated

which, as a result, made it possible to redo the configure command as decribed above.

I then built QEMU, which succeeded but with several warnings, and installed it, using

make
sudo make install

I could now use QEMU, for simulation of an ARM computer, e.g. as

qemu-system-arm -M realview-pb-a8 -nographic -kernel prog_arm_rpb_a8.bin