1 |
#!/bin/bash |
#!/bin/bash |
2 |
# $Header: /root/magellan-cvs/src/virtualbox/virtualbox-config.sh,v 1.2 2007-04-13 22:51:43 niro Exp $ |
# $Header: /root/magellan-cvs/src/virtualbox/virtualbox-config.sh,v 1.12 2010-02-21 20:06:45 niro Exp $ |
3 |
# Configures virtualbox for Magellan-Linux |
# Configures virtualbox for Magellan-Linux |
4 |
|
|
5 |
LIBDIR=/usr/lib |
LIBDIR=/usr/lib |
6 |
INSTDIR=${LIBDIR}/virtualbox |
INSTDIR=${LIBDIR}/virtualbox |
7 |
VBOXMODULE=vboxdrv.ko |
VBOXMODULE=vboxdrv.ko |
8 |
|
VBOXNETMODULE=vboxnetflt.ko |
9 |
|
VBOXNETADPMODULE=vboxnetadp.ko |
10 |
|
|
11 |
if [[ $(id -u) != 0 ]] |
COLRED="\033[1;6m\033[31m" |
12 |
|
COLGREEN="\033[1;6m\033[32m" |
13 |
|
COLDEFAULT="\033[0m" |
14 |
|
|
15 |
|
if [[ ${NOCOLORS} = true ]] |
16 |
then |
then |
17 |
echo "You must be r00t!" |
COLRED="" |
18 |
exit 1 |
COLGREEN="" |
19 |
|
COLDEFAULT="" |
20 |
fi |
fi |
21 |
|
|
22 |
echo "Running $(basename $0) for kernelversion $(uname -r) ..." |
die() { echo -e "${COLRED}$@${COLDEFAULT}"; exit 1; } |
23 |
|
mecho() { echo -e "${COLGREEN}$@${COLDEFAULT}"; } |
24 |
|
|
25 |
if [ ! -f /lib/modules/$(uname -r)/source/include/linux/version.h ] |
# must be root |
26 |
then |
[[ $(id -u) != 0 ]] && die "You must be r00t!" |
27 |
echo "No includes for $(uname -r) found! Aborting." |
|
28 |
exit 1 |
# check for given argvs |
29 |
fi |
for i in $* |
30 |
|
do |
31 |
|
case $1 in |
32 |
|
--kernel-version) shift; KERNEL_VERSION="$1" ;; |
33 |
|
--kernel-sources) shift; KERNEL_SOURCES="$1" ;; |
34 |
|
esac |
35 |
|
shift |
36 |
|
done |
37 |
|
|
38 |
|
# some sane defaults |
39 |
|
[[ -z ${KERNEL_VERSION} ]] && KERNEL_VERSION="$(uname -r)" |
40 |
|
[[ -z ${KERNEL_SOURCES} ]] && KERNEL_SOURCES="/lib/modules/${KERNEL_VERSION}/source" |
41 |
|
|
42 |
|
mecho "Running $(basename $0) for kernelversion ${KERNEL_VERSION} ..." |
43 |
|
|
44 |
if [[ -f /lib/modules/$(uname -r)/misc/${VBOXMODULE} ]] |
if [ ! -f ${KERNEL_SOURCES}/include/linux/version.h ] |
45 |
then |
then |
46 |
echo "Removing old module ..." |
die "No kernel sources for kernel ${KERNEL_VERSION} found! Aborting." |
|
rm -f /lib/modules/$(uname -r)/misc/${VBOXMODULE} |
|
47 |
fi |
fi |
48 |
|
|
49 |
# compile the module |
for module in ${VBOXMODULE} ${VBOXNETMODULE} ${VBOXNETADPMODULE} |
50 |
cd ${INSTDIR}/src |
do |
51 |
make -C /lib/modules/$(uname -r)/source SUBDIRS=$(pwd) SRCROOT=$(pwd) clean modules |
if [[ -f /lib/modules/${KERNEL_VERSION}/misc/${module} ]] |
52 |
|
then |
53 |
# install the module |
mecho "Removing old ${module} module ..." |
54 |
install -d /lib/modules/$(uname -r)/misc |
# try to unload the modules |
55 |
install -m0644 ${VBOXMODULE} /lib/modules/$(uname -r)/misc |
if [[ -n $(grep "${module} " /proc/modules 2> /dev/null) ]] |
56 |
|
then |
57 |
|
modprobe -r ${module/.ko/} |
58 |
|
fi |
59 |
|
rm -f /lib/modules/${KERNEL_VERSION}/misc/${module} |
60 |
|
fi |
61 |
|
done |
62 |
|
|
63 |
|
for module in ${VBOXMODULE} ${VBOXNETMODULE} ${VBOXNETADPMODULE} |
64 |
|
do |
65 |
|
# compile the module |
66 |
|
cd ${INSTDIR}/src/${module/.ko/} |
67 |
|
|
68 |
|
make -C ${KERNEL_SOURCES} SUBDIRS=$(pwd) SRCROOT=$(pwd) clean || die "mod-compile ${module}" |
69 |
|
|
70 |
|
# need some symver from vboxmodule (must be run after clean!) |
71 |
|
if [[ ${module} = ${VBOXNETMODULE} ]] || [[ ${module} = ${VBOXNETADPMODULE} ]] |
72 |
|
then |
73 |
|
[[ -f ../${VBOXMODULE/.ko/}/Module.symvers ]] && cp ../${VBOXMODULE/.ko/}/Module.symvers . |
74 |
|
fi |
75 |
|
|
76 |
|
make -C ${KERNEL_SOURCES} SUBDIRS=$(pwd) SRCROOT=$(pwd) modules || die "mod-compile ${module}" |
77 |
|
|
78 |
|
# install the modules |
79 |
|
install -d /lib/modules/${KERNEL_VERSION}/misc |
80 |
|
install -m0644 ${module} /lib/modules/${KERNEL_VERSION}/misc || die "mod-install ${module}" |
81 |
|
done |
82 |
|
|
83 |
# calc module dependencies |
# calc module dependencies |
84 |
depmod -ae |
mecho "Calculating module dependencies ..." |
85 |
|
depmod -a ${KERNEL_VERSION} |
86 |
|
|
87 |
|
# re-read udev rules to grant the right permissions |
88 |
|
if [[ -x $(which udevadm) ]] |
89 |
|
then |
90 |
|
mecho "Reloading udev configuration ..." |
91 |
|
$(which udevadm) control --reload-rules |
92 |
|
fi |
93 |
|
|
94 |
# load the module |
# load the module |
95 |
echo "Loading module ${VBOXMODULE} ..." |
if [[ x$(uname -r) = x${KERNEL_VERSION} ]] |
96 |
modprobe $(basename ${VBOXMODULE} .ko) |
then |
97 |
|
for module in ${VBOXMODULE} ${VBOXNETMODULE} ${VBOXNETADPMODULE} |
98 |
|
do |
99 |
|
mecho "Loading kernel-module ${module} ..." |
100 |
|
modprobe $(basename ${module} .ko) |
101 |
|
done |
102 |
|
|
103 |
|
if [ $(echo ${KERNEL_VERSION%%-*} | sed 's:\.::g') -ge 2631 ] |
104 |
|
then |
105 |
|
# fixes NMI warnings with kernels >=2.6.31: |
106 |
|
# vboxdrv: Warning: 2.6.31+ kernel detected. Most likely the hardware performance |
107 |
|
# vboxdrv: counter framework which can generate NMIs is active. |
108 |
|
mecho "Disabled hardware performance counter NMIs ..." |
109 |
|
echo 2 > /proc/sys/kernel/perf_counter_paranoid |
110 |
|
fi |
111 |
|
else |
112 |
|
echo -e ${COLRED} |
113 |
|
echo "Your current running kernel does not match the the module target." |
114 |
|
echo "You must boot into your target kernel and load the modules manually," |
115 |
|
echo "before you can use virtualbox." |
116 |
|
echo -en ${COLDEFAULT} |
117 |
|
fi |
118 |
|
|
119 |
echo |
echo |
120 |
echo "Virtualbox is now configured for your system." |
mecho "Virtualbox is now configured for your system." |
121 |
echo "Do not forget to add you users to the 'virtualbox' group." |
mecho "Do not forget to add your users to the 'virtualbox' group." |
122 |
echo |
echo |
123 |
|
|
124 |
exit 0 |
exit 0 |