Annotation of /trunk/virtualbox/virtualbox-config.sh
Parent Directory | Revision Log
Revision 1672 -
(hide annotations)
(download)
(as text)
Sat Mar 3 02:48:55 2012 UTC (12 years, 6 months ago) by niro
File MIME type: application/x-sh
File size: 4534 byte(s)
Sat Mar 3 02:48:55 2012 UTC (12 years, 6 months ago) by niro
File MIME type: application/x-sh
File size: 4534 byte(s)
-compile missing vboxpci module, get virtualbox location from vbox.cfg, fixed noisyness and some other issues
1 | niro | 126 | #!/bin/bash |
2 | niro | 1672 | # $Id$ |
3 | niro | 126 | # Configures virtualbox for Magellan-Linux |
4 | |||
5 | niro | 1672 | # get INSTALL_DIR location |
6 | source /etc/vbox/vbox.cfg | ||
7 | |||
8 | VBOXVERSION="$(< ${INSTALL_DIR}/version)" | ||
9 | niro | 1049 | VBOXMODEXT=ko |
10 | VBOXMODULE=vboxdrv | ||
11 | VBOXNETMODULE=vboxnetflt | ||
12 | VBOXNETADPMODULE=vboxnetadp | ||
13 | niro | 1672 | VBOXPCIMODULE=vboxpci |
14 | KERNELMODULES="${VBOXMODULE} ${VBOXNETMODULE} ${VBOXNETADPMODULE} ${VBOXPCIMODULE}" | ||
15 | niro | 126 | |
16 | niro | 129 | COLRED="\033[1;6m\033[31m" |
17 | COLGREEN="\033[1;6m\033[32m" | ||
18 | COLDEFAULT="\033[0m" | ||
19 | |||
20 | if [[ ${NOCOLORS} = true ]] | ||
21 | niro | 127 | then |
22 | niro | 129 | COLRED="" |
23 | COLGREEN="" | ||
24 | COLDEFAULT="" | ||
25 | niro | 127 | fi |
26 | |||
27 | niro | 129 | die() { echo -e "${COLRED}$@${COLDEFAULT}"; exit 1; } |
28 | mecho() { echo -e "${COLGREEN}$@${COLDEFAULT}"; } | ||
29 | niro | 126 | |
30 | niro | 129 | # must be root |
31 | [[ $(id -u) != 0 ]] && die "You must be r00t!" | ||
32 | |||
33 | niro | 229 | # check for given argvs |
34 | for i in $* | ||
35 | do | ||
36 | case $1 in | ||
37 | --kernel-version) shift; KERNEL_VERSION="$1" ;; | ||
38 | --kernel-sources) shift; KERNEL_SOURCES="$1" ;; | ||
39 | esac | ||
40 | shift | ||
41 | done | ||
42 | niro | 129 | |
43 | niro | 229 | # some sane defaults |
44 | [[ -z ${KERNEL_VERSION} ]] && KERNEL_VERSION="$(uname -r)" | ||
45 | [[ -z ${KERNEL_SOURCES} ]] && KERNEL_SOURCES="/lib/modules/${KERNEL_VERSION}/source" | ||
46 | |||
47 | mecho "Running $(basename $0) for kernelversion ${KERNEL_VERSION} ..." | ||
48 | |||
49 | niro | 1672 | # check module version and recompile if it doesen't fit else break here |
50 | compile="yes" | ||
51 | for module in ${KERNELMODULES} | ||
52 | niro | 860 | do |
53 | niro | 1672 | if [[ -f /lib/modules/${KERNEL_VERSION}/misc/${module}.${VBOXMODEXT} ]] |
54 | niro | 520 | then |
55 | niro | 1672 | myver=$(modinfo -k ${KERNEL_VERSION} -F version ${module} | sed "s:\(.*\)_.*:\1:") |
56 | if [[ ${VBOXVERSION} = ${myver} ]] | ||
57 | then | ||
58 | compile="no" | ||
59 | fi | ||
60 | niro | 1049 | done |
61 | |||
62 | niro | 1672 | for module in ${KERNELMODULES} |
63 | niro | 1049 | do |
64 | if [[ -f /lib/modules/${KERNEL_VERSION}/misc/${module}.${VBOXMODEXT} ]] | ||
65 | then | ||
66 | niro | 860 | # try to unload the modules |
67 | if [[ -n $(grep "${module} " /proc/modules 2> /dev/null) ]] | ||
68 | then | ||
69 | niro | 1049 | mecho "Unloading ${module} module ..." |
70 | modprobe -r ${module} | ||
71 | niro | 860 | fi |
72 | niro | 520 | fi |
73 | niro | 860 | done |
74 | niro | 126 | |
75 | niro | 1049 | if [[ ${compile} = yes ]] |
76 | then | ||
77 | if [ ! -f ${KERNEL_SOURCES}/include/linux/version.h ] | ||
78 | niro | 860 | then |
79 | niro | 1049 | die "No kernel sources for kernel ${KERNEL_VERSION} found! Aborting." |
80 | niro | 860 | fi |
81 | |||
82 | niro | 1672 | for module in ${KERNELMODULES} |
83 | niro | 1049 | do |
84 | if [[ -f /lib/modules/${KERNEL_VERSION}/misc/${module}.${VBOXMODEXT} ]] | ||
85 | then | ||
86 | mecho "Removing old ${module} module ..." | ||
87 | rm -f /lib/modules/${KERNEL_VERSION}/misc/${module}.${VBOXMODEXT} | ||
88 | fi | ||
89 | done | ||
90 | niro | 860 | |
91 | niro | 1672 | # compile the modules |
92 | pushd ${INSTALL_DIR}/src | ||
93 | for module in ${KERNELMODULES} | ||
94 | niro | 1049 | do |
95 | niro | 1672 | make -C ${module} KBUILD_VERBOSE=1 clean || die "mod-compile ${module}" |
96 | niro | 860 | |
97 | niro | 1049 | # need some symver from vboxmodule (must be run after clean!) |
98 | niro | 1672 | if [[ ${module} = ${VBOXNETMODULE} ]] || |
99 | [[ ${module} = ${VBOXNETADPMODULE} ]] || | ||
100 | [[ ${module} = ${VBOXPCIMODULE} ]] | ||
101 | niro | 1049 | then |
102 | niro | 1672 | [[ -f ${VBOXMODULE}/Module.symvers ]] && cp ${VBOXMODULE}/Module.symvers ${module} |
103 | niro | 1049 | fi |
104 | niro | 126 | |
105 | niro | 1672 | make -C ${module} KBUILD_VERBOSE=1 || die "mod-compile ${module}" |
106 | niro | 1049 | |
107 | # install the modules | ||
108 | install -d /lib/modules/${KERNEL_VERSION}/misc | ||
109 | niro | 1672 | install -m0644 ${module}/${module}.${VBOXMODEXT} /lib/modules/${KERNEL_VERSION}/misc || die "mod-install ${module}" |
110 | |||
111 | # clean up | ||
112 | make -C ${module} KBUILD_VERBOSE=1 clean || die "mod-compile ${module}" | ||
113 | niro | 1049 | done |
114 | niro | 1672 | popd |
115 | niro | 1049 | |
116 | # calc module dependencies | ||
117 | mecho "Calculating module dependencies ..." | ||
118 | depmod -a ${KERNEL_VERSION} | ||
119 | |||
120 | # re-read udev rules to grant the right permissions | ||
121 | if [[ -x $(which udevadm) ]] | ||
122 | then | ||
123 | mecho "Reloading udev configuration ..." | ||
124 | niro | 1672 | udevadm control --reload-rules |
125 | niro | 1049 | fi |
126 | niro | 129 | fi |
127 | |||
128 | niro | 126 | # load the module |
129 | niro | 230 | if [[ x$(uname -r) = x${KERNEL_VERSION} ]] |
130 | niro | 229 | then |
131 | niro | 1672 | for module in ${KERNELMODULES} |
132 | niro | 860 | do |
133 | mecho "Loading kernel-module ${module} ..." | ||
134 | niro | 1049 | modprobe ${module} |
135 | niro | 860 | done |
136 | niro | 988 | |
137 | niro | 1389 | if [ $(echo ${KERNEL_VERSION%%-*} | sed 's:\.::g') -ge 2639 ] |
138 | niro | 988 | then |
139 | # fixes NMI warnings with kernels >=2.6.31: | ||
140 | # vboxdrv: Warning: 2.6.31+ kernel detected. Most likely the hardware performance | ||
141 | # vboxdrv: counter framework which can generate NMIs is active. | ||
142 | mecho "Disabled hardware performance counter NMIs ..." | ||
143 | niro | 1389 | echo 2 > /proc/sys/kernel/perf_event_paranoid |
144 | |||
145 | elif [ $(echo ${KERNEL_VERSION%%-*} | sed 's:\.::g') -ge 2631 ] | ||
146 | niro | 1379 | then |
147 | # fixes NMI warnings with kernels >=2.6.31: | ||
148 | # vboxdrv: Warning: 2.6.31+ kernel detected. Most likely the hardware performance | ||
149 | # vboxdrv: counter framework which can generate NMIs is active. | ||
150 | mecho "Disabled hardware performance counter NMIs ..." | ||
151 | niro | 1389 | echo 2 > /proc/sys/kernel/perf_counter_paranoid |
152 | niro | 1379 | fi |
153 | niro | 229 | else |
154 | echo -e ${COLRED} | ||
155 | echo "Your current running kernel does not match the the module target." | ||
156 | niro | 860 | echo "You must boot into your target kernel and load the modules manually," |
157 | niro | 986 | echo "before you can use virtualbox." |
158 | niro | 229 | echo -en ${COLDEFAULT} |
159 | fi | ||
160 | niro | 126 | |
161 | echo | ||
162 | niro | 129 | mecho "Virtualbox is now configured for your system." |
163 | niro | 1406 | mecho "Do not forget to add your users to the 'vboxusers' group." |
164 | niro | 126 | echo |
165 | |||
166 | exit 0 |