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