VirtualBox: Compile dari Source Code

From OnnoWiki
Jump to navigation Jump to search

While we try to not favor any distribution, we only build with certain distributions. These include Debian, Ubuntu and Oracle Linux. Things should not be much different for other distributions though. If you want to supply specific build instructions (especially package names) for other distributions, please contact the VirtualBox team.

Guest Additions

These instructions will also build the Guest Additions - the Linux parts only, and for the bit count your host system is using. To only build the Additions (this requires a lot less dependencies, though sadly configure does not know that) add the make file parameter VBOX_ONLY_ADDITIONS=1 to the kmk command line. To create an Additions disk image installer, do a second kmk run with packing on the command line. And to do a 32-bit build on a 64-bit host, add the parameter KBUILD_TARGET_ARCH=x86. Output goes to the folder out/linux.*/*/bin/additions. The Additions built will generally not work on a system older than the one they were built on (e.g. a build on Ubuntu 16.10 will cause problems on an Ubuntu 14.04 guest). Build in a chroot environment or on the target virtual machine to solve this. Prerequisites

You need:

GCC 3.3.3 or later (except for the GCC 4.0.x series). GCC 4.4.1 is recommended.
as86 (real mode assembler, usually part of the dev86 or bin86 package.)
bcc (Bruce Evans C Compiler; often part of the dev86 package; only required for VBox < 4.2)
Note: The bcc compiler contained in openSUSE10.2 as part of dev86-0.16.0-218 is known to generate broken code. Unfortunately, bcc -v is not supported.
IASL (Intel ACPI compiler)
xsltproc (libxslt, XML style sheet processor)
libxml2 (required for VBox version >= 1.6, XML file handling)
libxslt1 (required for VBox version >= 1.6, XML file transformation)
libXcursor (required to support color mouse pointers in the guest)
libxinerama
librandr
Qt 4.x.y (with x >= 4, including the OpenGL part, required for VBox version > 3.0)
libIDL
libSDL (SDL frontend)
ALSA (audio backend)
PulseAudio (audio backend)
libhal (detect host floppy/DVD)
libcap (CAP_NET_RAW for ICMP sockets in NAT)
libdevmapper
libpam0g (PAM support for the guest additions, required for VBox version >= 3.2)
python-dev (Python bindings)
gsoap (webservice API, version 2.7.9f or higher)
Java SE 6 JDK (Java API bindings, both webservice and XPCOM)
Xmu (for OpenGL)
Mesa (for OpenGL)
cURL (version 7.16.1 or higher, required for VBox version >= 3.0)
Java JDK (required to generate the Java bindings)
makeself (for creating the generic installer package, required for VBox version >= 4.0)
pdflatex (normally provided by texlive-latex-base) 

On 64-bit systems you need the following packages as well:

ia32-libs (various libraries needed for compiling the 32-bit guest additions)
libc6-dev-i386 (libc6 i386 development headers)
lib32gcc1 (gcc support for i386)
gcc-multilib (gcc support for i386)
lib32stdc++6 (libstdc++ for i386)
g++-multilib (g++ support for i386) 

On Debian-based systems, the following command should install the required packages:

apt install gcc g++ bcc iasl xsltproc uuid-dev zlib1g-dev libidl-dev \
            libsdl1.2-dev libxcursor-dev libasound2-dev libstdc++5 \
            libpulse-dev libxml2-dev libxslt1-dev \
            python-dev libqt4-dev qt4-dev-tools libcap-dev \
            libxmu-dev mesa-common-dev libglu1-mesa-dev \
            linux-libc-dev libcurl4-openssl-dev libpam0g-dev \
            libxrandr-dev libxinerama-dev libqt4-opengl-dev makeself \
            libdevmapper-dev default-jdk python \
            texlive-latex-base \
            texlive-latex-extra texlive-latex-recommended \
            texlive-fonts-extra texlive-fonts-recommended

On 64-bit Debian-based systems, the following command should install the required additional packages:

apt install libc6-dev-i386 lib32gcc1 gcc-multilib \
            lib32stdc++6 g++-multilib


To get the beramono.sty LaTeX style which is missing in Fedora (thanks to Perry):

cd /usr/share/texmf/tex/latex/
mkdir bera
cd bera/
wget http://www.tug.org/texlive/devsrc/Master/texmf-dist/tex/latex/bera/beramono.sty
texhash

Note that VirtualBox makes use of YASM as its assembler which is part of the source repository as the currently available releases of YASM contain various bugs. As soon as a working release becomes officially available, we will add YASM to the list of prerequisites.

apt install yasm


Special tweaks for 64 bit binaries

Building on a 64bit host still requires 32bit libraries and build tools as the Guest Additions which are part of the build process are 32bit. Note that on 64bit Ubuntu systems some links to shared libraries are missing. This can be fixed with

ln -s libX11.so.6    /usr/lib32/libX11.so 
ln -s libXTrap.so.6  /usr/lib32/libXTrap.so 
ln -s libXt.so.6     /usr/lib32/libXt.so 
ln -s libXtst.so.6   /usr/lib32/libXtst.so
ln -s libXmu.so.6    /usr/lib32/libXmu.so
ln -s libXext.so.6   /usr/lib32/libXext.so

Building VirtualBox

Download source code

cd /usr/local/src/
wget http://download.virtualbox.org/virtualbox/5.1.30/VirtualBox-5.1.30.tar.bz2
tar jxvf VirtualBox-5.1.30.tar.bz2


Change to the root directory of the sources and execute the configure script:

./configure --disable-hardening

If it finds everything it needs, it will create a file called 'AutoConfig.kmk' containing paths to the various tools on your system. Also, it will create an environment setup script called env.sh. This step only has to be done once (if something changes in your build tool setup, you might have to repeat it but keep in mind that both output files will be overwritten).

The switch --disable-hardening should not be used for building packages for redistribution or for production use.

Whenever you want to build VirtualBox, you have to open a shell and source the generated environment setup script 'env.sh', i.e. do

source ./env.sh

To build a release package, type

kmk all

This produces the required binaries in out/linux.x86/release/bin/. If you want to build a debug version, type

kmk BUILD_TYPE=debug

In case you have more than one CPU core, kmk will automatically do a parallel build.

Running a hardened build from the bin/ directory will not work because all hardened binaries do explicit link against libraries from /opt/VirtualBox (fixed path).

Building VirtualBox packages for distribution

Never disable hardening (see previous section) when creating packages for redistribution.

To be more LSB-compliant, change the default pathes which are used by the VirtualBox binaries to find their components. Add the following build variables to LocalConfig.kmk:

VBOX_PATH_APP_PRIVATE_ARCH := /usr/lib/virtualbox
   This is the application's private directory, architecture-dependent. 
VBOX_PATH_SHARED_LIBS := $(VBOX_PATH_APP_PRIVATE_ARCH)
   Where to put the shared libraries, usually the same directory as the private path as the VirtualBox shared libraries are normally not used by any other application. 
VBOX_WITH_ORIGIN :=
   Disable RPATH=$ORIGIN and use a fixed RUNPATH. 
VBOX_WITH_RUNPATH := $(VBOX_PATH_APP_PRIVATE_ARCH)
   Set RUNPATH to the directory where our shared libraries can be found. 
VBOX_PATH_APP_PRIVATE := /usr/share/virtualbox
   This is the applications's private directory, not architecture-dependent. 
VBOX_PATH_APP_DOCS := /usr/share/doc/virtualbox
   Set the directory containing the documentation. The file VirtualBox.chm and UserManual.pdf are searched within this directory. 
VBOX_WITH_TESTCASES :=
   Save compile time by not building the testcases. 
VBOX_WITH_TESTSUITE :=
   Save compile time by not building the testsuite.

Running your build

You can run VirtualBox directly from the build target directory (out/linux.x86/release/bin/) if the build was not hardened. But first of all, you must build and install the VirtualBox kernel module, whose sources will have been copied to the build target directory.

So, issue the following:

cd out/linux.x86/release/bin/src
make
sudo make install
cd ..

Then it should have been installed to your modules directory and you can load it using modprobe vboxdrv. Make sure you give yourself read and write access to /dev/vboxdrv.

Finally, you can start one of the frontends, e.g.

./VirtualBox