VirtualBox

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

最後變更 在這個檔案從57969是 57969,由 vboxsync 提交於 9 年 前

Installers/linux: drop DKMS support.

  • 屬性 svn:eol-style 設為 LF
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 10.4 KB
 
1#! /bin/sh
2# Oracle VM VirtualBox
3# Linux kernel module init script
4
5#
6# Copyright (C) 2006-2015 Oracle Corporation
7#
8# This file is part of VirtualBox Open Source Edition (OSE), as
9# available from http://www.alldomusa.eu.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: 345 20 80
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
29## @todo get rid of the autogeneration, perhaps write "group" to
30## a configuration file in /etc
31
32PATH=/sbin:/bin:/usr/sbin:/usr/bin:$PATH
33DEVICE=/dev/vboxdrv
34LOG="/var/log/vbox-install.log"
35MODPROBE=/sbin/modprobe
36SCRIPTNAME=vboxdrv
37
38if $MODPROBE -c | grep -q '^allow_unsupported_modules *0'; then
39 MODPROBE="$MODPROBE --allow-unsupported-modules"
40fi
41
42[ -f /etc/vbox/vbox.cfg ] && . /etc/vbox/vbox.cfg
43export BUILD_TYPE
44export USERNAME
45export USER=$USERNAME
46
47if [ -n "$INSTALL_DIR" ]; then
48 VBOXMANAGE="$INSTALL_DIR/VBoxManage"
49 MODULE_SRC="$INSTALL_DIR/src/vboxhost"
50else
51 VBOXMANAGE="/usr/lib/virtualbox/VBoxManage"
52 MODULE_SRC="/usr/share/virtualbox/src/vboxhost"
53fi
54BUILDINTMP="$MODULE_SRC/build_in_tmp"
55
56# silently exit if the package was uninstalled but not purged,
57# applies to Debian packages only (but shouldn't hurt elsewhere)
58[ ! -f /etc/debian_release -o -x $VBOXMANAGE -a -x $BUILDINTMP ] || exit 0
59
60[ -r /etc/default/virtualbox ] && . /etc/default/virtualbox
61
62# Preamble for Gentoo
63if [ "`which $0`" = "/sbin/rc" ]; then
64 shift
65fi
66
67begin_msg()
68{
69 test -n "${2}" && echo "${SCRIPTNAME}: ${1}."
70 logger "${SCRIPTNAME}: ${1}."
71}
72
73succ_msg()
74{
75 logger "${SCRIPTNAME}: done."
76}
77
78fail_msg()
79{
80 echo "${SCRIPTNAME}: failed: ${1}." >&2
81 logger "${SCRIPTNAME}: failed: ${1}."
82}
83
84failure()
85{
86 fail_msg "$1"
87 exit 0
88}
89
90running()
91{
92 lsmod | grep -q "$1[^_-]"
93}
94
95start()
96{
97 begin_msg "Starting VirtualBox kernel modules" console
98 if [ -d /proc/xen ]; then
99 failure "Running VirtualBox in a Xen environment is not supported"
100 fi
101 if ! running vboxdrv; then
102 if ! rm -f $DEVICE; then
103 failure "Cannot remove $DEVICE"
104 fi
105 if ! $MODPROBE vboxdrv > /dev/null 2>&1; then
106 failure "modprobe vboxdrv failed. Please use 'dmesg' to find out why"
107 fi
108 sleep .2
109 fi
110 # ensure the character special exists
111 if [ ! -c $DEVICE ]; then
112 MAJOR=`sed -n 's;\([0-9]\+\) vboxdrv$;\1;p' /proc/devices`
113 if [ ! -z "$MAJOR" ]; then
114 MINOR=0
115 else
116 MINOR=`sed -n 's;\([0-9]\+\) vboxdrv$;\1;p' /proc/misc`
117 if [ ! -z "$MINOR" ]; then
118 MAJOR=10
119 fi
120 fi
121 if [ -z "$MAJOR" ]; then
122 rmmod vboxdrv 2>/dev/null
123 failure "Cannot locate the VirtualBox device"
124 fi
125 if ! mknod -m 0660 $DEVICE c $MAJOR $MINOR 2>/dev/null; then
126 rmmod vboxdrv 2>/dev/null
127 failure "Cannot create device $DEVICE with major $MAJOR and minor $MINOR"
128 fi
129 fi
130 # ensure permissions
131 if ! chown :%GROUP% $DEVICE 2>/dev/null; then
132 rmmod vboxpci 2>/dev/null
133 rmmod vboxnetadp 2>/dev/null
134 rmmod vboxnetflt 2>/dev/null
135 rmmod vboxdrv 2>/dev/null
136 failure "Cannot change group %GROUP% for device $DEVICE"
137 fi
138 if ! $MODPROBE vboxnetflt > /dev/null 2>&1; then
139 failure "modprobe vboxnetflt failed. Please use 'dmesg' to find out why"
140 fi
141 if ! $MODPROBE vboxnetadp > /dev/null 2>&1; then
142 failure "modprobe vboxnetadp failed. Please use 'dmesg' to find out why"
143 fi
144 if ! $MODPROBE vboxpci > /dev/null 2>&1; then
145 failure "modprobe vboxpci failed. Please use 'dmesg' to find out why"
146 fi
147 # Create the /dev/vboxusb directory if the host supports that method
148 # of USB access. The USB code checks for the existance of that path.
149 if grep -q usb_device /proc/devices; then
150 mkdir -p -m 0750 /dev/vboxusb 2>/dev/null
151 chown root:vboxusers /dev/vboxusb 2>/dev/null
152 fi
153 succ_msg
154}
155
156stop()
157{
158 begin_msg "Stopping VirtualBox kernel modules" console
159 if running vboxpci; then
160 if ! rmmod vboxpci 2>/dev/null; then
161 failure "Cannot unload module vboxpci"
162 fi
163 fi
164 if running vboxnetadp; then
165 if ! rmmod vboxnetadp 2>/dev/null; then
166 failure "Cannot unload module vboxnetadp"
167 fi
168 fi
169 if running vboxdrv; then
170 if running vboxnetflt; then
171 if ! rmmod vboxnetflt 2>/dev/null; then
172 failure "Cannot unload module vboxnetflt"
173 fi
174 fi
175 if ! rmmod vboxdrv 2>/dev/null; then
176 failure "Cannot unload module vboxdrv"
177 fi
178 if ! rm -f $DEVICE; then
179 failure "Cannot unlink $DEVICE"
180 fi
181 fi
182 succ_msg
183}
184
185# enter the following variables in /etc/default/virtualbox:
186# SHUTDOWN_USERS="foo bar"
187# check for running VMs of user foo and user bar
188# SHUTDOWN=poweroff
189# SHUTDOWN=acpibutton
190# SHUTDOWN=savestate
191# select one of these shutdown methods for running VMs
192stop_vms()
193{
194 wait=0
195 for i in $SHUTDOWN_USERS; do
196 # don't create the ipcd directory with wrong permissions!
197 if [ -d /tmp/.vbox-$i-ipc ]; then
198 export VBOX_IPC_SOCKETID="$i"
199 VMS=`$VBOXMANAGE --nologo list runningvms | sed -e 's/^".*".*{\(.*\)}/\1/' 2>/dev/null`
200 if [ -n "$VMS" ]; then
201 if [ "$SHUTDOWN" = "poweroff" ]; then
202 begin_msg "Powering off remaining VMs"
203 for v in $VMS; do
204 $VBOXMANAGE --nologo controlvm $v poweroff
205 done
206 succ_msg
207 elif [ "$SHUTDOWN" = "acpibutton" ]; then
208 begin_msg "Sending ACPI power button event to remaining VMs"
209 for v in $VMS; do
210 $VBOXMANAGE --nologo controlvm $v acpipowerbutton
211 wait=30
212 done
213 succ_msg
214 elif [ "$SHUTDOWN" = "savestate" ]; then
215 begin_msg "Saving state of remaining VMs"
216 for v in $VMS; do
217 $VBOXMANAGE --nologo controlvm $v savestate
218 done
219 succ_msg
220 fi
221 fi
222 fi
223 done
224 # wait for some seconds when doing ACPI shutdown
225 if [ "$wait" -ne 0 ]; then
226 begin_msg "Waiting for $wait seconds for VM shutdown"
227 sleep $wait
228 succ_msg
229 fi
230}
231
232# setup_script
233setup()
234{
235 stop
236 if find /lib/modules/`uname -r` -name "vboxpci\.*" 2>/dev/null|grep -q vboxpci; then
237 begin_msg "Removing old VirtualBox pci kernel module"
238 find /lib/modules/`uname -r` -name "vboxpci\.*" 2>/dev/null|xargs rm -f 2>/dev/null
239 succ_msg
240 fi
241 if find /lib/modules/`uname -r` -name "vboxnetadp\.*" 2>/dev/null|grep -q vboxnetadp; then
242 begin_msg "Removing old VirtualBox netadp kernel module"
243 find /lib/modules/`uname -r` -name "vboxnetadp\.*" 2>/dev/null|xargs rm -f 2>/dev/null
244 succ_msg
245 fi
246 if find /lib/modules/`uname -r` -name "vboxnetflt\.*" 2>/dev/null|grep -q vboxnetflt; then
247 begin_msg "Removing old VirtualBox netflt kernel module"
248 find /lib/modules/`uname -r` -name "vboxnetflt\.*" 2>/dev/null|xargs rm -f 2>/dev/null
249 succ_msg
250 fi
251 if find /lib/modules/`uname -r` -name "vboxdrv\.*" 2>/dev/null|grep -q vboxdrv; then
252 begin_msg "Removing old VirtualBox kernel module"
253 find /lib/modules/`uname -r` -name "vboxdrv\.*" 2>/dev/null|xargs rm -f 2>/dev/null
254 succ_msg
255 fi
256 begin_msg "Recompiling VirtualBox kernel modules"
257 if ! $BUILDINTMP \
258 --save-module-symvers /tmp/vboxdrv-Module.symvers \
259 --module-source "$MODULE_SRC/vboxdrv" \
260 --no-print-directory install >> $LOG 2>&1; then
261 failure "Look at $LOG to find out what went wrong"
262 fi
263 if ! $BUILDINTMP \
264 --use-module-symvers /tmp/vboxdrv-Module.symvers \
265 --module-source "$MODULE_SRC/vboxnetflt" \
266 --no-print-directory install >> $LOG 2>&1; then
267 failure "Look at $LOG to find out what went wrong"
268 fi
269 if ! $BUILDINTMP \
270 --use-module-symvers /tmp/vboxdrv-Module.symvers \
271 --module-source "$MODULE_SRC/vboxnetadp" \
272 --no-print-directory install >> $LOG 2>&1; then
273 failure "Look at $LOG to find out what went wrong"
274 fi
275 if ! $BUILDINTMP \
276 --use-module-symvers /tmp/vboxdrv-Module.symvers \
277 --module-source "$MODULE_SRC/vboxpci" \
278 --no-print-directory install >> $LOG 2>&1; then
279 failure "Look at $LOG to find out what went wrong"
280 fi
281 rm -f /etc/vbox/module_not_compiled
282 succ_msg
283 start
284}
285
286dmnstatus()
287{
288 if running vboxdrv; then
289 str="vboxdrv"
290 if running vboxnetflt; then
291 str="$str, vboxnetflt"
292 if running vboxnetadp; then
293 str="$str, vboxnetadp"
294 fi
295 fi
296 if running vboxpci; then
297 str="$str, vboxpci"
298 fi
299 echo "VirtualBox kernel modules ($str) are loaded."
300 for i in $SHUTDOWN_USERS; do
301 # don't create the ipcd directory with wrong permissions!
302 if [ -d /tmp/.vbox-$i-ipc ]; then
303 export VBOX_IPC_SOCKETID="$i"
304 VMS=`$VBOXMANAGE --nologo list runningvms | sed -e 's/^".*".*{\(.*\)}/\1/' 2>/dev/null`
305 if [ -n "$VMS" ]; then
306 echo "The following VMs are currently running:"
307 for v in $VMS; do
308 echo " $v"
309 done
310 fi
311 fi
312 done
313 else
314 echo "VirtualBox kernel module is not loaded."
315 fi
316}
317
318case "$1" in
319start)
320 start
321 ;;
322stop)
323 stop_vms
324 stop
325 ;;
326stop_vms)
327 stop_vms
328 ;;
329restart)
330 stop && start
331 ;;
332force-reload)
333 stop
334 start
335 ;;
336setup)
337 setup
338 ;;
339status)
340 dmnstatus
341 ;;
342*)
343 echo "Usage: $0 {start|stop|stop_vms|restart|force-reload|status|setup}"
344 exit 1
345esac
346
347exit 0
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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