Installing VirtualBox in unRAID
Use these instructions with discretion.
This guide is a walk through for unRAID users that want to be able to compile their own kernel headers, and therefore compile and run VirtualBox into unRAID server. Note that a huge amount of RAM is necessary for compile and run VBox, so I recommend 4GB+ of RAM.
Contents
Dependencies
First of all, you have to satisfy these dependencies:
a) Vanilla copy of Linux kernel;
b) gcc, glibc, binutils, make, patch, perl, ncurses, cpio, pkgtools and cxxlibs packages;
c) VirtualBox Linux "All Distributions" 32bits package.
At the time of writing, using unRAID 4.7, all those packages can be found at the following locations:
- VirtualBox --> http://www.virtualbox.org/wiki/Linux_Downloads/
- Linux kernel 2.6.32.9 --> http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.32.9.tar.gz
- gcc --> http://slackware.oregonstate.edu/slackware-12.2/slackware/d/gcc-4.2.4-i486-1.tgz
- glibc --> http://slackware.oregonstate.edu/slackware-12.2/slackware/l/glibc-2.7-i486-17.tgz
- binutils --> http://slackware.oregonstate.edu/slackware-12.2/slackware/d/binutils-2.18.50.0.9-i486-1.tgz
- make --> http://slackware.oregonstate.edu/slackware-12.2/slackware/d/make-3.81-i486-1.tgz
- cxxlibs --> http://slackware.oregonstate.edu/slackware-12.2/slackware/a/cxxlibs-6.0.9-i486-1.tgz
- pkgtools --> http://slackware.osuosl.org/slackware-12.2/slackware/a/pkgtools-12.1.0-noarch-7.tgz
- perl --> http://slackware.osuosl.org/slackware-12.2/slackware/d/perl-5.10.0-i486-1.tgz
- cpio --> http://slackware.osuosl.org/slackware-12.2/slackware/a/cpio-2.5-i486-3.tgz
- patch --> http://slackware.osuosl.org/slackware-12.2/slackware/a/patch-2.5.4-i486-1.tgz
- ncurses --> http://slackware.osuosl.org/slackware-12.2/slackware/l/ncurses-5.6-i486-3.tgz
For unRAID version 5.x, those packages can be found here:
- For unRAID v. 5.0 - i386, grab this version of the kernel instead --> https://www.kernel.org/pub/linux/kernel/v3.x/linux-3.9.6.tar.gz
- VirtualBox --> http://www.virtualbox.org/wiki/Linux_Downloads/
- gcc --> http://slackware.osuosl.org/slackware-13.1/slackware/d/gcc-4.4.4-i486-1.txz
- glibc --> http://slackware.osuosl.org/slackware-13.1/slackware/l/glibc-2.11.1-i486-3.txz
- binutils --> http://slackware.osuosl.org/slackware-13.1/slackware/d/binutils-2.20.51.0.8-i486-1.txz
- make --> http://slackware.osuosl.org/slackware-13.1/slackware/d/make-3.81-i486-1.txz
- cxxlibs --> http://slackware.osuosl.org/slackware-13.1/slackware/a/cxxlibs-6.0.13-i486-2.txz
- perl --> http://slackware.osuosl.org/slackware-13.1/slackware/d/perl-5.10.1-i486-1.txz
- patch --> http://slackware.osuosl.org/slackware-13.1/slackware/a/patch-2.5.4-i486-1.txz
- ncurses --> http://slackware.osuosl.org/slackware-13.1/slackware/l/ncurses-5.7-i486-1.txz
- mpfr --> http://slackware.osuosl.org/slackware-13.1/slackware/l/mpfr-2.4.2p03-i486-1.txz
- gcc-g++ --> http://slackware.osuosl.org/slackware-13.1/slackware/d/gcc-g++-4.4.4-i486-1.txz
For unRAID version 5 RC13 and newer (kernel 3.9 and greater), you will also need these packages:
- bc --> http://slackware.cs.utah.edu/pub/slackware/slackware-13.1/slackware/ap/bc-1.06.95-i486-1.txz
- kernerl headers --> http://slackware.osuosl.org/slackware-13.1/slackware/d/kernel-headers-2.6.33.4_smp-x86-1.txz
Installing the kernel source and making your own headers
First, install the ".tgz" or ".txz" packages from above. Code:
# unRAID 4.7 "tgz" files installpkg binutils-2.18.50.0.9-i486-1.tgz installpkg cpio-2.5-i486-3.tgz installpkg cxxlibs-6.0.9-i486-1.tgz installpkg gcc-4.2.4-i486-1.tgz installpkg glibc-2.7-i486-17.tgz installpkg make-3.81-i486-1.tgz installpkg ncurses-5.6-i486-3.tgz installpkg pkgtools-12.1.0-noarch-7.tgz installpkg patch-2.5.4-i486-1.tgz installpkg perl-5.10.0-i486-1.tgz
# unRAID 5.x "txz" files installpkg binutils-2.20.51.0.8-i486-1.txz installpkg cxxlibs-6.0.13-i486-2.txz installpkg gcc-4.4.4-i486-1.txz installpkg gcc-g++-4.4.4-i486-1.txz installpkg glibc-2.11.1-i486-3.txz installpkg make-3.81-i486-1.txz installpkg mpfr-2.4.2p03-i486-1.txz installpkg ncurses-5.7-i486-1.txz installpkg patch-2.5.4-i486-1.txz installpkg perl-5.10.1-i486-1.txz
Go to "/usr/src" directory, and rename the folder "linux" to "linux_original".
Code:
$ mv /usr/src/linux /usr/src/linux_original
Note: On unRAID 5.x you will see the kernel version at the end of "/usr/src/linux". For example in 5.0 - i386, use this command instead. Code:
$ mv /usr/src/linux-3.9.6p-unRAID /usr/src/linux_original
Now extract the vanilla kernel file (change linux-2.6.32.9.tar.gz to match your version's kernel) into "/usr/src":
Code:
$ tar -C /usr/src -zxvf linux-2.6.32.9.tar.gz
Link the new source directory (change linux-2.6.32.9 to match your version's kernel) to "/usr/src/linux" path:
Code:
$ ln -sf /usr/src/linux-2.6.32.9 /usr/src/linux
Copy all default drivers and configuration to the new source directory:
Code:
$ cp -rf /usr/src/linux_original/* /usr/src/linux/ $ cp -f /usr/src/linux_original/.config /usr/src/linux/
Move existing kernel headers includes, and replace them with the new source includes:
Code:
$ [ -e "/usr/include/linux" ] && mv /usr/include/linux /usr/include/linux_original $ [ -e "/usr/include/asm-generic" ] && mv /usr/include/asm-generic /usr/include/asm-generic_original $ [ -e "/usr/include/asm" ] && mv /usr/include/asm /usr/include/asm_original
On unRAID 5 RC12 and lower (including unRAID 4.7), you can link the following sources:
Code:
$ ln -sf /usr/src/linux/include/asm-generic /usr/include/asm-generic $ ln -sf /usr/src/linux/include/linux /usr/include/linux $ ln -sf /usr/src/linux/arch/x86/include/asm /usr/include/asm
On unRAID 5 RC13 and newer, the kernel headers API for userspace had been splitted: http://lwn.net/Articles/507794/ So the links are a bit different:
Code:
$ ln -sf /usr/src/linux/include/uapi/asm-generic /usr/include/asm-generic $ ln -sf /usr/src/linux/include/uapi/linux /usr/include/linux $ ln -sf /usr/src/linux/arch/x86/include/uapi/asm /usr/include/asm $ cp /usr/src/linux/tools/perf/util/include/linux/compiler.h /usr/include/linux/
Now it's time to compile the kernel source:
Code:
$ cd /usr/src/linux $ make oldconfig && make
Congratulations, now you have your own headers!
Installing VirtualBox
Make a directory to store your configuration (e.g. /boot/custom/vbox ), and link it to root home folder: Code:
$ mkdir -p /boot/custom/vbox && ln -sf /boot/custom/vbox /root/.VirtualBox
Run the VirtualBox<version>.run file:
Code:
$ sh VirtualBox<version>.run
If it claims that the temporary dir doesn't have enough space, you have to make a new temp dir (e.g. /mnt/cache/tmp ) and type:
Code:
$ export TMPDIR=<new tmpdir> && sh VirtualBox<version>.run
If everything worked fine, you now have a working copy of VirtualBox running into your server. It's time to make it permanent over reboots.
Making a VBox package
VirtualBox installer extracts binary files to "/opt/VirtualBox" directory, creates an udev rule, compiles and insert the kernel modules and creates a lot of links, so we have to do all these steps using a package.
1) Create a folder for temporary files (e.g. /mnt/cache/vbox_package ):
Code:
$ mkdir /mnt/cache/vbox_package
2) Copy these directories to your temp folder:
Code:
$ cd /mnt/cache/vbox_package/ $ cp --parents -rf /opt/VirtualBox ./ $ cp --parents -f /lib/modules/`uname -r`/misc/vboxdrv.ko ./ $ cp --parents -f /lib/modules/`uname -r`/misc/vboxnetadp.ko ./ $ cp --parents -f /lib/modules/`uname -r`/misc/vboxnetflt.ko ./ $ cp --parents -rf /etc/vbox ./ $ cp --parents -f /etc/udev/rules.d/10-vboxdrv.rules ./
3) Make an "install" dir under your temp folder:
Code:
$ mkdir /mnt/cache/vbox_package/install
4) For unRAID 4.7, under the new "install" folder, create a "doinst.sh" file with this content:
Code:
# Insert VBox modules on the kernel insmod /lib/modules/`uname -r`/misc/vboxdrv.ko insmod /lib/modules/`uname -r`/misc/vboxnetadp.ko insmod /lib/modules/`uname -r`/misc/vboxnetflt.ko # Create some necessary links ln -sf /opt/VirtualBox/VBox.sh /usr/bin/VBoxHeadless ln -sf /opt/VirtualBox/VBox.sh /usr/bin/VBoxManage ln -sf /opt/VirtualBox/VBox.sh /usr/bin/VBoxSDL ln -sf /opt/VirtualBox/VBox.sh /usr/bin/VBoxVRDP ln -sf /opt/VirtualBox/VBox.sh /usr/bin/VirtualBox ln -sf /usr/bin/VBoxHeadless /usr/bin/vboxheadless ln -sf /usr/bin/VBoxManage /usr/bin/vboxmanage ln -sf /usr/bin/VBoxSDL /usr/bin/vboxsdl ln -sf /opt/VirtualBox/VBox.sh /usr/bin/vboxwebsrv # Reload udev rules udevadm control --reload-rules # Expac USB fix groupadd vboxusers usermod -a vboxusers root usermod -a vboxusers nobody mkdir /dev/vboxusb -m 0750 chown root:vboxusers /dev/vboxusb # Create and link the configuration dir mkdir -p /boot/custom/vbox -m 0777 ln -sf /boot/custom/vbox /root/.VirtualBox # Auto-generated rules
4) Or for unRAID 5.x, under the new "install" folder, create a "doinst.sh" file with this content:
Code:
# Insert VBox modules on the kernel insmod /lib/modules/`uname -r`/misc/vboxdrv.ko insmod /lib/modules/`uname -r`/misc/vboxnetadp.ko insmod /lib/modules/`uname -r`/misc/vboxnetflt.ko # Create some necessary links ln -sf /opt/VirtualBox/VBox.sh /usr/bin/VBoxHeadless ln -sf /opt/VirtualBox/VBox.sh /usr/bin/VBoxManage ln -sf /opt/VirtualBox/VBox.sh /usr/bin/VBoxSDL ln -sf /opt/VirtualBox/VBox.sh /usr/bin/VBoxVRDP ln -sf /opt/VirtualBox/VBox.sh /usr/bin/VirtualBox ln -sf /usr/bin/VBoxHeadless /usr/bin/vboxheadless ln -sf /usr/bin/VBoxManage /usr/bin/vboxmanage ln -sf /usr/bin/VBoxSDL /usr/bin/vboxsdl ln -sf /opt/VirtualBox/VBox.sh /usr/bin/vboxwebsrv # Reload udev rules udevadm control --reload-rules # Expac USB fix groupadd vboxusers usermod -aG vboxusers root usermod -aG vboxusers nobody mkdir /dev/vboxusb -m 0750 chown root:vboxusers /dev/vboxusb # Create and link the configuration dir mkdir -p /boot/custom/vbox -m 0777 ln -sf /boot/custom/vbox /root/.VirtualBox # Auto-generated rules
5) Finally, create the package:
Code:
$ cd /mnt/cache/vbox_package && makepkg /boot/vbox-unRAID.tgz
Other considerations
VBox can be managed from command line, but there is a very nice GUI that runs in php, named phpvirtualbox: http://code.google.com/p/phpvirtualbox/
If you want to run it from your unRAID server, you will need a http server, like lighttpd, and the php package installed. If anyone wishes to contribute with directions, please be my guest.
Helpfull scripts
This are scripts I made myself trying to automate the headers compilation and the VirtualBox package creation. Please note that those scripts doesn't have any control for errors or missing links, so you're advised to check all links before run them.
Headers and development tools to unRAID 4.7:
#!/bin/bash P="$(dirname "$(readlink -f ${BASH_SOURCE[0]})")" [ ! -d "$P/packages" ] && mkdir $P/packages cd $P/packages [ ! -e "linux-2.6.32.9.tar.gz" ] && wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.32.9.tar.gz [ ! -e "gcc-4.2.4-i486-1.tgz" ] && wget http://slackware.oregonstate.edu/slackware-12.2/slackware/d/gcc-4.2.4-i486-1.tgz [ ! -e "glibc-2.7-i486-17.tgz" ] && wget http://slackware.oregonstate.edu/slackware-12.2/slackware/l/glibc-2.7-i486-17.tgz [ ! -e "binutils-2.18.50.0.9-i486-1.tgz" ] && wget http://slackware.oregonstate.edu/slackware-12.2/slackware/d/binutils-2.18.50.0.9-i486-1.tgz [ ! -e "make-3.81-i486-1.tgz" ] && wget http://slackware.oregonstate.edu/slackware-12.2/slackware/d/make-3.81-i486-1.tgz [ ! -e "cxxlibs-6.0.9-i486-1.tgz" ] && wget http://slackware.oregonstate.edu/slackware-12.2/slackware/a/cxxlibs-6.0.9-i486-1.tgz [ ! -e "pkgtools-12.1.0-noarch-7.tgz" ] && wget http://slackware.osuosl.org/slackware-12.2/slackware/a/pkgtools-12.1.0-noarch-7.tgz [ ! -e "perl-5.10.0-i486-1.tgz" ] && wget http://slackware.osuosl.org/slackware-12.2/slackware/d/perl-5.10.0-i486-1.tgz [ ! -e "cpio-2.5-i486-3.tgz" ] && wget http://slackware.osuosl.org/slackware-12.2/slackware/a/cpio-2.5-i486-3.tgz [ ! -e "patch-2.5.4-i486-1.tgz" ] && wget http://slackware.osuosl.org/slackware-12.2/slackware/a/patch-2.5.4-i486-1.tgz [ ! -e "ncurses-5.6-i486-3.tgz" ] && wget http://slackware.osuosl.org/slackware-12.2/slackware/l/ncurses-5.6-i486-3.tgz installpkg *.tgz cd / mv /usr/src/linux /usr/src/linux_original if [ ! -d "$P/headers" ]; then mkdir -p $P/headers tar -C $P/headers -zxvf $P/packages/linux-2.6.32.9.tar.gz cp -rf /usr/src/linux_original/* $P/headers/linux-2.6.32.9/ cp -f /usr/src/linux_original/.config $P/headers/linux-2.6.32.9/ fi ln -sf $P/headers/linux-2.6.32.9 /usr/src/linux [ -e "/usr/include/linux" ] && mv /usr/include/linux /usr/include/linux_original [ -e "/usr/include/asm-generic" ] && mv /usr/include/asm-generic /usr/include/asm-generic_original [ -e "/usr/include/asm" ] && mv /usr/include/asm /usr/include/asm_original ln -sf /usr/src/linux/include/asm-generic /usr/include/asm-generic ln -sf /usr/src/linux/include/linux /usr/include/linux ln -sf /usr/src/linux/arch/x86/include/asm /usr/include/asm cd /usr/src/linux && make oldconfig && make
Headers and development tools to unRAID 5.0:
#!/bin/bash P="$(dirname "$(readlink -f ${BASH_SOURCE[0]})")" KVERSION="3.9.6" KDIR="/usr/src/linux-$(uname -r)" HEADERS="kernel-headers-$(uname -r).txz" [ ! -d "$P/packages" ] && mkdir $P/packages URLS=" https://www.kernel.org/pub/linux/kernel/v3.x/linux-3.9.6.tar.gz http://linorg.usp.br/slackware/slackware-13.1/slackware/d/gcc-4.4.4-i486-1.txz http://linorg.usp.br/slackware/slackware-13.1/slackware/l/glibc-2.11.1-i486-3.txz http://linorg.usp.br/slackware/slackware-13.1/slackware/d/binutils-2.20.51.0.8-i486-1.txz http://linorg.usp.br/slackware/slackware-13.1/slackware/d/make-3.81-i486-1.txz http://linorg.usp.br/slackware/slackware-13.1/slackware/a/cxxlibs-6.0.13-i486-2.txz http://linorg.usp.br/slackware/slackware-13.1/slackware/d/perl-5.10.1-i486-1.txz http://linorg.usp.br/slackware/slackware-13.1/slackware/a/patch-2.5.4-i486-1.txz http://linorg.usp.br/slackware/slackware-13.1/slackware/l/ncurses-5.7-i486-1.txz http://linorg.usp.br/slackware/slackware-13.1/slackware/l/mpfr-2.4.2p03-i486-1.txz http://linorg.usp.br/slackware/slackware-13.1/slackware/d/gcc-g++-4.4.4-i486-1.txz http://linorg.usp.br/slackware/slackware-13.1/slackware/ap/bc-1.06.95-i486-1.txz " IFS=$'\n'; set -f; for url in $URLS do echo $url PKGPATH=${P}/packages/$(basename $url) [ ! -e "${PKGPATH}" ] && wget --no-check-certificate $url -O ${PKGPATH} [[ "${PKGPATH}" == *.txz ]] && upgradepkg --install-new ${PKGPATH} if [[ "${PKGPATH}" == *.tar.gz ]]; then [ ! -d "$P/linux-$KVERSION" ] && tar -C $P -zxvf ${PKGPATH}; fi done [ -e "${HEADERS}" ] && installpkg ${HEADERS} && exit 0 rm /usr/src/linux ln -sf $P/linux-$KVERSION /usr/src/linux cd /usr/src/linux-$(uname -r) && find . -maxdepth 1 -exec cp -rf '{}' $P/linux-$KVERSION/ \; dirs=$(find /usr/src/linux/include/uapi/* -maxdepth 0 -printf "%f\n"); mkdir /usr/include_bkp for d in $dirs; do [ -e "/usr/include/$d" ] && mv /usr/include/$d /usr/include_bkp/ ln -sf /usr/src/linux/include/uapi/$d /usr/include/ done [ -e "/usr/include/asm" ] && mv /usr/include/asm /usr/include_bkp ln -sf /usr/src/linux/arch/x86/include/uapi/asm /usr/include/ cp /usr/src/linux/tools/perf/util/include/linux/compiler.h /usr/include/linux/ cd /usr/src/linux && yes "" | make oldconfig && make -j4 [ -e "$P/root" ] && rm -rf $P/root/; mkdir -p $P/root/usr make headers_install INSTALL_HDR_PATH=$P/root/usr cd $P/root/ && makepkg ../kernel-headers-$(uname -r).txz
VirtualBox package creation:
#!/bin/bash VBOXVERSION="4.0.6" P="$(dirname "$(readlink -f ${BASH_SOURCE[0]})")" TMPDIR="$P/vbox_temp" [ -d "$TMPDIR" ] && rm -rf $TMPDIR mkdir $TMPDIR cd $TMPDIR cp --parents -rf /opt/VirtualBox $TMPDIR/ cp --parents -f /lib/modules/`uname -r`/misc/vboxdrv.ko $TMPDIR/ cp --parents -f /lib/modules/`uname -r`/misc/vboxnetadp.ko $TMPDIR/ cp --parents -f /lib/modules/`uname -r`/misc/vboxnetflt.ko $TMPDIR/ cp --parents -rf /etc/vbox $TMPDIR/ cp --parents -f /etc/udev/rules.d/10-vboxdrv.rules $TMPDIR/ mkdir $TMPDIR/install cat >>$TMPDIR/install/doinst.sh << 'THE_END_OF_SCRIPT' # Insert VBox modules on the kernel insmod /lib/modules/`uname -r`/misc/vboxdrv.ko insmod /lib/modules/`uname -r`/misc/vboxnetadp.ko insmod /lib/modules/`uname -r`/misc/vboxnetflt.ko # Create some necessary links ln -sf /opt/VirtualBox/VBox.sh /usr/bin/VBoxHeadless ln -sf /opt/VirtualBox/VBox.sh /usr/bin/VBoxManage ln -sf /opt/VirtualBox/VBox.sh /usr/bin/VBoxSDL ln -sf /opt/VirtualBox/VBox.sh /usr/bin/VBoxVRDP ln -sf /opt/VirtualBox/VBox.sh /usr/bin/VirtualBox ln -sf /usr/bin/VBoxHeadless /usr/bin/vboxheadless ln -sf /usr/bin/VBoxManage /usr/bin/vboxmanage ln -sf /usr/bin/VBoxSDL /usr/bin/vboxsdl ln -sf /opt/VirtualBox/VBox.sh /usr/bin/vboxwebsrv # Reload udev rules udevadm control --reload-rules # Link the configuration dir [ ! -d "/boot/custom/vbox" ] && mkdir -p /boot/custom/vbox ln -sf /boot/custom/vbox /root/.VirtualBox # Auto-created rules THE_END_OF_SCRIPT cd $TMPDIR/ && makepkg ../VirtualBox-${VBOXVERSION}-unRAID.tgz rm -rf $TMPDIR