VirtualBox

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

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

Installer: Linux: vboxdrv.sh: introduce helper functions to detect compatible modules installation, bugref:9958

  • 屬性 svn:eol-style 設為 LF
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 21.2 KB
 
1#! /bin/sh
2# Oracle VM VirtualBox
3# Linux kernel module init script
4
5#
6# Copyright (C) 2006-2020 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 This file duplicates a lot of script with vboxadd.sh. When making
30# changes please try to reduce differences between the two wherever possible.
31
32## @todo Remove the stop_vms target so that this script is only relevant to
33# kernel modules. Nice but not urgent.
34
35PATH=/sbin:/bin:/usr/sbin:/usr/bin:$PATH
36DEVICE=/dev/vboxdrv
37MODPROBE=/sbin/modprobe
38SCRIPTNAME=vboxdrv.sh
39
40# The below is GNU-specific. See VBox.sh for the longer Solaris/OS X version.
41TARGET=`readlink -e -- "${0}"` || exit 1
42SCRIPT_DIR="${TARGET%/[!/]*}"
43
44if $MODPROBE -c | grep -q '^allow_unsupported_modules *0'; then
45 MODPROBE="$MODPROBE --allow-unsupported-modules"
46fi
47
48setup_log()
49{
50 test -n "${LOG}" && return 0
51 # Rotate log files
52 LOG="/var/log/vbox-setup.log"
53 mv "${LOG}.3" "${LOG}.4" 2>/dev/null
54 mv "${LOG}.2" "${LOG}.3" 2>/dev/null
55 mv "${LOG}.1" "${LOG}.2" 2>/dev/null
56 mv "${LOG}" "${LOG}.1" 2>/dev/null
57}
58
59[ -f /etc/vbox/vbox.cfg ] && . /etc/vbox/vbox.cfg
60export VBOX_KBUILD_TYPE
61export USERNAME
62export USER=$USERNAME
63
64if test -n "${INSTALL_DIR}" && test -x "${INSTALL_DIR}/VirtualBox"; then
65 MODULE_SRC="${INSTALL_DIR}/src/vboxhost"
66elif test -x /usr/lib/virtualbox/VirtualBox; then
67 INSTALL_DIR=/usr/lib/virtualbox
68 MODULE_SRC="/usr/share/virtualbox/src/vboxhost"
69elif test -x "${SCRIPT_DIR}/VirtualBox"; then
70 # Executing from the build directory
71 INSTALL_DIR="${SCRIPT_DIR}"
72 MODULE_SRC="${INSTALL_DIR}/src"
73else
74 # Silently exit if the package was uninstalled but not purged.
75 # Applies to Debian packages only (but shouldn't hurt elsewhere)
76 exit 0
77fi
78VIRTUALBOX="${INSTALL_DIR}/VirtualBox"
79VBOXMANAGE="${INSTALL_DIR}/VBoxManage"
80BUILDINTMP="${MODULE_SRC}/build_in_tmp"
81if test -u "${VIRTUALBOX}"; then
82 GROUP=root
83 DEVICE_MODE=0600
84else
85 GROUP=vboxusers
86 DEVICE_MODE=0660
87fi
88
89KERN_VER=`uname -r`
90if test -e "${MODULE_SRC}/vboxpci"; then
91 MODULE_LIST="vboxdrv vboxnetflt vboxnetadp vboxpci"
92else
93 MODULE_LIST="vboxdrv vboxnetflt vboxnetadp"
94fi
95# Secure boot state.
96case "`mokutil --sb-state 2>/dev/null`" in
97 *"disabled in shim"*) unset HAVE_SEC_BOOT;;
98 *"SecureBoot enabled"*) HAVE_SEC_BOOT=true;;
99 *) unset HAVE_SEC_BOOT;;
100esac
101# So far we can only sign modules on Ubuntu and on Debian 10 and later.
102DEB_PUB_KEY=/var/lib/shim-signed/mok/MOK.der
103DEB_PRIV_KEY=/var/lib/shim-signed/mok/MOK.priv
104unset HAVE_DEB_KEY
105case "`mokutil --test-key "$DEB_PUB_KEY" 2>/dev/null`" in
106 *"is already"*) DEB_KEY_ENROLLED=true;;
107 *) unset DEB_KEY_ENROLLED;;
108esac
109
110[ -r /etc/default/virtualbox ] && . /etc/default/virtualbox
111
112# Preamble for Gentoo
113if [ "`which $0`" = "/sbin/rc" ]; then
114 shift
115fi
116
117begin_msg()
118{
119 test -n "${2}" && echo "${SCRIPTNAME}: ${1}."
120 logger -t "${SCRIPTNAME}" "${1}."
121}
122
123succ_msg()
124{
125 logger -t "${SCRIPTNAME}" "${1}."
126}
127
128fail_msg()
129{
130 echo "${SCRIPTNAME}: failed: ${1}." >&2
131 logger -t "${SCRIPTNAME}" "failed: ${1}."
132}
133
134failure()
135{
136 fail_msg "$1"
137 exit 1
138}
139
140running()
141{
142 lsmod | grep -q "$1[^_-]"
143}
144
145log()
146{
147 setup_log
148 echo "${1}" >> "${LOG}"
149}
150
151module_build_log()
152{
153 setup_log
154 echo "${1}" | egrep -v \
155 "^test -e include/generated/autoconf.h|^echo >&2|^/bin/false\)$" \
156 >> "${LOG}"
157}
158
159# Detect VirtualBox version info or report error on error.
160VBOX_VERSION=$($VBOXMANAGE -v 2>/dev/null | cut -d 'r' -f1)
161VBOX_REVISION="r$($VBOXMANAGE -v 2>/dev/null | cut -d 'r' -f2)"
162if test -z "$VBOX_VERSION" -o "$VBOX_REVISION" = "r"; then
163 failure 'Cannot detect VirtualBox version'
164fi
165
166## Output the vboxdrv part of our udev rule. This is redirected to the right file.
167udev_write_vboxdrv() {
168 VBOXDRV_GRP="$1"
169 VBOXDRV_MODE="$2"
170
171 echo "KERNEL==\"vboxdrv\", NAME=\"vboxdrv\", OWNER=\"root\", GROUP=\"$VBOXDRV_GRP\", MODE=\"$VBOXDRV_MODE\""
172 echo "KERNEL==\"vboxdrvu\", NAME=\"vboxdrvu\", OWNER=\"root\", GROUP=\"root\", MODE=\"0666\""
173 echo "KERNEL==\"vboxnetctl\", NAME=\"vboxnetctl\", OWNER=\"root\", GROUP=\"$VBOXDRV_GRP\", MODE=\"$VBOXDRV_MODE\""
174}
175
176## Output the USB part of our udev rule. This is redirected to the right file.
177udev_write_usb() {
178 INSTALLATION_DIR="$1"
179 USB_GROUP="$2"
180
181 echo "SUBSYSTEM==\"usb_device\", ACTION==\"add\", RUN+=\"$INSTALLATION_DIR/VBoxCreateUSBNode.sh \$major \$minor \$attr{bDeviceClass}${USB_GROUP}\""
182 echo "SUBSYSTEM==\"usb\", ACTION==\"add\", ENV{DEVTYPE}==\"usb_device\", RUN+=\"$INSTALLATION_DIR/VBoxCreateUSBNode.sh \$major \$minor \$attr{bDeviceClass}${USB_GROUP}\""
183 echo "SUBSYSTEM==\"usb_device\", ACTION==\"remove\", RUN+=\"$INSTALLATION_DIR/VBoxCreateUSBNode.sh --remove \$major \$minor\""
184 echo "SUBSYSTEM==\"usb\", ACTION==\"remove\", ENV{DEVTYPE}==\"usb_device\", RUN+=\"$INSTALLATION_DIR/VBoxCreateUSBNode.sh --remove \$major \$minor\""
185}
186
187## Generate our udev rule file. This takes a change in udev rule syntax in
188## version 55 into account. It only creates rules for USB for udev versions
189## recent enough to support USB device nodes.
190generate_udev_rule() {
191 VBOXDRV_GRP="$1" # The group owning the vboxdrv device
192 VBOXDRV_MODE="$2" # The access mode for the vboxdrv device
193 INSTALLATION_DIR="$3" # The directory VirtualBox is installed in
194 USB_GROUP="$4" # The group that has permission to access USB devices
195 NO_INSTALL="$5" # Set this to "1" to remove but not re-install rules
196
197 # Extra space!
198 case "$USB_GROUP" in ?*) USB_GROUP=" $USB_GROUP" ;; esac
199 case "$NO_INSTALL" in "1") return ;; esac
200 udev_write_vboxdrv "$VBOXDRV_GRP" "$VBOXDRV_MODE"
201 udev_write_usb "$INSTALLATION_DIR" "$USB_GROUP"
202}
203
204## Install udev rule (disable with INSTALL_NO_UDEV=1 in
205## /etc/default/virtualbox).
206install_udev() {
207 VBOXDRV_GRP="$1" # The group owning the vboxdrv device
208 VBOXDRV_MODE="$2" # The access mode for the vboxdrv device
209 INSTALLATION_DIR="$3" # The directory VirtualBox is installed in
210 USB_GROUP="$4" # The group that has permission to access USB devices
211 NO_INSTALL="$5" # Set this to "1" to remove but not re-install rules
212
213 if test -d /etc/udev/rules.d; then
214 generate_udev_rule "$VBOXDRV_GRP" "$VBOXDRV_MODE" "$INSTALLATION_DIR" \
215 "$USB_GROUP" "$NO_INSTALL"
216 fi
217 # Remove old udev description file
218 rm -f /etc/udev/rules.d/10-vboxdrv.rules 2> /dev/null
219}
220
221## Create a usb device node for a given sysfs path to a USB device.
222install_create_usb_node_for_sysfs() {
223 path="$1" # sysfs path for the device
224 usb_createnode="$2" # Path to the USB device node creation script
225 usb_group="$3" # The group to give ownership of the node to
226 if test -r "${path}/dev"; then
227 dev="`cat "${path}/dev" 2> /dev/null`"
228 major="`expr "$dev" : '\(.*\):' 2> /dev/null`"
229 minor="`expr "$dev" : '.*:\(.*\)' 2> /dev/null`"
230 class="`cat ${path}/bDeviceClass 2> /dev/null`"
231 sh "${usb_createnode}" "$major" "$minor" "$class" \
232 "${usb_group}" 2>/dev/null
233 fi
234}
235
236udev_rule_file=/etc/udev/rules.d/60-vboxdrv.rules
237sysfs_usb_devices="/sys/bus/usb/devices/*"
238
239## Install udev rules and create device nodes for usb access
240setup_usb() {
241 VBOXDRV_GRP="$1" # The group that should own /dev/vboxdrv
242 VBOXDRV_MODE="$2" # The mode to be used for /dev/vboxdrv
243 INSTALLATION_DIR="$3" # The directory VirtualBox is installed in
244 USB_GROUP="$4" # The group that should own the /dev/vboxusb device
245 # nodes unless INSTALL_NO_GROUP=1 in
246 # /etc/default/virtualbox. Optional.
247 usb_createnode="$INSTALLATION_DIR/VBoxCreateUSBNode.sh"
248 # install udev rule (disable with INSTALL_NO_UDEV=1 in
249 # /etc/default/virtualbox)
250 if [ "$INSTALL_NO_GROUP" != "1" ]; then
251 usb_group=$USB_GROUP
252 vboxdrv_group=$VBOXDRV_GRP
253 else
254 usb_group=root
255 vboxdrv_group=root
256 fi
257 install_udev "${vboxdrv_group}" "$VBOXDRV_MODE" \
258 "$INSTALLATION_DIR" "${usb_group}" \
259 "$INSTALL_NO_UDEV" > ${udev_rule_file}
260 # Build our device tree
261 for i in ${sysfs_usb_devices}; do # This line intentionally without quotes.
262 install_create_usb_node_for_sysfs "$i" "${usb_createnode}" \
263 "${usb_group}"
264 done
265}
266
267cleanup_usb()
268{
269 # Remove udev description file
270 rm -f /etc/udev/rules.d/60-vboxdrv.rules
271 rm -f /etc/udev/rules.d/10-vboxdrv.rules
272
273 # Remove our USB device tree
274 rm -rf /dev/vboxusb
275}
276
277# Returns module version if module is available or empty string.
278module_version()
279{
280 mod="$1"
281 [ -n "$mod" ] || return
282
283 modinfo "$mod" 2>/dev/null | grep -e "^version:" | tr -s ' ' | cut -d " " -f2
284}
285
286# Returns module revision if module is available in the system or empty string.
287module_revision()
288{
289 mod="$1"
290 [ -n "$mod" ] || return
291
292 modinfo "$mod" 2>/dev/null | grep -e "^version:" | tr -s ' ' | cut -d " " -f3
293}
294
295# Returns "1" if module is available in the system and its version and revision
296# number do match to current VirtualBox installation. Or empty string otherwise.
297module_available()
298{
299 mod="$1"
300 [ -n "$mod" ] || return
301
302 [ "$VBOX_VERSION" = "$(module_version $mod)" ] || return
303 [ "$VBOX_REVISION" = "$(module_revision $mod)" ] || return
304
305 echo "1"
306}
307
308start()
309{
310 begin_msg "Starting VirtualBox services" console
311 if [ -d /proc/xen ]; then
312 failure "Running VirtualBox in a Xen environment is not supported"
313 fi
314 if test -n "$HAVE_SEC_BOOT" && test -z "$DEB_KEY_ENROLLED"; then
315 if test -n "$HAVE_DEB_KEY"; then
316 begin_msg "You must re-start your system to finish Debian secure boot set-up." console
317 else
318 begin_msg "You must sign these kernel modules before using VirtualBox:
319 $MODULE_LIST
320See the documenatation for your Linux distribution." console
321 fi
322 fi
323 if ! running vboxdrv; then
324 if ! rm -f $DEVICE; then
325 failure "Cannot remove $DEVICE"
326 fi
327 if ! $MODPROBE vboxdrv > /dev/null 2>&1; then
328 setup
329 if ! $MODPROBE vboxdrv > /dev/null 2>&1; then
330 failure "modprobe vboxdrv failed. Please use 'dmesg' to find out why"
331 fi
332 fi
333 sleep .2
334 fi
335 # ensure the character special exists
336 if [ ! -c $DEVICE ]; then
337 MAJOR=`sed -n 's;\([0-9]\+\) vboxdrv$;\1;p' /proc/devices`
338 if [ ! -z "$MAJOR" ]; then
339 MINOR=0
340 else
341 MINOR=`sed -n 's;\([0-9]\+\) vboxdrv$;\1;p' /proc/misc`
342 if [ ! -z "$MINOR" ]; then
343 MAJOR=10
344 fi
345 fi
346 if [ -z "$MAJOR" ]; then
347 rmmod vboxdrv 2>/dev/null
348 failure "Cannot locate the VirtualBox device"
349 fi
350 if ! mknod -m 0660 $DEVICE c $MAJOR $MINOR 2>/dev/null; then
351 rmmod vboxdrv 2>/dev/null
352 failure "Cannot create device $DEVICE with major $MAJOR and minor $MINOR"
353 fi
354 fi
355 # ensure permissions
356 if ! chown :"${GROUP}" $DEVICE 2>/dev/null; then
357 rmmod vboxpci 2>/dev/null
358 rmmod vboxnetadp 2>/dev/null
359 rmmod vboxnetflt 2>/dev/null
360 rmmod vboxdrv 2>/dev/null
361 failure "Cannot change group ${GROUP} for device $DEVICE"
362 fi
363 if ! $MODPROBE vboxnetflt > /dev/null 2>&1; then
364 failure "modprobe vboxnetflt failed. Please use 'dmesg' to find out why"
365 fi
366 if ! $MODPROBE vboxnetadp > /dev/null 2>&1; then
367 failure "modprobe vboxnetadp failed. Please use 'dmesg' to find out why"
368 fi
369 if test -e "${MODULE_SRC}/vboxpci" && ! $MODPROBE vboxpci > /dev/null 2>&1; then
370 failure "modprobe vboxpci failed. Please use 'dmesg' to find out why"
371 fi
372 # Create the /dev/vboxusb directory if the host supports that method
373 # of USB access. The USB code checks for the existance of that path.
374 if grep -q usb_device /proc/devices; then
375 mkdir -p -m 0750 /dev/vboxusb 2>/dev/null
376 chown root:vboxusers /dev/vboxusb 2>/dev/null
377 fi
378 # Remove any kernel modules left over from previously installed kernels.
379 cleanup only_old
380 succ_msg "VirtualBox services started"
381}
382
383stop()
384{
385 begin_msg "Stopping VirtualBox services" console
386
387 if running vboxpci; then
388 if ! rmmod vboxpci 2>/dev/null; then
389 failure "Cannot unload module vboxpci"
390 fi
391 fi
392 if running vboxnetadp; then
393 if ! rmmod vboxnetadp 2>/dev/null; then
394 failure "Cannot unload module vboxnetadp"
395 fi
396 fi
397 if running vboxdrv; then
398 if running vboxnetflt; then
399 if ! rmmod vboxnetflt 2>/dev/null; then
400 failure "Cannot unload module vboxnetflt"
401 fi
402 fi
403 if ! rmmod vboxdrv 2>/dev/null; then
404 failure "Cannot unload module vboxdrv"
405 fi
406 if ! rm -f $DEVICE; then
407 failure "Cannot unlink $DEVICE"
408 fi
409 fi
410 succ_msg "VirtualBox services stopped"
411}
412
413# enter the following variables in /etc/default/virtualbox:
414# SHUTDOWN_USERS="foo bar"
415# check for running VMs of user foo and user bar
416# SHUTDOWN=poweroff
417# SHUTDOWN=acpibutton
418# SHUTDOWN=savestate
419# select one of these shutdown methods for running VMs
420stop_vms()
421{
422 wait=0
423 for i in $SHUTDOWN_USERS; do
424 # don't create the ipcd directory with wrong permissions!
425 if [ -d /tmp/.vbox-$i-ipc ]; then
426 export VBOX_IPC_SOCKETID="$i"
427 VMS=`$VBOXMANAGE --nologo list runningvms | sed -e 's/^".*".*{\(.*\)}/\1/' 2>/dev/null`
428 if [ -n "$VMS" ]; then
429 if [ "$SHUTDOWN" = "poweroff" ]; then
430 begin_msg "Powering off remaining VMs"
431 for v in $VMS; do
432 $VBOXMANAGE --nologo controlvm $v poweroff
433 done
434 succ_msg "Remaining VMs powered off"
435 elif [ "$SHUTDOWN" = "acpibutton" ]; then
436 begin_msg "Sending ACPI power button event to remaining VMs"
437 for v in $VMS; do
438 $VBOXMANAGE --nologo controlvm $v acpipowerbutton
439 wait=30
440 done
441 succ_msg "ACPI power button event sent to remaining VMs"
442 elif [ "$SHUTDOWN" = "savestate" ]; then
443 begin_msg "Saving state of remaining VMs"
444 for v in $VMS; do
445 $VBOXMANAGE --nologo controlvm $v savestate
446 done
447 succ_msg "State of remaining VMs saved"
448 fi
449 fi
450 fi
451 done
452 # wait for some seconds when doing ACPI shutdown
453 if [ "$wait" -ne 0 ]; then
454 begin_msg "Waiting for $wait seconds for VM shutdown"
455 sleep $wait
456 succ_msg "Waited for $wait seconds for VM shutdown"
457 fi
458}
459
460cleanup()
461{
462 # If this is set, only remove kernel modules for no longer installed
463 # kernels. Note that only generated kernel modules should be placed
464 # in /lib/modules/*/misc. Anything that we should not remove automatically
465 # should go elsewhere.
466 only_old="${1}"
467 for i in /lib/modules/*; do
468 # Check whether we are only cleaning up for uninstalled kernels.
469 test -n "${only_old}" && test -e "${i}/kernel/drivers" && continue
470 # We could just do "rm -f", but we only want to try deleting folders if
471 # we are sure they were ours, i.e. they had our modules in beforehand.
472 if test -e "${i}/misc/vboxdrv.ko" \
473 || test -e "${i}/misc/vboxnetadp.ko" \
474 || test -e "${i}/misc/vboxnetflt.ko" \
475 || test -e "${i}/misc/vboxpci.ko"; then
476 rm -f "${i}/misc/vboxdrv.ko" "${i}/misc/vboxnetadp.ko" \
477 "${i}/misc/vboxnetflt.ko" "${i}/misc/vboxpci.ko"
478 version=`expr "${i}" : "/lib/modules/\(.*\)"`
479 depmod -a "${version}"
480 sync
481 fi
482 # Remove the kernel version folder if it was empty except for us.
483 test "`echo ${i}/misc/* ${i}/misc/.?* ${i}/* ${i}/.?*`" \
484 = "${i}/misc/* ${i}/misc/.. ${i}/misc ${i}/.." &&
485 rmdir "${i}/misc" "${i}" # We used to leave empty folders.
486 done
487}
488
489# setup_script
490setup()
491{
492 begin_msg "Building VirtualBox kernel modules" console
493 log "Building the main VirtualBox module."
494 if ! myerr=`$BUILDINTMP \
495 --save-module-symvers /tmp/vboxdrv-Module.symvers \
496 --module-source "$MODULE_SRC/vboxdrv" \
497 --no-print-directory install 2>&1`; then
498 "${INSTALL_DIR}/check_module_dependencies.sh" || exit 1
499 log "Error building the module:"
500 module_build_log "$myerr"
501 failure "Look at $LOG to find out what went wrong"
502 fi
503 log "Building the net filter module."
504 if ! myerr=`$BUILDINTMP \
505 --use-module-symvers /tmp/vboxdrv-Module.symvers \
506 --module-source "$MODULE_SRC/vboxnetflt" \
507 --no-print-directory install 2>&1`; then
508 log "Error building the module:"
509 module_build_log "$myerr"
510 failure "Look at $LOG to find out what went wrong"
511 fi
512 log "Building the net adaptor module."
513 if ! myerr=`$BUILDINTMP \
514 --use-module-symvers /tmp/vboxdrv-Module.symvers \
515 --module-source "$MODULE_SRC/vboxnetadp" \
516 --no-print-directory install 2>&1`; then
517 log "Error building the module:"
518 module_build_log "$myerr"
519 failure "Look at $LOG to find out what went wrong"
520 fi
521 if test -e "$MODULE_SRC/vboxpci"; then
522 log "Building the PCI pass-through module."
523 if ! myerr=`$BUILDINTMP \
524 --use-module-symvers /tmp/vboxdrv-Module.symvers \
525 --module-source "$MODULE_SRC/vboxpci" \
526 --no-print-directory install 2>&1`; then
527 log "Error building the module:"
528 module_build_log "$myerr"
529 failure "Look at $LOG to find out what went wrong"
530 fi
531 fi
532 rm -f /etc/vbox/module_not_compiled
533 depmod -a
534 sync
535 succ_msg "VirtualBox kernel modules built"
536 # Secure boot on Ubuntu and Debian.
537 if test -n "$HAVE_SEC_BOOT" &&
538 type update-secureboot-policy >/dev/null 2>&1; then
539 SHIM_NOTRIGGER=y update-secureboot-policy --new-key
540 fi
541 if test -f "$DEB_PUB_KEY" && test -f "$DEB_PRIV_KEY"; then
542 HAVE_DEB_KEY=true
543 for i in $MODULE_LIST; do
544 kmodsign sha512 /var/lib/shim-signed/mok/MOK.priv \
545 /var/lib/shim-signed/mok/MOK.der \
546 /lib/modules/"$KERN_VER"/misc/"$i".ko
547 done
548 # update-secureboot-policy "expects" DKMS modules.
549 # Work around this and talk to the authors as soon
550 # as possible to fix it.
551 mkdir -p /var/lib/dkms/vbox-temp
552 update-secureboot-policy --enroll-key 2>/dev/null ||
553 begin_msg "Failed to enroll secure boot key." console
554 rmdir -p /var/lib/dkms/vbox-temp 2>/dev/null
555 fi
556}
557
558dmnstatus()
559{
560 if running vboxdrv; then
561 str="vboxdrv"
562 if running vboxnetflt; then
563 str="$str, vboxnetflt"
564 if running vboxnetadp; then
565 str="$str, vboxnetadp"
566 fi
567 fi
568 if running vboxpci; then
569 str="$str, vboxpci"
570 fi
571 echo "VirtualBox kernel modules ($str) are loaded."
572 for i in $SHUTDOWN_USERS; do
573 # don't create the ipcd directory with wrong permissions!
574 if [ -d /tmp/.vbox-$i-ipc ]; then
575 export VBOX_IPC_SOCKETID="$i"
576 VMS=`$VBOXMANAGE --nologo list runningvms | sed -e 's/^".*".*{\(.*\)}/\1/' 2>/dev/null`
577 if [ -n "$VMS" ]; then
578 echo "The following VMs are currently running:"
579 for v in $VMS; do
580 echo " $v"
581 done
582 fi
583 fi
584 done
585 else
586 echo "VirtualBox kernel module is not loaded."
587 fi
588}
589
590case "$1" in
591start)
592 start
593 ;;
594stop)
595 stop_vms
596 stop
597 ;;
598stop_vms)
599 stop_vms
600 ;;
601restart)
602 stop && start
603 ;;
604setup)
605 test -n "${2}" && export KERN_VER="${2}"
606 # Create udev rule and USB device nodes.
607 ## todo Wouldn't it make more sense to install the rule to /lib/udev? This
608 ## is not a user-created configuration file after all.
609 ## todo Do we need a udev rule to create /dev/vboxdrv[u] at all? We have
610 ## working fall-back code here anyway, and the "right" code is more complex
611 ## than the fall-back. Unnecessary duplication?
612 stop && cleanup
613 setup_usb "$GROUP" "$DEVICE_MODE" "$INSTALL_DIR"
614 start
615 ;;
616cleanup)
617 stop && cleanup
618 cleanup_usb
619 ;;
620force-reload)
621 stop
622 start
623 ;;
624status)
625 dmnstatus
626 ;;
627*)
628 echo "Usage: $0 {start|stop|stop_vms|restart|setup|cleanup|force-reload|status}"
629 exit 1
630esac
631
632exit 0
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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