#!/bin/bash # $Header: /root/magellan-cvs/src/virtualbox/virtualbox-config.sh,v 1.13 2010-06-09 22:29:52 niro Exp $ # Configures virtualbox for Magellan-Linux LIBDIR=/usr/lib INSTDIR=${LIBDIR}/virtualbox VBOXVERSION="$(< ${INSTDIR}/version)" VBOXMODEXT=ko VBOXMODULE=vboxdrv VBOXNETMODULE=vboxnetflt VBOXNETADPMODULE=vboxnetadp COLRED="\033[1;6m\033[31m" COLGREEN="\033[1;6m\033[32m" COLDEFAULT="\033[0m" if [[ ${NOCOLORS} = true ]] then COLRED="" COLGREEN="" COLDEFAULT="" fi die() { echo -e "${COLRED}$@${COLDEFAULT}"; exit 1; } mecho() { echo -e "${COLGREEN}$@${COLDEFAULT}"; } # must be root [[ $(id -u) != 0 ]] && die "You must be r00t!" # check for given argvs for i in $* do case $1 in --kernel-version) shift; KERNEL_VERSION="$1" ;; --kernel-sources) shift; KERNEL_SOURCES="$1" ;; esac shift done # some sane defaults [[ -z ${KERNEL_VERSION} ]] && KERNEL_VERSION="$(uname -r)" [[ -z ${KERNEL_SOURCES} ]] && KERNEL_SOURCES="/lib/modules/${KERNEL_VERSION}/source" mecho "Running $(basename $0) for kernelversion ${KERNEL_VERSION} ..." # check module version an recompile if it doesen't fit else break here compile="no" for module in ${VBOXMODULE} ${VBOXNETMODULE} ${VBOXNETADPMODULE} do myver=$(modinfo -k ${KERNEL_VERSION} -F version ${module} | sed "s:\(.*\)_.*:\1:") if [[ ${VBOXVERSION} != ${myver} ]] then compile="yes" fi done for module in ${VBOXNETADPMODULE} ${VBOXNETMODULE} ${VBOXMODULE} do if [[ -f /lib/modules/${KERNEL_VERSION}/misc/${module}.${VBOXMODEXT} ]] then # try to unload the modules if [[ -n $(grep "${module} " /proc/modules 2> /dev/null) ]] then mecho "Unloading ${module} module ..." modprobe -r ${module} fi fi done if [[ ${compile} = yes ]] then if [ ! -f ${KERNEL_SOURCES}/include/linux/version.h ] then die "No kernel sources for kernel ${KERNEL_VERSION} found! Aborting." fi for module in ${VBOXMODULE} ${VBOXNETMODULE} ${VBOXNETADPMODULE} do if [[ -f /lib/modules/${KERNEL_VERSION}/misc/${module}.${VBOXMODEXT} ]] then mecho "Removing old ${module} module ..." rm -f /lib/modules/${KERNEL_VERSION}/misc/${module}.${VBOXMODEXT} fi done for module in ${VBOXMODULE} ${VBOXNETMODULE} ${VBOXNETADPMODULE} do # compile the module cd ${INSTDIR}/src/${module} make -C ${KERNEL_SOURCES} SUBDIRS=$(pwd) SRCROOT=$(pwd) clean || die "mod-compile ${module}" # need some symver from vboxmodule (must be run after clean!) if [[ ${module} = ${VBOXNETMODULE} ]] || [[ ${module} = ${VBOXNETADPMODULE} ]] then [[ -f ../${VBOXMODULE}/Module.symvers ]] && cp ../${VBOXMODULE}/Module.symvers . fi make -C ${KERNEL_SOURCES} SUBDIRS=$(pwd) SRCROOT=$(pwd) modules || die "mod-compile ${module}" # install the modules install -d /lib/modules/${KERNEL_VERSION}/misc install -m0644 ${module}.${VBOXMODEXT} /lib/modules/${KERNEL_VERSION}/misc || die "mod-install ${module}" done # calc module dependencies mecho "Calculating module dependencies ..." depmod -a ${KERNEL_VERSION} # re-read udev rules to grant the right permissions if [[ -x $(which udevadm) ]] then mecho "Reloading udev configuration ..." $(which udevadm) control --reload-rules fi fi # load the module if [[ x$(uname -r) = x${KERNEL_VERSION} ]] then for module in ${VBOXMODULE} ${VBOXNETMODULE} ${VBOXNETADPMODULE} do mecho "Loading kernel-module ${module} ..." modprobe ${module} done if [ $(echo ${KERNEL_VERSION%%-*} | sed 's:\.::g') -ge 2631 ] then # fixes NMI warnings with kernels >=2.6.31: # vboxdrv: Warning: 2.6.31+ kernel detected. Most likely the hardware performance # vboxdrv: counter framework which can generate NMIs is active. mecho "Disabled hardware performance counter NMIs ..." echo 2 > /proc/sys/kernel/perf_counter_paranoid fi if [ $(echo ${KERNEL_VERSION%%-*} | sed 's:\.::g') -ge 2639 ] then # fixes NMI warnings with kernels >=2.6.31: # vboxdrv: Warning: 2.6.31+ kernel detected. Most likely the hardware performance # vboxdrv: counter framework which can generate NMIs is active. mecho "Disabled hardware performance counter NMIs ..." echo 2 > /proc/sys/kernel/perf_event_paranoid fi else echo -e ${COLRED} echo "Your current running kernel does not match the the module target." echo "You must boot into your target kernel and load the modules manually," echo "before you can use virtualbox." echo -en ${COLDEFAULT} fi echo mecho "Virtualbox is now configured for your system." mecho "Do not forget to add your users to the 'virtualbox' group." echo exit 0