Magellan Linux

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

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

revision 1379 by niro, Wed Jun 29 23:15:17 2011 UTC revision 1684 by niro, Sun Mar 4 11:32:46 2012 UTC
# Line 1  Line 1 
1  #!/bin/bash  #!/bin/bash
2  # $Header: /root/magellan-cvs/src/virtualbox/virtualbox-config.sh,v 1.13 2010-06-09 22:29:52 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  VBOXVERSION="$(< ${INSTDIR}/version)"  
8    VBOXVERSION="$(< ${INSTALL_DIR}/version)"
9  VBOXMODEXT=ko  VBOXMODEXT=ko
10  VBOXMODULE=vboxdrv  VBOXMODULE=vboxdrv
11  VBOXNETMODULE=vboxnetflt  VBOXNETMODULE=vboxnetflt
12  VBOXNETADPMODULE=vboxnetadp  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 23  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 33  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 40  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  # check module version an recompile if it doesen't fit else break here  # check module version and recompile if it doesen't fit else break here
67  compile="no"  compile="yes"
68  for module in ${VBOXMODULE} ${VBOXNETMODULE} ${VBOXNETADPMODULE}  for module in ${KERNELMODULES[*]}
69  do  do
70   myver=$(modinfo -k ${KERNEL_VERSION} -F version ${module} | sed "s:\(.*\)_.*:\1:")   if [[ -f /lib/modules/${KERNEL_VERSION}/misc/${module}.${VBOXMODEXT} ]]
  if [[ ${VBOXVERSION} != ${myver} ]]  
71   then   then
72   compile="yes"   myver=$(modinfo -k ${KERNEL_VERSION} -F version ${module} | sed "s:\(.*\)_.*:\1:")
73     if [[ ${VBOXVERSION} = ${myver} ]] && [[ ${FORCED_REBUILD} = 0 ]]
74     then
75     compile="no"
76     fi
77   fi   fi
78  done  done
79    
80  for module in ${VBOXNETADPMODULE} ${VBOXNETMODULE} ${VBOXMODULE}  # 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   if [[ -f /lib/modules/${KERNEL_VERSION}/misc/${module}.${VBOXMODEXT} ]]   if [[ -f /lib/modules/${KERNEL_VERSION}/misc/${KERNELMODULES[${i}]}.${VBOXMODEXT} ]]
85   then   then
86   # try to unload the modules   if [[ -n $(grep "${KERNELMODULES[${i}]} " /proc/modules 2> /dev/null) ]]
  if [[ -n $(grep "${module} " /proc/modules 2> /dev/null) ]]  
87   then   then
88   mecho "Unloading ${module} module ..."   mecho "Unloading ${KERNELMODULES[${i}]} module ..."
89   modprobe -r ${module}   modprobe -r ${KERNELMODULES[${i}]}
90   fi   fi
91   fi   fi
92  done  done
# Line 74  then Line 98  then
98   die "No kernel sources for kernel ${KERNEL_VERSION} found! Aborting."   die "No kernel sources for kernel ${KERNEL_VERSION} found! Aborting."
99   fi   fi
100    
101   for module in ${VBOXMODULE} ${VBOXNETMODULE} ${VBOXNETADPMODULE}   for module in ${KERNELMODULES[*]}
102   do   do
103   if [[ -f /lib/modules/${KERNEL_VERSION}/misc/${module}.${VBOXMODEXT} ]]   if [[ -f /lib/modules/${KERNEL_VERSION}/misc/${module}.${VBOXMODEXT} ]]
104   then   then
# Line 83  then Line 107  then
107   fi   fi
108   done   done
109    
110   for module in ${VBOXMODULE} ${VBOXNETMODULE} ${VBOXNETADPMODULE}   # compile the modules
111     pushd ${INSTALL_DIR}/src > /dev/null
112     for module in ${KERNELMODULES[*]}
113   do   do
114   # compile the module   mecho "Compiling ${module} module ..."
115   cd ${INSTDIR}/src/${module}   make ${makequiet} -C ${module} KBUILD_VERBOSE=${VERBOSE} clean || die "mod-compile ${module}"
   
  make -C ${KERNEL_SOURCES} SUBDIRS=$(pwd) SRCROOT=$(pwd) clean || die "mod-compile ${module}"  
116    
117   # need some symver from vboxmodule (must be run after clean!)   # need some symver from vboxmodule (must be run after clean!)
118   if [[ ${module} = ${VBOXNETMODULE} ]] || [[ ${module} = ${VBOXNETADPMODULE} ]]   if [[ ${module} = ${VBOXNETMODULE} ]] ||
119     [[ ${module} = ${VBOXNETADPMODULE} ]] ||
120     [[ ${module} = ${VBOXPCIMODULE} ]]
121   then   then
122   [[ -f ../${VBOXMODULE}/Module.symvers ]] && cp ../${VBOXMODULE}/Module.symvers .   [[ -f ${VBOXMODULE}/Module.symvers ]] && cp ${VBOXMODULE}/Module.symvers ${module}
123   fi   fi
124    
125   make -C ${KERNEL_SOURCES} SUBDIRS=$(pwd) SRCROOT=$(pwd) modules || die "mod-compile ${module}"   make ${makequiet} -C ${module} KBUILD_VERBOSE=${VERBOSE} || die "mod-compile ${module}"
126    
127   # install the modules   # install the modules
128   install -d /lib/modules/${KERNEL_VERSION}/misc   install -d /lib/modules/${KERNEL_VERSION}/misc
129   install -m0644 ${module}.${VBOXMODEXT} /lib/modules/${KERNEL_VERSION}/misc || die "mod-install ${module}"   install -m0644 ${module}/${module}.${VBOXMODEXT} /lib/modules/${KERNEL_VERSION}/misc || die "mod-install ${module}"
130     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     # clean up
135     make ${makequiet} -C ${module} KBUILD_VERBOSE=${VERBOSE} clean || die "mod-compile ${module}"
136   done   done
137     popd > /dev/null
138    
139   # calc module dependencies   # calc module dependencies
140   mecho "Calculating module dependencies ..."   mecho "Calculating module dependencies ..."
# Line 111  then Line 144  then
144   if [[ -x $(which udevadm) ]]   if [[ -x $(which udevadm) ]]
145   then   then
146   mecho "Reloading udev configuration ..."   mecho "Reloading udev configuration ..."
147   $(which udevadm) control --reload-rules   udevadm control --reload-rules
148   fi   fi
149  fi  fi
150    
151  # load the module  # load the module
152  if [[ x$(uname -r) = x${KERNEL_VERSION} ]]  if [[ x$(uname -r) = x${KERNEL_VERSION} ]]
153  then  then
154   for module in ${VBOXMODULE} ${VBOXNETMODULE} ${VBOXNETADPMODULE}   for module in ${KERNELMODULES[*]}
155   do   do
156   mecho "Loading kernel-module ${module} ..."   mecho "Loading kernel-module ${module} ..."
157   modprobe ${module}   modprobe ${module}
158   done   done
159    
160   if [ $(echo ${KERNEL_VERSION%%-*} | sed 's:\.::g') -ge 2631 ]   if [ $(echo ${KERNEL_VERSION%%-*} | sed 's:\.::g') -ge 2639 ]
161   then   then
162   # fixes NMI warnings with kernels >=2.6.31:   # fixes NMI warnings with kernels >=2.6.31:
163   # vboxdrv: Warning: 2.6.31+ kernel detected. Most likely the hardware performance   # vboxdrv: Warning: 2.6.31+ kernel detected. Most likely the hardware performance
164   # vboxdrv: counter framework which can generate NMIs is active.   # vboxdrv: counter framework which can generate NMIs is active.
165   mecho "Disabled hardware performance counter NMIs ..."   mecho "Disabled hardware performance counter NMIs ..."
166   echo 2 > /proc/sys/kernel/perf_counter_paranoid   echo 2 > /proc/sys/kernel/perf_event_paranoid
167   fi  
168   if [ $(echo ${KERNEL_VERSION%%-*} | sed 's:\.::g') -ge 2639 ]   elif [ $(echo ${KERNEL_VERSION%%-*} | sed 's:\.::g') -ge 2631 ]
169   then   then
170   # fixes NMI warnings with kernels >=2.6.31:   # fixes NMI warnings with kernels >=2.6.31:
171   # vboxdrv: Warning: 2.6.31+ kernel detected. Most likely the hardware performance   # vboxdrv: Warning: 2.6.31+ kernel detected. Most likely the hardware performance
172   # vboxdrv: counter framework which can generate NMIs is active.   # vboxdrv: counter framework which can generate NMIs is active.
173   mecho "Disabled hardware performance counter NMIs ..."   mecho "Disabled hardware performance counter NMIs ..."
174   echo 2 > /proc/sys/kernel/perf_event_paranoid   echo 2 > /proc/sys/kernel/perf_counter_paranoid
175   fi   fi
176  else  else
177   echo -e ${COLRED}   echo -e ${COLRED}
# Line 150  fi Line 183  fi
183    
184  echo  echo
185  mecho "Virtualbox is now configured for your system."  mecho "Virtualbox is now configured for your system."
186  mecho "Do not forget to add your users to the 'virtualbox' group."  mecho "Do not forget to add your users to the 'vboxusers' group."
187  echo  echo
188    
189  exit 0  exit 0

Legend:
Removed from v.1379  
changed lines
  Added in v.1684