Annotation of /trunk/virtualbox/virtualbox-config.sh
Parent Directory | Revision Log
Revision 2057 -
(hide annotations)
(download)
(as text)
Wed Jan 30 13:41:46 2013 UTC (11 years, 9 months ago) by niro
File MIME type: application/x-sh
File size: 5599 byte(s)
Wed Jan 30 13:41:46 2013 UTC (11 years, 9 months ago) by niro
File MIME type: application/x-sh
File size: 5599 byte(s)
-use internal bash function type instead of which to reduce runtime-dependencies
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 | niro | 1684 | 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 | 1684 | usage() |
30 | { | ||
31 | echo "Usage: $(basename $0 .sh) [opts]" | ||
32 | echo "Options are:" | ||
33 | echo " --kernel-version - build modules for given kernel version not current" | ||
34 | echo " --kernel-sources - use kernel sources different from default path" | ||
35 | echo " --force - force a rebuild of the kernel modules even if they exist" | ||
36 | echo " --verbose - be verbose while building the modules" | ||
37 | echo " --help - show this help" | ||
38 | exit | ||
39 | } | ||
40 | niro | 126 | |
41 | niro | 129 | # must be root |
42 | [[ $(id -u) != 0 ]] && die "You must be r00t!" | ||
43 | |||
44 | niro | 229 | # check for given argvs |
45 | for i in $* | ||
46 | do | ||
47 | case $1 in | ||
48 | --kernel-version) shift; KERNEL_VERSION="$1" ;; | ||
49 | --kernel-sources) shift; KERNEL_SOURCES="$1" ;; | ||
50 | niro | 1684 | --force) FORCED_REBUILD="1" ;; |
51 | --verbose) VERBOSE="1" ;; | ||
52 | --help) usage ;; | ||
53 | niro | 229 | esac |
54 | shift | ||
55 | done | ||
56 | niro | 129 | |
57 | niro | 229 | # some sane defaults |
58 | [[ -z ${KERNEL_VERSION} ]] && KERNEL_VERSION="$(uname -r)" | ||
59 | [[ -z ${KERNEL_SOURCES} ]] && KERNEL_SOURCES="/lib/modules/${KERNEL_VERSION}/source" | ||
60 | niro | 1684 | [[ -z ${FORCED_REBUILD} ]] && FORCED_REBUILD="0" |
61 | [[ -z ${VERBOSE} ]] && VERBOSE="0" | ||
62 | [[ ${VERBOSE} = 0 ]] && makequiet="-s" | ||
63 | niro | 229 | |
64 | mecho "Running $(basename $0) for kernelversion ${KERNEL_VERSION} ..." | ||
65 | |||
66 | niro | 1672 | # check module version and recompile if it doesen't fit else break here |
67 | compile="yes" | ||
68 | niro | 1684 | for module in ${KERNELMODULES[*]} |
69 | niro | 860 | do |
70 | niro | 1672 | if [[ -f /lib/modules/${KERNEL_VERSION}/misc/${module}.${VBOXMODEXT} ]] |
71 | niro | 520 | then |
72 | niro | 1672 | myver=$(modinfo -k ${KERNEL_VERSION} -F version ${module} | sed "s:\(.*\)_.*:\1:") |
73 | niro | 1684 | if [[ ${VBOXVERSION} = ${myver} ]] && [[ ${FORCED_REBUILD} = 0 ]] |
74 | niro | 1672 | then |
75 | compile="no" | ||
76 | fi | ||
77 | niro | 1684 | fi |
78 | niro | 1049 | done |
79 | |||
80 | niro | 1684 | # try to unload the modules in reverse order to honor dependencies |
81 | count=${#KERNELMODULES[*]} | ||
82 | for (( i=count-1; i>=0; i-- )) | ||
83 | niro | 1049 | do |
84 | niro | 1684 | if [[ -f /lib/modules/${KERNEL_VERSION}/misc/${KERNELMODULES[${i}]}.${VBOXMODEXT} ]] |
85 | niro | 1049 | then |
86 | niro | 1684 | if [[ -n $(grep "${KERNELMODULES[${i}]} " /proc/modules 2> /dev/null) ]] |
87 | niro | 860 | then |
88 | niro | 1684 | mecho "Unloading ${KERNELMODULES[${i}]} module ..." |
89 | modprobe -r ${KERNELMODULES[${i}]} | ||
90 | niro | 860 | fi |
91 | niro | 520 | fi |
92 | niro | 860 | done |
93 | niro | 126 | |
94 | niro | 1049 | if [[ ${compile} = yes ]] |
95 | then | ||
96 | if [ ! -f ${KERNEL_SOURCES}/include/linux/version.h ] | ||
97 | niro | 860 | then |
98 | niro | 1049 | die "No kernel sources for kernel ${KERNEL_VERSION} found! Aborting." |
99 | niro | 860 | fi |
100 | |||
101 | niro | 1684 | for module in ${KERNELMODULES[*]} |
102 | niro | 1049 | do |
103 | if [[ -f /lib/modules/${KERNEL_VERSION}/misc/${module}.${VBOXMODEXT} ]] | ||
104 | then | ||
105 | mecho "Removing old ${module} module ..." | ||
106 | rm -f /lib/modules/${KERNEL_VERSION}/misc/${module}.${VBOXMODEXT} | ||
107 | fi | ||
108 | done | ||
109 | niro | 860 | |
110 | niro | 1672 | # compile the modules |
111 | niro | 1684 | pushd ${INSTALL_DIR}/src > /dev/null |
112 | for module in ${KERNELMODULES[*]} | ||
113 | niro | 1049 | do |
114 | niro | 1684 | mecho "Compiling ${module} module ..." |
115 | make ${makequiet} -C ${module} KBUILD_VERBOSE=${VERBOSE} clean || die "mod-compile ${module}" | ||
116 | niro | 860 | |
117 | niro | 1049 | # need some symver from vboxmodule (must be run after clean!) |
118 | niro | 1672 | if [[ ${module} = ${VBOXNETMODULE} ]] || |
119 | [[ ${module} = ${VBOXNETADPMODULE} ]] || | ||
120 | [[ ${module} = ${VBOXPCIMODULE} ]] | ||
121 | niro | 1049 | then |
122 | niro | 1672 | [[ -f ${VBOXMODULE}/Module.symvers ]] && cp ${VBOXMODULE}/Module.symvers ${module} |
123 | niro | 1049 | fi |
124 | niro | 126 | |
125 | niro | 1684 | make ${makequiet} -C ${module} KBUILD_VERBOSE=${VERBOSE} || die "mod-compile ${module}" |
126 | niro | 1049 | |
127 | # install the modules | ||
128 | install -d /lib/modules/${KERNEL_VERSION}/misc | ||
129 | niro | 1672 | install -m0644 ${module}/${module}.${VBOXMODEXT} /lib/modules/${KERNEL_VERSION}/misc || die "mod-install ${module}" |
130 | niro | 1684 | done |
131 | # do no clean before all modules are build, or required symbols and objects get deleted | ||
132 | for module in ${KERNELMODULES[*]} | ||
133 | do | ||
134 | niro | 1672 | # clean up |
135 | niro | 1684 | make ${makequiet} -C ${module} KBUILD_VERBOSE=${VERBOSE} clean || die "mod-compile ${module}" |
136 | niro | 1049 | done |
137 | niro | 1684 | popd > /dev/null |
138 | niro | 1049 | |
139 | # calc module dependencies | ||
140 | mecho "Calculating module dependencies ..." | ||
141 | depmod -a ${KERNEL_VERSION} | ||
142 | niro | 1686 | fi |
143 | niro | 1049 | |
144 | niro | 1686 | # re-read udev rules to grant the right permissions |
145 | niro | 2057 | if [[ -x $(type -P udevadm) ]] |
146 | niro | 1686 | then |
147 | mecho "Reloading udev configuration ..." | ||
148 | udevadm control --reload-rules | ||
149 | niro | 129 | fi |
150 | |||
151 | niro | 126 | # load the module |
152 | niro | 230 | if [[ x$(uname -r) = x${KERNEL_VERSION} ]] |
153 | niro | 229 | then |
154 | niro | 1684 | for module in ${KERNELMODULES[*]} |
155 | niro | 860 | do |
156 | mecho "Loading kernel-module ${module} ..." | ||
157 | niro | 1049 | modprobe ${module} |
158 | niro | 860 | done |
159 | niro | 988 | |
160 | niro | 1389 | if [ $(echo ${KERNEL_VERSION%%-*} | sed 's:\.::g') -ge 2639 ] |
161 | niro | 988 | then |
162 | # fixes NMI warnings with kernels >=2.6.31: | ||
163 | # vboxdrv: Warning: 2.6.31+ kernel detected. Most likely the hardware performance | ||
164 | # vboxdrv: counter framework which can generate NMIs is active. | ||
165 | mecho "Disabled hardware performance counter NMIs ..." | ||
166 | niro | 1389 | echo 2 > /proc/sys/kernel/perf_event_paranoid |
167 | |||
168 | elif [ $(echo ${KERNEL_VERSION%%-*} | sed 's:\.::g') -ge 2631 ] | ||
169 | niro | 1379 | then |
170 | # fixes NMI warnings with kernels >=2.6.31: | ||
171 | # vboxdrv: Warning: 2.6.31+ kernel detected. Most likely the hardware performance | ||
172 | # vboxdrv: counter framework which can generate NMIs is active. | ||
173 | mecho "Disabled hardware performance counter NMIs ..." | ||
174 | niro | 1389 | echo 2 > /proc/sys/kernel/perf_counter_paranoid |
175 | niro | 1379 | fi |
176 | niro | 229 | else |
177 | echo -e ${COLRED} | ||
178 | echo "Your current running kernel does not match the the module target." | ||
179 | niro | 860 | echo "You must boot into your target kernel and load the modules manually," |
180 | niro | 986 | echo "before you can use virtualbox." |
181 | niro | 229 | echo -en ${COLDEFAULT} |
182 | fi | ||
183 | niro | 126 | |
184 | echo | ||
185 | niro | 129 | mecho "Virtualbox is now configured for your system." |
186 | niro | 1406 | mecho "Do not forget to add your users to the 'vboxusers' group." |
187 | niro | 126 | echo |
188 | |||
189 | exit 0 |