VirtualBox in unRAID

From unRAID
Jump to: navigation, search

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.


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:


For unRAID version 5.x, those packages can be found here:

For unRAID version 5 RC13 and newer (kernel 3.9 and greater), you will also need these packages:


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, just install these 2 packages instead:

Code:

$ installpkg bc-1.06.95-i486-1.txz
$ installpkg kernel-headers-2.6.33.4_smp-x86-1.txz


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


Create a temporary directory (e.g. mkdir /mnt/disk1/tmpdir ) and type: Code:

$ export TMPDIR=/mnt/disk1/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.