VirtualBox

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

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

Linux vboxdrv script: don't search for the vboxdrv module, this is superflous and wastes time

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 10.3 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 if ! modprobe vboxdrv > /dev/null 2>&1; then
157 failure "modprobe vboxdrv failed. Please use 'dmesg' to find out why"
158 fi
159 sleep .2
160 fi
161 # ensure the character special exists
162 if [ ! -c $DEVICE ]; then
163 MAJOR=`sed -n 's;\([0-9]\+\) vboxdrv;\1;p' /proc/devices`
164 if [ ! -z "$MAJOR" ]; then
165 MINOR=0
166 else
167 MINOR=`sed -n 's;\([0-9]\+\) vboxdrv;\1;p' /proc/misc`
168 if [ ! -z "$MINOR" ]; then
169 MAJOR=10
170 fi
171 fi
172 if [ -z "$MAJOR" ]; then
173 rmmod vboxdrv 2>/dev/null
174 failure "Cannot locate the VirtualBox device"
175 fi
176 if ! mknod -m 0660 $DEVICE c $MAJOR $MINOR 2>/dev/null; then
177 rmmod vboxdrv 2>/dev/null
178 failure "Cannot create device $DEVICE with major $MAJOR and minor $MINOR"
179 fi
180 fi
181 # ensure permissions
182 if ! chown :$GROUPNAME $DEVICE 2>/dev/null; then
183 rmmod vboxnetadp 2>/dev/null
184 rmmod vboxnetflt 2>/dev/null
185 rmmod vboxdrv 2>/dev/null
186 failure "Cannot change owner $GROUPNAME for device $DEVICE"
187 fi
188 if ! modprobe vboxnetflt > /dev/null 2>&1; then
189 failure "modprobe vboxnetflt failed. Please use 'dmesg' to find out why"
190 fi
191 if ! modprobe vboxnetadp > /dev/null 2>&1; then
192 failure "modprobe vboxnetadp failed. Please use 'dmesg' to find out why"
193 fi
194 succ_msg
195}
196
197stop()
198{
199 begin_msg "Stopping VirtualBox kernel module"
200 if running vboxnetadp; then
201 if ! rmmod vboxnetadp 2>/dev/null; then
202 failure "Cannot unload module vboxnetadp"
203 fi
204 fi
205 if running vboxdrv; then
206 if running vboxnetflt; then
207 if ! rmmod vboxnetflt 2>/dev/null; then
208 failure "Cannot unload module vboxnetflt"
209 fi
210 fi
211 if ! rmmod vboxdrv 2>/dev/null; then
212 failure "Cannot unload module vboxdrv"
213 fi
214 if ! rm -f $DEVICE; then
215 failure "Cannot unlink $DEVICE"
216 fi
217 fi
218 succ_msg
219}
220
221# enter the following variables in /etc/default/%PACKAGE%:
222# SHUTDOWN_USERS="foo bar"
223# check for running VMs of user foo and user bar
224# SHUTDOWN=poweroff
225# SHUTDOWN=acpibutton
226# SHUTDOWN=savestate
227# select one of these shutdown methods for running VMs
228stop_vms()
229{
230 wait=0
231 for i in $SHUTDOWN_USERS; do
232 # don't create the ipcd directory with wrong permissions!
233 if [ -d /tmp/.vbox-$i-ipc ]; then
234 export VBOX_IPC_SOCKETID="$i"
235 VMS=`$VBOXMANAGE --nologo list runningvms | sed -e 's/^".*"//' 2>/dev/null`
236 if [ -n "$VMS" ]; then
237 if [ "$SHUTDOWN" = "poweroff" ]; then
238 begin_msg "Powering off remaining VMs"
239 for v in $VMS; do
240 $VBOXMANAGE --nologo controlvm $v poweroff
241 done
242 succ_msg
243 elif [ "$SHUTDOWN" = "acpibutton" ]; then
244 begin_msg "Sending ACPI power button event to remaining VMs"
245 for v in $VMS; do
246 $VBOXMANAGE --nologo controlvm $v acpipowerbutton
247 wait=30
248 done
249 succ_msg
250 elif [ "$SHUTDOWN" = "savestate" ]; then
251 begin_msg "Saving state of remaining VMs"
252 for v in $VMS; do
253 $VBOXMANAGE --nologo controlvm $v savestate
254 done
255 succ_msg
256 fi
257 fi
258 fi
259 done
260 # wait for some seconds when doing ACPI shutdown
261 if [ "$wait" -ne 0 ]; then
262 begin_msg "Waiting for $wait seconds for VM shutdown"
263 sleep $wait
264 succ_msg
265 fi
266}
267
268setup()
269{
270 stop
271 if find /lib/modules/`uname -r` -name "vboxnetadp\.*" 2>/dev/null|grep -q vboxnetadp; then
272 begin_msg "Removing old VirtualBox netadp kernel module"
273 find /lib/modules/`uname -r` -name "vboxnetadp\.*" 2>/dev/null|xargs rm -f 2>/dev/null
274 succ_msg
275 fi
276 if find /lib/modules/`uname -r` -name "vboxnetflt\.*" 2>/dev/null|grep -q vboxnetflt; then
277 begin_msg "Removing old VirtualBox netflt kernel module"
278 find /lib/modules/`uname -r` -name "vboxnetflt\.*" 2>/dev/null|xargs rm -f 2>/dev/null
279 succ_msg
280 fi
281 if find /lib/modules/`uname -r` -name "vboxdrv\.*" 2>/dev/null|grep -q vboxdrv; then
282 begin_msg "Removing old VirtualBox kernel module"
283 find /lib/modules/`uname -r` -name "vboxdrv\.*" 2>/dev/null|xargs rm -f 2>/dev/null
284 succ_msg
285 fi
286 begin_msg "Recompiling VirtualBox kernel module"
287 if ! $BUILDVBOXDRV \
288 --save-module-symvers /tmp/vboxdrv-Module.symvers \
289 --no-print-directory install > $LOG 2>&1; then
290 failure "Look at $LOG to find out what went wrong"
291 fi
292 if ! $BUILDVBOXNETFLT \
293 --use-module-symvers /tmp/vboxdrv-Module.symvers \
294 --no-print-directory install >> $LOG 2>&1; then
295 failure "Look at $LOG to find out what went wrong"
296 fi
297 if ! $BUILDVBOXNETADP \
298 --use-module-symvers /tmp/vboxdrv-Module.symvers \
299 --no-print-directory install >> $LOG 2>&1; then
300 failure "Look at $LOG to find out what went wrong"
301 fi
302 rm -f /etc/vbox/module_not_compiled
303 succ_msg
304 start
305}
306
307dmnstatus()
308{
309 if running vboxdrv; then
310 if running vboxnetflt; then
311 if running vboxnetadp; then
312 echo "VirtualBox kernel modules (vboxdrv, vboxnetflt and vboxnetadp) are loaded."
313 else
314 echo "VirtualBox kernel modules (vboxdrv and vboxnetflt) are loaded."
315 fi
316 else
317 echo "VirtualBox kernel module is loaded."
318 fi
319 for i in $SHUTDOWN_USERS; do
320 # don't create the ipcd directory with wrong permissions!
321 if [ -d /tmp/.vbox-$i-ipc ]; then
322 export VBOX_IPC_SOCKETID="$i"
323 VMS=`$VBOXMANAGE --nologo list runningvms | sed -e 's/^".*"//' 2>/dev/null`
324 if [ -n "$VMS" ]; then
325 echo "The following VMs are currently running:"
326 for v in $VMS; do
327 echo " $v"
328 done
329 fi
330 fi
331 done
332 else
333 echo "VirtualBox kernel module is not loaded."
334 fi
335}
336
337case "$1" in
338start)
339 start
340 ;;
341stop)
342 stop_vms
343 stop
344 ;;
345stop_vms)
346 stop_vms
347 ;;
348restart)
349 stop && start
350 ;;
351force-reload)
352 stop
353 start
354 ;;
355setup)
356 setup
357 ;;
358status)
359 dmnstatus
360 ;;
361*)
362 echo "Usage: $0 {start|stop|stop_vms|restart|force-reload|status|setup}"
363 exit 1
364esac
365
366exit 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