Building Qemu 2.0

From MK Wiki EN
Revision as of 17:19, 28 June 2018 by MkWikiEnSysOp (talk | contribs) (4 revisions imported)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

My system is currently running Ubuntu 12.04 LTS (Precise Pangolin) which ships with version 1.0 of Qemu (see here), which is quite old. For some reasons - especially the very convenient option "-net bridge" - I desired to run Qemu 2.0. I decided to try to build it myself, which wasn't very easy for me, but finally I could resolve all challenges.

Getting Qemu's Sources

May be that's the easiest part of all. You can get Qemu's sources either by git or a simple HTTP download. I decided for the latter one. You can find the download link in the Qemu wiki. By now, it's http://wiki.qemu-project.org/download/qemu-2.0.2.tar.bz2. Unpack those to a directory of your choice.

Fetching Dependencies

In order to be able to build Qemu, the compilation infrastructure needs some development packages. You can get those with these commands:

apt-get build-dep qemu
apt-get install libvde-dev libvdeplug2-dev libcap-ng-dev libattr1-dev

The second line was a little tricky to find out. May be that's because the first line only gets all the libraries needed to build Qemu 1.0, but not Qemu 2.0.

Building Qemu

Open a terminal now and change to the directory with your copy of Qemu's source code. Now do the following:

mkdir -p bin/debug/native
cd bin/debug/native
../../../configure --enable-sdl --audio-drv-list=alsa,oss --enable-curses --enable-vnc-jpeg --enable-curl --enable-fdt --enable-kvm --enable-tcg-interpreter --enable-system --enable-user \
 --enable-linux-user --enable-guest-base --enable-pie --enable-uuid --enable-vde --enable-linux-aio --enable-cap-ng --enable-attr --enable-docs --enable-vhost-net --enable-rbd \
 --enable-guest-agent --target-list=x86_64-softmmu,i386-softmmu
make -j2

Adjust option "--target-list" of configure and option "-j" of make to your needs! My CPU has 2 cores, that's why I used "-j2".

This process took 4 min 54 seconds on my system.

The Qemu wiki was very helpful at this point: Hosts/Linux.

Configuring And Installing Qemu

If you already have the qemu package from Ubuntu on your system, it's now time to remove it.

apt-get remove qemu

Now let's install Qemu:

sudo make install

If you already have a file /etc/bridge.conf on your system, create a symbolic link to it:

ln -s /etc/qemu/bridge.conf /usr/local/etc/qemu/bridge.conf

If you don't have that file, just create it:

echo "allow br0" >> /usr/local/etc/qemu/bridge.conf

Adjust "br0" to your needs and repeat that command for every bridge you intend to use.

Testing Qemu

Copy your currently running kernel to a directory:

mkdir ~/temp
sudo cp /boot/vmlinuz-`uname -r` ~/temp
sudo chown `whoami`.`whoami` ~/temp/vmlinuz-`uname -r`

Boot that kernel:

sudo x86_64-softmmu/qemu-system-x86_64 -L pc-bios -kernel ~/temp/vmlinuz-`uname -r` -enable-kvm -net nic,macaddr=52:54:13:11:0:1 -net bridge,br=br0

Important: Adjust the MAC address of your virtual system!!!

If your CPU doesn't have virtualization functions you must remove "-enable-kvm". If you want to use a bridge other than "br0", adjust that value too.

This command just opens Qemu and boots the kernel. After some milliseconds, a kernel panic appears, because there is no init process. That's a desired behavior. The command only checks if Qemu runs accordingly and doesn't yield any errors.

Conclusion

For me, it took some hours until I resolved all problems, mainly the dependencies required for a successful build, but once you have finished, it all looks very simple. Ubuntu 12.04 is running smoothly on my system and Qemu had been the only reason yet why to upgrade. Now I have Qemu 2.0 on my system and there's no need to upgrade to Ubuntu 14.04 and fight against all the bugs. I can calmly wait for the 14.04.2 or even 14.04.3 release.