1 |
#!/bin/bash |
#!/bin/bash |
2 |
# $Header: /root/magellan-cvs/src/virtualbox/virtualbox-config.sh,v 1.8 2008-03-22 20:19:30 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" |
43 |
|
|
44 |
mecho "Running $(basename $0) for kernelversion ${KERNEL_VERSION} ..." |
mecho "Running $(basename $0) for kernelversion ${KERNEL_VERSION} ..." |
45 |
|
|
46 |
if [ ! -f ${KERNEL_SOURCES}/include/linux/version.h ] |
# check module version an recompile if it doesen't fit else break here |
47 |
then |
compile="no" |
48 |
die "No kernel sources for kernel ${KERNEL_VERSION} found! Aborting." |
for module in ${VBOXMODULE} ${VBOXNETMODULE} ${VBOXNETADPMODULE} |
49 |
fi |
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/${KERNEL_VERSION}/misc/${VBOXMODULE} ]] |
if [[ ${compile} = yes ]] |
71 |
then |
then |
72 |
mecho "Removing old module ..." |
if [ ! -f ${KERNEL_SOURCES}/include/linux/version.h ] |
|
# try to unload the module |
|
|
if [[ -n $(grep "${VBOXMODULE} " /proc/modules 2> /dev/null) ]] |
|
73 |
then |
then |
74 |
modprobe -r ${VBOXMODULE/.ko/} |
die "No kernel sources for kernel ${KERNEL_VERSION} found! Aborting." |
75 |
fi |
fi |
|
rm -f /lib/modules/${KERNEL_VERSION}/misc/${VBOXMODULE} |
|
|
fi |
|
76 |
|
|
77 |
# compile the module |
for module in ${VBOXMODULE} ${VBOXNETMODULE} ${VBOXNETADPMODULE} |
78 |
cd ${INSTDIR}/src |
do |
79 |
make -C ${KERNEL_SOURCES} SUBDIRS=$(pwd) SRCROOT=$(pwd) clean modules || die "mod-compile" |
if [[ -f /lib/modules/${KERNEL_VERSION}/misc/${module}.${VBOXMODEXT} ]] |
80 |
|
then |
81 |
# install the module |
mecho "Removing old ${module} module ..." |
82 |
install -d /lib/modules/${KERNEL_VERSION}/misc |
rm -f /lib/modules/${KERNEL_VERSION}/misc/${module}.${VBOXMODEXT} |
83 |
install -m0644 ${VBOXMODULE} /lib/modules/${KERNEL_VERSION}/misc || die "mod-install" |
fi |
84 |
|
done |
85 |
# calc module dependencies |
|
86 |
mecho "Calculating module dependencies ..." |
for module in ${VBOXMODULE} ${VBOXNETMODULE} ${VBOXNETADPMODULE} |
87 |
depmod -ae ${KERNEL_VERSION} |
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 |
# re-read udev rules to grant the right permissions |
111 |
if [[ -x $(which udevcontrol) ]] |
if [[ -x $(which udevadm) ]] |
112 |
then |
then |
113 |
mecho "Reloading udev configuration ..." |
mecho "Reloading udev configuration ..." |
114 |
$(which udevcontrol) reload_rules |
$(which udevadm) control --reload-rules |
115 |
|
fi |
116 |
fi |
fi |
117 |
|
|
118 |
# load the module |
# load the module |
119 |
if [[ x$(uname -r) = x${KERNEL_VERSION} ]] |
if [[ x$(uname -r) = x${KERNEL_VERSION} ]] |
120 |
then |
then |
121 |
mecho "Loading kernel-module ${VBOXMODULE} ..." |
for module in ${VBOXMODULE} ${VBOXNETMODULE} ${VBOXNETADPMODULE} |
122 |
modprobe $(basename ${VBOXMODULE} .ko) |
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 |
|
if [ $(echo ${KERNEL_VERSION%%-*} | sed 's:\.::g') -ge 2639 ] |
136 |
|
then |
137 |
|
# fixes NMI warnings with kernels >=2.6.31: |
138 |
|
# vboxdrv: Warning: 2.6.31+ kernel detected. Most likely the hardware performance |
139 |
|
# vboxdrv: counter framework which can generate NMIs is active. |
140 |
|
mecho "Disabled hardware performance counter NMIs ..." |
141 |
|
echo 2 > /proc/sys/kernel/perf_event_paranoid |
142 |
|
fi |
143 |
else |
else |
144 |
echo -e ${COLRED} |
echo -e ${COLRED} |
145 |
echo "Your current running kernel does not match the the module target." |
echo "Your current running kernel does not match the the module target." |
146 |
echo "You must boot into your target kernel and load the module manually," |
echo "You must boot into your target kernel and load the modules manually," |
147 |
echo "before you can use virtual box." |
echo "before you can use virtualbox." |
148 |
echo -en ${COLDEFAULT} |
echo -en ${COLDEFAULT} |
149 |
fi |
fi |
150 |
|
|