VirtualBox

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

Last change on this file since 7108 was 7006, checked in by vboxsync, 17 years ago

Installers/Linux: after a DKMS kernel module build, the module was no longer loaded properly as DKMS installs to a different location

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 6.8 KB
Line 
1#! /bin/sh
2# innotek VirtualBox
3# Linux kernel module init script
4
5#
6# Copyright (C) 2006-2007 innotek GmbH
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 60
18# description: VirtualBox Linux kernel module
19#
20### BEGIN INIT INFO
21# Provides: vboxdrv
22# Required-Start: $syslog
23# Required-Stop:
24# Default-Start: 3 5
25# Default-Stop:
26# Description: VirtualBox Linux kernel module
27### END INIT INFO
28
29PATH=$PATH:/bin:/sbin:/usr/sbin
30CONFIG="/etc/vbox/vbox.cfg"
31. "$CONFIG"
32VBOXMANAGE="$INSTALL_DIR/VBoxManage"
33
34if [ -f /etc/redhat-release ]; then
35 system=redhat
36elif [ -f /etc/SuSE-release ]; then
37 system=suse
38elif [ -f /etc/gentoo-release ]; then
39 system=gentoo
40else
41 system=other
42fi
43
44if [ -r /etc/default/virtualbox ]; then
45 . /etc/default/virtualbox
46fi
47
48if [ "$system" = "redhat" ]; then
49 . /etc/init.d/functions
50 fail_msg() {
51 echo_failure
52 echo
53 }
54
55 succ_msg() {
56 echo_success
57 echo
58 }
59
60 begin() {
61 echo -n "$1"
62 }
63fi
64
65if [ "$system" = "suse" ]; then
66 . /etc/rc.status
67 fail_msg() {
68 rc_failed 1
69 rc_status -v
70 }
71
72 succ_msg() {
73 rc_reset
74 rc_status -v
75 }
76
77 begin() {
78 echo -n "$1"
79 }
80fi
81
82if [ "$system" = "gentoo" ]; then
83 . /sbin/functions.sh
84 fail_msg() {
85 eend 1
86 }
87
88 succ_msg() {
89 eend $?
90 }
91
92 begin() {
93 ebegin $1
94 }
95
96 if [ "`which $0`" = "/sbin/rc" ]; then
97 shift
98 fi
99fi
100
101if [ "$system" = "other" ]; then
102 fail_msg() {
103 echo " ...fail!"
104 }
105
106 succ_msg() {
107 echo " ...done."
108 }
109
110 begin() {
111 echo -n $1
112 }
113fi
114
115
116dev=/dev/vboxdrv
117modname=vboxdrv
118groupname=vboxusers
119
120fail() {
121 if [ "$system" = "gentoo" ]; then
122 eerror $1
123 exit 1
124 fi
125 fail_msg
126 echo "($1)"
127 exit 1
128}
129
130running() {
131 lsmod | grep -q "$modname[^_-]"
132}
133
134start() {
135 begin "Starting VirtualBox kernel module "
136 find /lib/modules/`uname -r` -name "vboxdrv\.*" 2>/dev/null|grep -q vboxdrv || {
137 fail "Kernel module not found"
138 }
139 running || {
140 rm -f $dev || {
141 fail "Cannot remove $dev"
142 }
143
144 modprobe $modname > /dev/null 2>&1 || {
145 fail "modprobe $modname failed"
146 }
147
148 sleep 1
149 }
150 if [ ! -c $dev ]; then
151 maj=`sed -n 's;\([0-9]\+\) vboxdrv;\1;p' /proc/devices`
152 if [ ! -z "$maj" ]; then
153 min=0
154 else
155 min=`sed -n 's;\([0-9]\+\) vboxdrv;\1;p' /proc/misc`
156 if [ ! -z "$min" ]; then
157 maj=10
158 fi
159 fi
160 test -z "$maj" && {
161 rmmod $modname 2>/dev/null
162 fail "Cannot locate the VirtualBox device"
163 }
164
165 mknod -m 0660 $dev c $maj $min 2>/dev/null || {
166 rmmod $modname 2>/dev/null
167 fail "Cannot create device $dev with major $maj and minor $min"
168 }
169 fi
170
171 chown :$groupname $dev 2>/dev/null || {
172 rmmod $modname 2>/dev/null
173 fail "Cannot change owner $groupname for device $dev"
174 }
175
176 succ_msg
177 return 0
178}
179
180stop() {
181 begin "Stopping VirtualBox kernel module "
182 if running; then
183 rmmod $modname 2>/dev/null || fail "Cannot unload module $modname"
184 rm -f $dev || fail "Cannot unlink $dev"
185 fi
186 succ_msg
187 return 0
188}
189
190# enter the following variables in /etc/default/virtualbox:
191# SHUTDOWN_USERS="foo bar"
192# check for running VMs of user foo and user bar
193# SHUTDOWN=poweroff
194# SHUTDOWN=acpibutton
195# SHUTDOWN=savestate
196# select one of these shutdown methods for running VMs
197stop_vms() {
198 wait=0
199 for i in $SHUTDOWN_USERS; do
200 # don't create the ipcd directory with wrong permissions!
201 if [ -d /tmp/.vbox-$i-ipc ]; then
202 export VBOX_IPC_SOCKETID="$i"
203 VMS=`$VBOXMANAGE -nologo list runningvms 2>/dev/null`
204 if [ -n "$VMS" ]; then
205 if [ "$SHUTDOWN" = "poweroff" ]; then
206 begin "Powering off remaining VMs "
207 for v in $VMS; do
208 $VBOXMANAGE -nologo controlvm $v poweroff
209 done
210 succ_msg
211 elif [ "$SHUTDOWN" = "acpibutton" ]; then
212 begin "Sending ACPI power button event to remaining VMs "
213 for v in $VMS; do
214 $VBOXMANAGE -nologo controlvm $v acpipowerbutton
215 wait=15
216 done
217 succ_msg
218 elif [ "$SHUTDOWN" = "savestate" ]; then
219 begin "Saving state of remaining VMs "
220 for v in $VMS; do
221 $VBOXMANAGE -nologo controlvm $v savestate
222 done
223 succ_msg
224 fi
225 fi
226 fi
227 done
228 # wait for some seconds when doing ACPI shutdown
229 if [ "$wait" -ne 0 ]; then
230 log_daemon_msg "Waiting for $wait seconds for VM shutdown"
231 sleep $wait
232 log_end_msg
233 fi
234}
235
236restart() {
237 stop && start
238 return 0
239}
240
241setup() {
242 stop
243 if find /lib/modules/`uname -r` -name "vboxdrv\.*" 2>/dev/null|grep -q vboxdrv; then
244 begin "Removing old VirtualBox kernel module "
245 find /lib/modules/`uname -r` -name "vboxdrv\.*" 2>/dev/null|xargs rm -f 2>/dev/null
246 succ_msg
247 fi
248 begin "Recompiling VirtualBox kernel module "
249 if ! $INSTALL_DIR/src/build_in_tmp install > /var/log/vbox-install.log 2>&1; then
250 fail "Look at /var/log/vbox-install.log to find out what went wrong"
251 fi
252 succ_msg
253 start
254}
255
256dmnstatus() {
257 if running; then
258 echo "VirtualBox kernel module is loaded."
259 for i in $SHUTDOWN_USERS; do
260 # don't create the ipcd directory with wrong permissions!
261 if [ -d /tmp/.vbox-$i-ipc ]; then
262 export VBOX_IPC_SOCKETID="$i"
263 VMS=`$VBOXMANAGE -nologo list runningvms 2>/dev/null`
264 if [ -n "$VMS" ]; then
265 echo "The following VMs are currently running:"
266 for v in $VMS; do
267 echo " $v"
268 done
269 fi
270 fi
271 done
272 else
273 echo "VirtualBox kernel module is not loaded."
274 fi
275}
276
277case "$1" in
278start)
279 start
280 ;;
281stop)
282 stop_vms
283 stop
284 ;;
285stop_vms)
286 stop_vms
287 ;;
288restart)
289 restart
290 ;;
291setup)
292 setup
293 ;;
294status)
295 dmnstatus
296 ;;
297*)
298 echo "Usage: $0 {start|stop|stop_vms|restart|status|setup}"
299 exit 1
300esac
301
302exit
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