Magellan Linux

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

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

revision 230 by niro, Thu Jun 28 17:31:50 2007 UTC revision 2058 by niro, Wed Jan 30 13:43:16 2013 UTC
# Line 1  Line 1 
1  #!/bin/bash  #!/bin/bash
2  # $Header: /root/magellan-cvs/src/virtualbox/virtualbox-config.sh,v 1.6 2007-06-28 17:31:50 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    VBOXVERSION="$(< ${INSTALL_DIR}/version)"
9    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 19  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 29  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 36  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[*]}
69  fi  do
70     if [[ -f /lib/modules/${KERNEL_VERSION}/misc/${module}.${VBOXMODEXT} ]]
71     then
72     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
78    done
79    
80  if [[ -f /lib/modules/${KERNEL_VERSION}/misc/${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
84     if [[ -f /lib/modules/${KERNEL_VERSION}/misc/${KERNELMODULES[${i}]}.${VBOXMODEXT} ]]
85     then
86     if [[ -n $(grep "${KERNELMODULES[${i}]} " /proc/modules 2> /dev/null) ]]
87     then
88     mecho "Unloading ${KERNELMODULES[${i}]} module ..."
89     modprobe -r ${KERNELMODULES[${i}]}
90     fi
91     fi
92    done
93    
94    if [[ ${compile} = yes ]]
95  then  then
96   mecho "Removing old module ..."   if [ ! -f ${KERNEL_SOURCES}/include/linux/version.h ]
97   rm -f /lib/modules/${KERNEL_VERSION}/misc/${VBOXMODULE}   then
98     die "No kernel sources for kernel ${KERNEL_VERSION} found! Aborting."
99     fi
100    
101     for module in ${KERNELMODULES[*]}
102     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    
110     # compile the modules
111     pushd ${INSTALL_DIR}/src > /dev/null
112     for module in ${KERNELMODULES[*]}
113     do
114     mecho "Compiling ${module} module ..."
115     make ${makequiet} -C ${module} KBUILD_VERBOSE=${VERBOSE} clean || die "mod-compile ${module}"
116    
117     # need some symver from vboxmodule (must be run after clean!)
118     if [[ ${module} = ${VBOXNETMODULE} ]] ||
119     [[ ${module} = ${VBOXNETADPMODULE} ]] ||
120     [[ ${module} = ${VBOXPCIMODULE} ]]
121     then
122     [[ -f ${VBOXMODULE}/Module.symvers ]] && cp ${VBOXMODULE}/Module.symvers ${module}
123     fi
124    
125     make ${makequiet} -C ${module} KBUILD_VERBOSE=${VERBOSE} || die "mod-compile ${module}"
126    
127     # install the modules
128     install -d /lib/modules/${KERNEL_VERSION}/misc
129     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
137     popd > /dev/null
138    
139     # calc module dependencies
140     mecho "Calculating module dependencies ..."
141     depmod -a ${KERNEL_VERSION}
142  fi  fi
143    
 # compile the module  
 cd ${INSTDIR}/src  
 make -C ${KERNEL_SOURCES} SUBDIRS=$(pwd) SRCROOT=$(pwd) clean modules || die "mod-compile"  
   
 # install the module  
 install -d /lib/modules/${KERNEL_VERSION}/misc  
 install -m0644 ${VBOXMODULE} /lib/modules/${KERNEL_VERSION}/misc || die "mod-install"  
   
 # calc module dependencies  
 mecho "Calculating module dependencies ..."  
 depmod -ae ${KERNEL_VERSION}  
   
144  # re-read udev rules to grant the right permissions  # re-read udev rules to grant the right permissions
145  if [[ -x $(which udevcontrol) ]]  if [[ -x $(type -P udevadm) ]]
146  then  then
147   mecho "Reloading udev configuration ..."   mecho "Reloading udev configuration ..."
148   $(which udevcontrol) reload_rules   if [ -x /usr/lib/systemd/systemd-udevd ]
149     then
150     udevadm control --reload
151     else
152     udevadm control --reload-rules
153     fi
154  fi  fi
155    
156  # load the module  # load the module
157  if [[ x$(uname -r) = x${KERNEL_VERSION} ]]  if [[ x$(uname -r) = x${KERNEL_VERSION} ]]
158  then  then
159   mecho "Loading kernel-module ${VBOXMODULE} ..."   for module in ${KERNELMODULES[*]}
160   modprobe $(basename ${VBOXMODULE} .ko)   do
161     mecho "Loading kernel-module ${module} ..."
162     modprobe ${module}
163     done
164    
165     if [ $(echo ${KERNEL_VERSION%%-*} | sed 's:\.::g') -ge 2639 ]
166     then
167     # fixes NMI warnings with kernels >=2.6.31:
168     # vboxdrv: Warning: 2.6.31+ kernel detected. Most likely the hardware performance
169     # vboxdrv: counter framework which can generate NMIs is active.
170     mecho "Disabled hardware performance counter NMIs ..."
171     echo 2 > /proc/sys/kernel/perf_event_paranoid
172    
173     elif [ $(echo ${KERNEL_VERSION%%-*} | sed 's:\.::g') -ge 2631 ]
174     then
175     # fixes NMI warnings with kernels >=2.6.31:
176     # vboxdrv: Warning: 2.6.31+ kernel detected. Most likely the hardware performance
177     # vboxdrv: counter framework which can generate NMIs is active.
178     mecho "Disabled hardware performance counter NMIs ..."
179     echo 2 > /proc/sys/kernel/perf_counter_paranoid
180     fi
181  else  else
182   echo -e ${COLRED}   echo -e ${COLRED}
183   echo "Your current running kernel does not match the the module target."   echo "Your current running kernel does not match the the module target."
184   echo "You must boot into your target kernel and load the module manually,"   echo "You must boot into your target kernel and load the modules manually,"
185   echo "before you can use virtual box."   echo "before you can use virtualbox."
186   echo -en ${COLDEFAULT}   echo -en ${COLDEFAULT}
187  fi  fi
188    
189  echo  echo
190  mecho "Virtualbox is now configured for your system."  mecho "Virtualbox is now configured for your system."
191  mecho "Do not forget to add you users to the 'virtualbox' group."  mecho "Do not forget to add your users to the 'vboxusers' group."
192  echo  echo
193    
194  exit 0  exit 0

Legend:
Removed from v.230  
changed lines
  Added in v.2058