VirtualBox

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

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

scm copyright and license note update

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

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