VirtualBox

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

Last change on this file since 14256 was 14256, checked in by vboxsync, 16 years ago

Linux installer: added vboxnetflt support

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 9.3 KB
Line 
1#! /bin/sh
2# Sun xVM VirtualBox
3# Linux kernel module init script
4
5#
6# Copyright (C) 2006-2007 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 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: 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%
34NETFLT=%NETFLT%
35
36[ -f /lib/lsb/init-functions ] || NOLSB=yes
37[ -f /etc/vbox/vbox.cfg ] && . /etc/vbox/vbox.cfg
38
39if [ -n "$INSTALL_DIR" ]; then
40 VBOXMANAGE="$INSTALL_DIR/VBoxManage"
41 BUILDVBOXDRV="$INSTALL_DIR/src/vboxdrv/build_in_tmp"
42 BUILDVBOXNETFLT="$INSTALL_DIR/src/vboxnetflt/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"
47fi
48
49if [ -n "$NOLSB" ]; then
50 if [ -f /etc/redhat-release ]; then
51 system=redhat
52 elif [ -f /etc/SuSE-release ]; then
53 system=suse
54 elif [ -f /etc/gentoo-release ]; then
55 system=gentoo
56 fi
57fi
58
59[ -r /etc/default/%PACKAGE% ] && . /etc/default/%PACKAGE%
60
61if [ -z "$NOLSB" ]; then
62 . /lib/lsb/init-functions
63 fail_msg() {
64 echo ""
65 log_failure_msg "$1"
66 }
67 succ_msg() {
68 log_success_msg " done."
69 }
70 begin_msg() {
71 log_daemon_msg "$@"
72 }
73else
74 if [ "$system" = "redhat" ]; then
75 . /etc/init.d/functions
76 fail_msg() {
77 echo -n " "
78 echo_failure
79 echo
80 echo " ($1)"
81 }
82 succ_msg() {
83 echo -n " "
84 echo_success
85 echo
86 }
87 elif [ "$system" = "suse" ]; then
88 . /etc/rc.status
89 fail_msg() {
90 rc_failed 1
91 rc_status -v
92 echo " ($1)"
93 }
94 succ_msg() {
95 rc_reset
96 rc_status -v
97 }
98 elif [ "$system" = "gentoo" ]; then
99 . /sbin/functions.sh
100 fail_msg() {
101 eerror "$1"
102 }
103 succ_msg() {
104 eend "$?"
105 }
106 begin_msg() {
107 ebegin "$1"
108 }
109 if [ "`which $0`" = "/sbin/rc" ]; then
110 shift
111 fi
112 else
113 fail_msg() {
114 echo " ...failed!"
115 echo " ($1)"
116 }
117 succ_msg() {
118 echo " ...done."
119 }
120 fi
121 if [ "$system" != "gentoo" ]; then
122 begin_msg() {
123 [ -z "${1:-}" ] && return 1
124 if [ -z "${2:-}" ]; then
125 echo -n "$1"
126 else
127 echo -n "$1: $2"
128 fi
129 }
130 fi
131fi
132
133failure()
134{
135 fail_msg "$1"
136 exit 0
137}
138
139running()
140{
141 lsmod | grep -q "$1[^_-]"
142}
143
144start()
145{
146 begin_msg "Starting VirtualBox kernel module"
147 if ! running vboxdrv; then
148 if ! find /lib/modules/`uname -r` -name "vboxdrv\.*" 2>/dev/null|grep -q vboxdrv; then
149 failure "No suitable module for running kernel found"
150 fi
151 if ! rm -f $DEVICE; then
152 failure "Cannot remove $DEVICE"
153 fi
154 if ! modprobe vboxdrv > /dev/null 2>&1; then
155 failure "modprobe vboxdrv failed. Please use 'dmesg' to find out why"
156 fi
157 sleep .2
158 fi
159 # ensure the character special exists
160 if [ ! -c $DEVICE ]; then
161 MAJOR=`sed -n 's;\([0-9]\+\) vboxdrv;\1;p' /proc/devices`
162 if [ ! -z "$MAJOR" ]; then
163 MINOR=0
164 else
165 MINOR=`sed -n 's;\([0-9]\+\) vboxdrv;\1;p' /proc/misc`
166 if [ ! -z "$MINOR" ]; then
167 MAJOR=10
168 fi
169 fi
170 if [ -z "$MAJOR" ]; then
171 rmmod vboxdrv 2>/dev/null
172 failure "Cannot locate the VirtualBox device"
173 fi
174 if ! mknod -m 0660 $DEVICE c $MAJOR $MINOR 2>/dev/null; then
175 rmmod vboxdrv 2>/dev/null
176 failure "Cannot create device $DEVICE with major $MAJOR and minor $MINOR"
177 fi
178 fi
179 # ensure permissions
180 if ! chown :$GROUPNAME $DEVICE 2>/dev/null; then
181 rmmod vboxnetflt 2>/dev/null
182 rmmod vboxdrv 2>/dev/null
183 failure "Cannot change owner $GROUPNAME for device $DEVICE"
184 fi
185 if [ -n "$NETFLT" ]; then
186 if ! modprobe vboxnetflt > /dev/null 2>&1; then
187 failure "modprobe vboxnetflt failed. Please use 'dmesg' to find out why"
188 fi
189 fi
190 succ_msg
191}
192
193stop()
194{
195 begin_msg "Stopping VirtualBox kernel module"
196 if running vboxdrv; then
197 if running vboxnetflt; then
198 if ! rmmod vboxnetflt 2>/dev/null; then
199 failure "Cannot unload module vboxnetflt"
200 fi
201 fi
202 if ! rmmod vboxdrv 2>/dev/null; then
203 failure "Cannot unload module vboxdrv"
204 fi
205 if ! rm -f $DEVICE; then
206 failure "Cannot unlink $DEVICE"
207 fi
208 fi
209 succ_msg
210}
211
212# enter the following variables in /etc/default/%PACKAGE%:
213# SHUTDOWN_USERS="foo bar"
214# check for running VMs of user foo and user bar
215# SHUTDOWN=poweroff
216# SHUTDOWN=acpibutton
217# SHUTDOWN=savestate
218# select one of these shutdown methods for running VMs
219stop_vms()
220{
221 wait=0
222 for i in $SHUTDOWN_USERS; do
223 # don't create the ipcd directory with wrong permissions!
224 if [ -d /tmp/.vbox-$i-ipc ]; then
225 export VBOX_IPC_SOCKETID="$i"
226 VMS=`$VBOXMANAGE -nologo list runningvms 2>/dev/null`
227 if [ -n "$VMS" ]; then
228 if [ "$SHUTDOWN" = "poweroff" ]; then
229 begin_msg "Powering off remaining VMs"
230 for v in $VMS; do
231 $VBOXMANAGE -nologo controlvm $v poweroff
232 done
233 succ_msg
234 elif [ "$SHUTDOWN" = "acpibutton" ]; then
235 begin_msg "Sending ACPI power button event to remaining VMs"
236 for v in $VMS; do
237 $VBOXMANAGE -nologo controlvm $v acpipowerbutton
238 wait=30
239 done
240 succ_msg
241 elif [ "$SHUTDOWN" = "savestate" ]; then
242 begin_msg "Saving state of remaining VMs"
243 for v in $VMS; do
244 $VBOXMANAGE -nologo controlvm $v savestate
245 done
246 succ_msg
247 fi
248 fi
249 fi
250 done
251 # wait for some seconds when doing ACPI shutdown
252 if [ "$wait" -ne 0 ]; then
253 begin_msg "Waiting for $wait seconds for VM shutdown"
254 sleep $wait
255 succ_msg
256 fi
257}
258
259setup()
260{
261 stop
262 if find /lib/modules/`uname -r` -name "vboxnetflt\.*" 2>/dev/null|grep -q vboxnetflt; then
263 begin_msg "Removing old VirtualBox netflt kernel module"
264 find /lib/modules/`uname -r` -name "vboxnetflt\.*" 2>/dev/null|xargs rm -f 2>/dev/null
265 succ_msg
266 fi
267 if find /lib/modules/`uname -r` -name "vboxdrv\.*" 2>/dev/null|grep -q vboxdrv; then
268 begin_msg "Removing old VirtualBox kernel module"
269 find /lib/modules/`uname -r` -name "vboxdrv\.*" 2>/dev/null|xargs rm -f 2>/dev/null
270 succ_msg
271 fi
272 begin_msg "Recompiling VirtualBox kernel module"
273 if ! $BUILDVBOXDRV \
274 --save-module-symvers /tmp/vboxdrv-Module.symvers \
275 --no-print-directory install > $LOG 2>&1; then
276 failure "Look at $LOG to find out what went wrong"
277 fi
278 if [ -n "$NETFLT" ]; then
279 if ! $BUILDVBOXNETFLT \
280 --use-module-symvers /tmp/vboxdrv-Module.symvers \
281 --no-print-directory install >> $LOG 2>&1; then
282 failure "Look at $LOG to find out what went wrong"
283 fi
284 fi
285 succ_msg
286 start
287}
288
289dmnstatus()
290{
291 if running vboxdrv; then
292 if running vboxnetflt; then
293 echo "VirtualBox kernel modules (vboxdrv and vboxnetflt) are loaded."
294 else
295 echo "VirtualBox kernel module is loaded."
296 fi
297 for i in $SHUTDOWN_USERS; do
298 # don't create the ipcd directory with wrong permissions!
299 if [ -d /tmp/.vbox-$i-ipc ]; then
300 export VBOX_IPC_SOCKETID="$i"
301 VMS=`$VBOXMANAGE -nologo list runningvms 2>/dev/null`
302 if [ -n "$VMS" ]; then
303 echo "The following VMs are currently running:"
304 for v in $VMS; do
305 echo " $v"
306 done
307 fi
308 fi
309 done
310 else
311 echo "VirtualBox kernel module is not loaded."
312 fi
313}
314
315case "$1" in
316start)
317 start
318 ;;
319stop)
320 stop_vms
321 stop
322 ;;
323stop_vms)
324 stop_vms
325 ;;
326restart)
327 stop && start
328 ;;
329force-reload)
330 stop
331 start
332 ;;
333setup)
334 setup
335 ;;
336status)
337 dmnstatus
338 ;;
339*)
340 echo "Usage: $0 {start|stop|stop_vms|restart|force-reload|status|setup}"
341 exit 1
342esac
343
344exit 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