Magellan Linux

Annotation of /trunk/virtualbox/virtualbox-config.sh

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1379 - (hide annotations) (download) (as text)
Wed Jun 29 23:15:17 2011 UTC (12 years, 10 months ago) by niro
File MIME type: application/x-sh
File size: 4515 byte(s)
-be compat with linux-2.6.39
1 niro 126 #!/bin/bash
2 niro 1049 # $Header: /root/magellan-cvs/src/virtualbox/virtualbox-config.sh,v 1.13 2010-06-09 22:29:52 niro Exp $
3 niro 126 # Configures virtualbox for Magellan-Linux
4    
5     LIBDIR=/usr/lib
6     INSTDIR=${LIBDIR}/virtualbox
7 niro 1049 VBOXVERSION="$(< ${INSTDIR}/version)"
8     VBOXMODEXT=ko
9     VBOXMODULE=vboxdrv
10     VBOXNETMODULE=vboxnetflt
11     VBOXNETADPMODULE=vboxnetadp
12 niro 126
13 niro 129 COLRED="\033[1;6m\033[31m"
14     COLGREEN="\033[1;6m\033[32m"
15     COLDEFAULT="\033[0m"
16    
17     if [[ ${NOCOLORS} = true ]]
18 niro 127 then
19 niro 129 COLRED=""
20     COLGREEN=""
21     COLDEFAULT=""
22 niro 127 fi
23    
24 niro 129 die() { echo -e "${COLRED}$@${COLDEFAULT}"; exit 1; }
25     mecho() { echo -e "${COLGREEN}$@${COLDEFAULT}"; }
26 niro 126
27 niro 129 # must be root
28     [[ $(id -u) != 0 ]] && die "You must be r00t!"
29    
30 niro 229 # 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 niro 129
40 niro 229 # 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 niro 1049 # check module version an recompile if it doesen't fit else break here
47     compile="no"
48 niro 861 for module in ${VBOXMODULE} ${VBOXNETMODULE} ${VBOXNETADPMODULE}
49 niro 860 do
50 niro 1049 myver=$(modinfo -k ${KERNEL_VERSION} -F version ${module} | sed "s:\(.*\)_.*:\1:")
51     if [[ ${VBOXVERSION} != ${myver} ]]
52 niro 520 then
53 niro 1049 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 niro 860 # try to unload the modules
62     if [[ -n $(grep "${module} " /proc/modules 2> /dev/null) ]]
63     then
64 niro 1049 mecho "Unloading ${module} module ..."
65     modprobe -r ${module}
66 niro 860 fi
67 niro 520 fi
68 niro 860 done
69 niro 126
70 niro 1049 if [[ ${compile} = yes ]]
71     then
72     if [ ! -f ${KERNEL_SOURCES}/include/linux/version.h ]
73 niro 860 then
74 niro 1049 die "No kernel sources for kernel ${KERNEL_VERSION} found! Aborting."
75 niro 860 fi
76    
77 niro 1049 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 niro 860
86 niro 1049 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 niro 860
93 niro 1049 # 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 niro 126
99 niro 1049 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 niro 129 fi
117    
118 niro 126 # load the module
119 niro 230 if [[ x$(uname -r) = x${KERNEL_VERSION} ]]
120 niro 229 then
121 niro 861 for module in ${VBOXMODULE} ${VBOXNETMODULE} ${VBOXNETADPMODULE}
122 niro 860 do
123     mecho "Loading kernel-module ${module} ..."
124 niro 1049 modprobe ${module}
125 niro 860 done
126 niro 988
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 niro 1379 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 niro 229 else
144     echo -e ${COLRED}
145     echo "Your current running kernel does not match the the module target."
146 niro 860 echo "You must boot into your target kernel and load the modules manually,"
147 niro 986 echo "before you can use virtualbox."
148 niro 229 echo -en ${COLDEFAULT}
149     fi
150 niro 126
151     echo
152 niro 129 mecho "Virtualbox is now configured for your system."
153 niro 313 mecho "Do not forget to add your users to the 'virtualbox' group."
154 niro 126 echo
155    
156     exit 0