VirtualBox

source: vbox/trunk/src/VBox/Installer/linux/vboxdrv.sh.in@ 21955

Last change on this file since 21955 was 21955, checked in by vboxsync, 15 years ago

Linux host driver: workaround for the 2.6.31 performance counter framework initializing the LVTPC APIC vector as NMI

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 10.5 KB
Line 
1#! /bin/sh
2# Sun VirtualBox
3# Linux kernel module init script
4
5#
6# Copyright (C) 2006-2009 Sun Microsystems, Inc.
7#
8# This file is part of VirtualBox Open Source Edition (OSE), as
9# available from http://www.virtualbox.org. This file is free software;
10# you can redistribute it and/or modify it under the terms of the GNU
11# General Public License (GPL) as published by the Free Software
12# Foundation, in version 2 as it comes in the "COPYING" file of the
13# VirtualBox OSE distribution. VirtualBox OSE is distributed in the
14# hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
15#
16
17# chkconfig: 35 30 70
18# description: VirtualBox Linux kernel module
19#
20### BEGIN INIT INFO
21# Provides: vboxdrv
22# Required-Start: $syslog
23# Required-Stop:
24# Default-Start: 2 3 4 5
25# Default-Stop: 0 1 6
26# Short-Description: VirtualBox Linux kernel module
27### END INIT INFO
28
29PATH=/sbin:/bin:/usr/sbin:/usr/bin:$PATH
30DEVICE=/dev/vboxdrv
31GROUPNAME=vboxusers
32LOG="/var/log/vbox-install.log"
33NOLSB=%NOLSB%
34
35[ -f /lib/lsb/init-functions ] || NOLSB=yes
36[ -f /etc/vbox/vbox.cfg ] && . /etc/vbox/vbox.cfg
37
38if [ -n "$INSTALL_DIR" ]; then
39 VBOXMANAGE="$INSTALL_DIR/VBoxManage"
40 BUILDVBOXDRV="$INSTALL_DIR/src/vboxdrv/build_in_tmp"
41 BUILDVBOXNETFLT="$INSTALL_DIR/src/vboxnetflt/build_in_tmp"
42 BUILDVBOXNETADP="$INSTALL_DIR/src/vboxnetadp/build_in_tmp"
43else
44 VBOXMANAGE="/usr/lib/%PACKAGE%/VBoxManage"
45 BUILDVBOXDRV="/usr/share/%PACKAGE%/src/vboxdrv/build_in_tmp"
46 BUILDVBOXNETFLT="/usr/share/%PACKAGE%/src/vboxnetflt/build_in_tmp"
47 BUILDVBOXNETADP="/usr/share/%PACKAGE%/src/vboxnetadp/build_in_tmp"
48fi
49
50if [ -n "$NOLSB" ]; then
51 if [ -f /etc/redhat-release ]; then
52 system=redhat
53 elif [ -f /etc/SuSE-release ]; then
54 system=suse
55 elif [ -f /etc/gentoo-release ]; then
56 system=gentoo
57 fi
58fi
59
60[ -r /etc/default/%PACKAGE% ] && . /etc/default/%PACKAGE%
61
62if [ -z "$NOLSB" ]; then
63 . /lib/lsb/init-functions
64 fail_msg() {
65 echo ""
66 log_failure_msg "$1"
67 }
68 succ_msg() {
69 log_success_msg " done."
70 }
71 begin_msg() {
72 log_daemon_msg "$@"
73 }
74else
75 if [ "$system" = "redhat" ]; then
76 . /etc/init.d/functions
77 fail_msg() {
78 echo -n " "
79 echo_failure
80 echo
81 echo " ($1)"
82 }
83 succ_msg() {
84 echo -n " "
85 echo_success
86 echo
87 }
88 elif [ "$system" = "suse" ]; then
89 . /etc/rc.status
90 fail_msg() {
91 rc_failed 1
92 rc_status -v
93 echo " ($1)"
94 }
95 succ_msg() {
96 rc_reset
97 rc_status -v
98 }
99 elif [ "$system" = "gentoo" ]; then
100 if [ -f /sbin/functions.sh ]; then
101 . /sbin/functions.sh
102 elif [ -f /etc/init.d/functions.sh ]; then
103 . /etc/init.d/functions.sh
104 fi
105 fail_msg() {
106 eerror "$1"
107 }
108 succ_msg() {
109 eend "$?"
110 }
111 begin_msg() {
112 ebegin "$1"
113 }
114 if [ "`which $0`" = "/sbin/rc" ]; then
115 shift
116 fi
117 else
118 fail_msg() {
119 echo " ...failed!"
120 echo " ($1)"
121 }
122 succ_msg() {
123 echo " ...done."
124 }
125 fi
126 if [ "$system" != "gentoo" ]; then
127 begin_msg() {
128 [ -z "${1:-}" ] && return 1
129 if [ -z "${2:-}" ]; then
130 echo -n "$1"
131 else
132 echo -n "$1: $2"
133 fi
134 }
135 fi
136fi
137
138failure()
139{
140 fail_msg "$1"
141 exit 0
142}
143
144running()
145{
146 lsmod | grep -q "$1[^_-]"
147}
148
149start()
150{
151 begin_msg "Starting VirtualBox kernel module"
152 if ! running vboxdrv; then
153 if ! rm -f $DEVICE; then
154 failure "Cannot remove $DEVICE"
155 fi
156 # HACK: disable the hardware performance counter framework
157 if [ -e /proc/sys/kernel/perf_counter_paranoid ]; then
158 echo 2 > /proc/sys/kernel/perf_counter_paranoid
159 fi
160 if ! modprobe vboxdrv > /dev/null 2>&1; then
161 failure "modprobe vboxdrv failed. Please use 'dmesg' to find out why"
162 fi
163 sleep .2
164 fi
165 # ensure the character special exists
166 if [ ! -c $DEVICE ]; then
167 MAJOR=`sed -n 's;\([0-9]\+\) vboxdrv;\1;p' /proc/devices`
168 if [ ! -z "$MAJOR" ]; then
169 MINOR=0
170 else
171 MINOR=`sed -n 's;\([0-9]\+\) vboxdrv;\1;p' /proc/misc`
172 if [ ! -z "$MINOR" ]; then
173 MAJOR=10
174 fi
175 fi
176 if [ -z "$MAJOR" ]; then
177 rmmod vboxdrv 2>/dev/null
178 failure "Cannot locate the VirtualBox device"
179 fi
180 if ! mknod -m 0660 $DEVICE c $MAJOR $MINOR 2>/dev/null; then
181 rmmod vboxdrv 2>/dev/null
182 failure "Cannot create device $DEVICE with major $MAJOR and minor $MINOR"
183 fi
184 fi
185 # ensure permissions
186 if ! chown :$GROUPNAME $DEVICE 2>/dev/null; then
187 rmmod vboxnetadp 2>/dev/null
188 rmmod vboxnetflt 2>/dev/null
189 rmmod vboxdrv 2>/dev/null
190 failure "Cannot change owner $GROUPNAME for device $DEVICE"
191 fi
192 if ! modprobe vboxnetflt > /dev/null 2>&1; then
193 failure "modprobe vboxnetflt failed. Please use 'dmesg' to find out why"
194 fi
195 if ! modprobe vboxnetadp > /dev/null 2>&1; then
196 failure "modprobe vboxnetadp failed. Please use 'dmesg' to find out why"
197 fi
198 succ_msg
199}
200
201stop()
202{
203 begin_msg "Stopping VirtualBox kernel module"
204 if running vboxnetadp; then
205 if ! rmmod vboxnetadp 2>/dev/null; then
206 failure "Cannot unload module vboxnetadp"
207 fi
208 fi
209 if running vboxdrv; then
210 if running vboxnetflt; then
211 if ! rmmod vboxnetflt 2>/dev/null; then
212 failure "Cannot unload module vboxnetflt"
213 fi
214 fi
215 if ! rmmod vboxdrv 2>/dev/null; then
216 failure "Cannot unload module vboxdrv"
217 fi
218 if ! rm -f $DEVICE; then
219 failure "Cannot unlink $DEVICE"
220 fi
221 fi
222 succ_msg
223}
224
225# enter the following variables in /etc/default/%PACKAGE%:
226# SHUTDOWN_USERS="foo bar"
227# check for running VMs of user foo and user bar
228# SHUTDOWN=poweroff
229# SHUTDOWN=acpibutton
230# SHUTDOWN=savestate
231# select one of these shutdown methods for running VMs
232stop_vms()
233{
234 wait=0
235 for i in $SHUTDOWN_USERS; do
236 # don't create the ipcd directory with wrong permissions!
237 if [ -d /tmp/.vbox-$i-ipc ]; then
238 export VBOX_IPC_SOCKETID="$i"
239 VMS=`$VBOXMANAGE --nologo list runningvms | sed -e 's/^".*".*{\(.*\)}/\1/' 2>/dev/null`
240 if [ -n "$VMS" ]; then
241 if [ "$SHUTDOWN" = "poweroff" ]; then
242 begin_msg "Powering off remaining VMs"
243 for v in $VMS; do
244 $VBOXMANAGE --nologo controlvm $v poweroff
245 done
246 succ_msg
247 elif [ "$SHUTDOWN" = "acpibutton" ]; then
248 begin_msg "Sending ACPI power button event to remaining VMs"
249 for v in $VMS; do
250 $VBOXMANAGE --nologo controlvm $v acpipowerbutton
251 wait=30
252 done
253 succ_msg
254 elif [ "$SHUTDOWN" = "savestate" ]; then
255 begin_msg "Saving state of remaining VMs"
256 for v in $VMS; do
257 $VBOXMANAGE --nologo controlvm $v savestate
258 done
259 succ_msg
260 fi
261 fi
262 fi
263 done
264 # wait for some seconds when doing ACPI shutdown
265 if [ "$wait" -ne 0 ]; then
266 begin_msg "Waiting for $wait seconds for VM shutdown"
267 sleep $wait
268 succ_msg
269 fi
270}
271
272setup()
273{
274 stop
275 if find /lib/modules/`uname -r` -name "vboxnetadp\.*" 2>/dev/null|grep -q vboxnetadp; then
276 begin_msg "Removing old VirtualBox netadp kernel module"
277 find /lib/modules/`uname -r` -name "vboxnetadp\.*" 2>/dev/null|xargs rm -f 2>/dev/null
278 succ_msg
279 fi
280 if find /lib/modules/`uname -r` -name "vboxnetflt\.*" 2>/dev/null|grep -q vboxnetflt; then
281 begin_msg "Removing old VirtualBox netflt kernel module"
282 find /lib/modules/`uname -r` -name "vboxnetflt\.*" 2>/dev/null|xargs rm -f 2>/dev/null
283 succ_msg
284 fi
285 if find /lib/modules/`uname -r` -name "vboxdrv\.*" 2>/dev/null|grep -q vboxdrv; then
286 begin_msg "Removing old VirtualBox kernel module"
287 find /lib/modules/`uname -r` -name "vboxdrv\.*" 2>/dev/null|xargs rm -f 2>/dev/null
288 succ_msg
289 fi
290 begin_msg "Recompiling VirtualBox kernel module"
291 if ! $BUILDVBOXDRV \
292 --save-module-symvers /tmp/vboxdrv-Module.symvers \
293 --no-print-directory install > $LOG 2>&1; then
294 failure "Look at $LOG to find out what went wrong"
295 fi
296 if ! $BUILDVBOXNETFLT \
297 --use-module-symvers /tmp/vboxdrv-Module.symvers \
298 --no-print-directory install >> $LOG 2>&1; then
299 failure "Look at $LOG to find out what went wrong"
300 fi
301 if ! $BUILDVBOXNETADP \
302 --use-module-symvers /tmp/vboxdrv-Module.symvers \
303 --no-print-directory install >> $LOG 2>&1; then
304 failure "Look at $LOG to find out what went wrong"
305 fi
306 rm -f /etc/vbox/module_not_compiled
307 succ_msg
308 start
309}
310
311dmnstatus()
312{
313 if running vboxdrv; then
314 if running vboxnetflt; then
315 if running vboxnetadp; then
316 echo "VirtualBox kernel modules (vboxdrv, vboxnetflt and vboxnetadp) are loaded."
317 else
318 echo "VirtualBox kernel modules (vboxdrv and vboxnetflt) are loaded."
319 fi
320 else
321 echo "VirtualBox kernel module is loaded."
322 fi
323 for i in $SHUTDOWN_USERS; do
324 # don't create the ipcd directory with wrong permissions!
325 if [ -d /tmp/.vbox-$i-ipc ]; then
326 export VBOX_IPC_SOCKETID="$i"
327 VMS=`$VBOXMANAGE --nologo list runningvms | sed -e 's/^".*".*{\(.*\)}/\1/' 2>/dev/null`
328 if [ -n "$VMS" ]; then
329 echo "The following VMs are currently running:"
330 for v in $VMS; do
331 echo " $v"
332 done
333 fi
334 fi
335 done
336 else
337 echo "VirtualBox kernel module is not loaded."
338 fi
339}
340
341case "$1" in
342start)
343 start
344 ;;
345stop)
346 stop_vms
347 stop
348 ;;
349stop_vms)
350 stop_vms
351 ;;
352restart)
353 stop && start
354 ;;
355force-reload)
356 stop
357 start
358 ;;
359setup)
360 setup
361 ;;
362status)
363 dmnstatus
364 ;;
365*)
366 echo "Usage: $0 {start|stop|stop_vms|restart|force-reload|status|setup}"
367 exit 1
368esac
369
370exit 0
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette