Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 988 by niro, Sun Feb 21 20:06:45 2010 UTC revision 2059 by niro, Wed Jan 30 13:43:50 2013 UTC
# Line 1  Line 1 
1  #!/bin/bash  #!/bin/bash
2  # $Header: /root/magellan-cvs/src/virtualbox/virtualbox-config.sh,v 1.12 2010-02-21 20:06:45 niro Exp $  # $Id$
3  # Configures virtualbox for Magellan-Linux  # Configures virtualbox for Magellan-Linux
4    
5  LIBDIR=/usr/lib  # get INSTALL_DIR location
6  INSTDIR=${LIBDIR}/virtualbox  source /etc/vbox/vbox.cfg
7  VBOXMODULE=vboxdrv.ko  
8  VBOXNETMODULE=vboxnetflt.ko  VBOXVERSION="$(< ${INSTALL_DIR}/version)"
9  VBOXNETADPMODULE=vboxnetadp.ko  VBOXMODEXT=ko
10    VBOXMODULE=vboxdrv
11    VBOXNETMODULE=vboxnetflt
12    VBOXNETADPMODULE=vboxnetadp
13    VBOXPCIMODULE=vboxpci
14    KERNELMODULES=( "${VBOXMODULE}" "${VBOXNETMODULE}" "${VBOXNETADPMODULE}" "${VBOXPCIMODULE}" )
15    
16  COLRED="\033[1;6m\033[31m"  COLRED="\033[1;6m\033[31m"
17  COLGREEN="\033[1;6m\033[32m"  COLGREEN="\033[1;6m\033[32m"
# Line 21  fi Line 26  fi
26    
27  die() { echo -e "${COLRED}$@${COLDEFAULT}"; exit 1; }  die() { echo -e "${COLRED}$@${COLDEFAULT}"; exit 1; }
28  mecho() { echo -e "${COLGREEN}$@${COLDEFAULT}"; }  mecho() { echo -e "${COLGREEN}$@${COLDEFAULT}"; }
29    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    
41  # must be root  # must be root
42  [[ $(id -u) != 0 ]] && die "You must be r00t!"  [[ $(id -u) != 0 ]] && die "You must be r00t!"
# Line 31  do Line 47  do
47   case $1 in   case $1 in
48   --kernel-version) shift; KERNEL_VERSION="$1" ;;   --kernel-version) shift; KERNEL_VERSION="$1" ;;
49   --kernel-sources) shift; KERNEL_SOURCES="$1" ;;   --kernel-sources) shift; KERNEL_SOURCES="$1" ;;
50     --force) FORCED_REBUILD="1" ;;
51     --verbose) VERBOSE="1" ;;
52     --help) usage ;;
53   esac   esac
54   shift   shift
55  done  done
# Line 38  done Line 57  done
57  # some sane defaults  # some sane defaults
58  [[ -z ${KERNEL_VERSION} ]] && KERNEL_VERSION="$(uname -r)"  [[ -z ${KERNEL_VERSION} ]] && KERNEL_VERSION="$(uname -r)"
59  [[ -z ${KERNEL_SOURCES} ]] && KERNEL_SOURCES="/lib/modules/${KERNEL_VERSION}/source"  [[ -z ${KERNEL_SOURCES} ]] && KERNEL_SOURCES="/lib/modules/${KERNEL_VERSION}/source"
60    [[ -z ${FORCED_REBUILD} ]] && FORCED_REBUILD="0"
61    [[ -z ${VERBOSE} ]] && VERBOSE="0"
62    [[ ${VERBOSE} = 0 ]]  && makequiet="-s"
63    
64  mecho "Running $(basename $0) for kernelversion ${KERNEL_VERSION} ..."  mecho "Running $(basename $0) for kernelversion ${KERNEL_VERSION} ..."
65    
66  if [ ! -f ${KERNEL_SOURCES}/include/linux/version.h ]  # check module version and recompile if it doesen't fit else break here
67  then  compile="yes"
68   die "No kernel sources for kernel ${KERNEL_VERSION} found! Aborting."  for module in ${KERNELMODULES[*]}
 fi  
   
 for module in ${VBOXMODULE} ${VBOXNETMODULE} ${VBOXNETADPMODULE}  
69  do  do
70   if [[ -f /lib/modules/${KERNEL_VERSION}/misc/${module} ]]   if [[ -f /lib/modules/${KERNEL_VERSION}/misc/${module}.${VBOXMODEXT} ]]
71   then   then
72   mecho "Removing old ${module} module ..."   myver=$(modinfo -k ${KERNEL_VERSION} -F version ${module} | sed "s:\(.*\)_.*:\1:")
73   # try to unload the modules   if [[ ${VBOXVERSION} = ${myver} ]] && [[ ${FORCED_REBUILD} = 0 ]]
  if [[ -n $(grep "${module} " /proc/modules 2> /dev/null) ]]  
74   then   then
75   modprobe -r ${module/.ko/}   compile="no"
76   fi   fi
  rm -f /lib/modules/${KERNEL_VERSION}/misc/${module}  
77   fi   fi
78  done  done
79    
80  for module in ${VBOXMODULE} ${VBOXNETMODULE} ${VBOXNETADPMODULE}  # try to unload the modules in reverse order to honor dependencies
81    count=${#KERNELMODULES[*]}
82    for (( i=count-1; i>=0; i-- ))
83  do  do
84   # compile the module   if [[ -f /lib/modules/${KERNEL_VERSION}/misc/${KERNELMODULES[${i}]}.${VBOXMODEXT} ]]
85   cd ${INSTDIR}/src/${module/.ko/}   then
86     if [[ -n $(grep "${KERNELMODULES[${i}]} " /proc/modules 2> /dev/null) ]]
87   make -C ${KERNEL_SOURCES} SUBDIRS=$(pwd) SRCROOT=$(pwd) clean || die "mod-compile ${module}"   then
88     mecho "Unloading ${KERNELMODULES[${i}]} module ..."
89     modprobe -r ${KERNELMODULES[${i}]}
90     fi
91     fi
92    done
93    
94   # need some symver from vboxmodule (must be run after clean!)  if [[ ${compile} = yes ]]
95   if [[ ${module} = ${VBOXNETMODULE} ]] || [[ ${module} = ${VBOXNETADPMODULE} ]]  then
96     if [ ! -f ${KERNEL_SOURCES}/include/linux/version.h ] &&
97     [ ! -f ${KERNEL_SOURCES}/include/generated/uapi/linux/version.h ]
98   then   then
99   [[ -f ../${VBOXMODULE/.ko/}/Module.symvers ]] && cp ../${VBOXMODULE/.ko/}/Module.symvers .   die "No kernel sources for kernel ${KERNEL_VERSION} found! Aborting."
100   fi   fi
101    
102   make -C ${KERNEL_SOURCES} SUBDIRS=$(pwd) SRCROOT=$(pwd) modules || die "mod-compile ${module}"   for module in ${KERNELMODULES[*]}
103     do
104     if [[ -f /lib/modules/${KERNEL_VERSION}/misc/${module}.${VBOXMODEXT} ]]
105     then
106     mecho "Removing old ${module} module ..."
107     rm -f /lib/modules/${KERNEL_VERSION}/misc/${module}.${VBOXMODEXT}
108     fi
109     done
110    
111   # install the modules   # compile the modules
112   install -d /lib/modules/${KERNEL_VERSION}/misc   pushd ${INSTALL_DIR}/src > /dev/null
113   install -m0644 ${module} /lib/modules/${KERNEL_VERSION}/misc || die "mod-install ${module}"   for module in ${KERNELMODULES[*]}
114  done   do
115     mecho "Compiling ${module} module ..."
116     make ${makequiet} -C ${module} KBUILD_VERBOSE=${VERBOSE} clean || die "mod-compile ${module}"
117    
118  # calc module dependencies   # need some symver from vboxmodule (must be run after clean!)
119  mecho "Calculating module dependencies ..."   if [[ ${module} = ${VBOXNETMODULE} ]] ||
120  depmod -a ${KERNEL_VERSION}   [[ ${module} = ${VBOXNETADPMODULE} ]] ||
121     [[ ${module} = ${VBOXPCIMODULE} ]]
122     then
123     [[ -f ${VBOXMODULE}/Module.symvers ]] && cp ${VBOXMODULE}/Module.symvers ${module}
124     fi
125    
126     make ${makequiet} -C ${module} KBUILD_VERBOSE=${VERBOSE} || die "mod-compile ${module}"
127    
128     # install the modules
129     install -d /lib/modules/${KERNEL_VERSION}/misc
130     install -m0644 ${module}/${module}.${VBOXMODEXT} /lib/modules/${KERNEL_VERSION}/misc || die "mod-install ${module}"
131     done
132     # do no clean before all modules are build, or required symbols and objects get deleted
133     for module in ${KERNELMODULES[*]}
134     do
135     # clean up
136     make ${makequiet} -C ${module} KBUILD_VERBOSE=${VERBOSE} clean || die "mod-compile ${module}"
137     done
138     popd > /dev/null
139    
140     # calc module dependencies
141     mecho "Calculating module dependencies ..."
142     depmod -a ${KERNEL_VERSION}
143    fi
144    
145  # re-read udev rules to grant the right permissions  # re-read udev rules to grant the right permissions
146  if [[ -x $(which udevadm) ]]  if [[ -x $(type -P udevadm) ]]
147  then  then
148   mecho "Reloading udev configuration ..."   mecho "Reloading udev configuration ..."
149   $(which udevadm) control --reload-rules   if [ -x /usr/lib/systemd/systemd-udevd ]
150     then
151     udevadm control --reload
152     else
153     udevadm control --reload-rules
154     fi
155  fi  fi
156    
157  # load the module  # load the module
158  if [[ x$(uname -r) = x${KERNEL_VERSION} ]]  if [[ x$(uname -r) = x${KERNEL_VERSION} ]]
159  then  then
160   for module in ${VBOXMODULE} ${VBOXNETMODULE} ${VBOXNETADPMODULE}   for module in ${KERNELMODULES[*]}
161   do   do
162   mecho "Loading kernel-module ${module} ..."   mecho "Loading kernel-module ${module} ..."
163   modprobe $(basename ${module} .ko)   modprobe ${module}
164   done   done
165    
166   if [ $(echo ${KERNEL_VERSION%%-*} | sed 's:\.::g') -ge 2631 ]   if [ $(echo ${KERNEL_VERSION%%-*} | sed 's:\.::g') -ge 2639 ]
167     then
168     # fixes NMI warnings with kernels >=2.6.31:
169     # vboxdrv: Warning: 2.6.31+ kernel detected. Most likely the hardware performance
170     # vboxdrv: counter framework which can generate NMIs is active.
171     mecho "Disabled hardware performance counter NMIs ..."
172     echo 2 > /proc/sys/kernel/perf_event_paranoid
173    
174     elif [ $(echo ${KERNEL_VERSION%%-*} | sed 's:\.::g') -ge 2631 ]
175   then   then
176   # fixes NMI warnings with kernels >=2.6.31:   # fixes NMI warnings with kernels >=2.6.31:
177   # vboxdrv: Warning: 2.6.31+ kernel detected. Most likely the hardware performance   # vboxdrv: Warning: 2.6.31+ kernel detected. Most likely the hardware performance
# Line 118  fi Line 189  fi
189    
190  echo  echo
191  mecho "Virtualbox is now configured for your system."  mecho "Virtualbox is now configured for your system."
192  mecho "Do not forget to add your users to the 'virtualbox' group."  mecho "Do not forget to add your users to the 'vboxusers' group."
193  echo  echo
194    
195  exit 0  exit 0

Legend:
Removed from v.988  
changed lines
  Added in v.2059