VirtualBox

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

Last change on this file since 89164 was 89164, checked in by vboxsync, 4 years ago

Installer: Linux: reverted r144498, r144499, r144501: temporary diagnostic logging.

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 21.6 KB
Line 
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.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: 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
308# Check if required modules are installed in the system and versions match.
309setup_complete()
310{
311 [ "$(module_available vboxdrv)" = "1" ] || return
312 [ "$(module_available vboxnetflt)" = "1" ] || return
313 [ "$(module_available vboxnetadp)" = "1" ] || return
314
315 # All modules are in place.
316 echo "1"
317}
318
319start()
320{
321 begin_msg "Starting VirtualBox services" console
322 if [ -d /proc/xen ]; then
323 failure "Running VirtualBox in a Xen environment is not supported"
324 fi
325 if test -n "$HAVE_SEC_BOOT" && test -z "$DEB_KEY_ENROLLED"; then
326 if test -n "$HAVE_DEB_KEY"; then
327 begin_msg "You must re-start your system to finish Debian secure boot set-up." console
328 else
329 begin_msg "You must sign these kernel modules before using VirtualBox:
330 $MODULE_LIST
331See the documenatation for your Linux distribution." console
332 fi
333 fi
334
335 # Check if system already has matching modules installed.
336 [ "$(setup_complete)" = "1" ] || setup
337
338 if ! running vboxdrv; then
339 if ! rm -f $DEVICE; then
340 failure "Cannot remove $DEVICE"
341 fi
342 if ! $MODPROBE vboxdrv > /dev/null 2>&1; then
343 failure "modprobe vboxdrv failed. Please use 'dmesg' to find out why"
344 fi
345 sleep .2
346 fi
347 # ensure the character special exists
348 if [ ! -c $DEVICE ]; then
349 MAJOR=`sed -n 's;\([0-9]\+\) vboxdrv$;\1;p' /proc/devices`
350 if [ ! -z "$MAJOR" ]; then
351 MINOR=0
352 else
353 MINOR=`sed -n 's;\([0-9]\+\) vboxdrv$;\1;p' /proc/misc`
354 if [ ! -z "$MINOR" ]; then
355 MAJOR=10
356 fi
357 fi
358 if [ -z "$MAJOR" ]; then
359 rmmod vboxdrv 2>/dev/null
360 failure "Cannot locate the VirtualBox device"
361 fi
362 if ! mknod -m 0660 $DEVICE c $MAJOR $MINOR 2>/dev/null; then
363 rmmod vboxdrv 2>/dev/null
364 failure "Cannot create device $DEVICE with major $MAJOR and minor $MINOR"
365 fi
366 fi
367 # ensure permissions
368 if ! chown :"${GROUP}" $DEVICE 2>/dev/null; then
369 rmmod vboxpci 2>/dev/null
370 rmmod vboxnetadp 2>/dev/null
371 rmmod vboxnetflt 2>/dev/null
372 rmmod vboxdrv 2>/dev/null
373 failure "Cannot change group ${GROUP} for device $DEVICE"
374 fi
375 if ! $MODPROBE vboxnetflt > /dev/null 2>&1; then
376 failure "modprobe vboxnetflt failed. Please use 'dmesg' to find out why"
377 fi
378 if ! $MODPROBE vboxnetadp > /dev/null 2>&1; then
379 failure "modprobe vboxnetadp failed. Please use 'dmesg' to find out why"
380 fi
381 if test -e "${MODULE_SRC}/vboxpci" && ! $MODPROBE vboxpci > /dev/null 2>&1; then
382 failure "modprobe vboxpci failed. Please use 'dmesg' to find out why"
383 fi
384 # Create the /dev/vboxusb directory if the host supports that method
385 # of USB access. The USB code checks for the existance of that path.
386 if grep -q usb_device /proc/devices; then
387 mkdir -p -m 0750 /dev/vboxusb 2>/dev/null
388 chown root:vboxusers /dev/vboxusb 2>/dev/null
389 fi
390 # Remove any kernel modules left over from previously installed kernels.
391 cleanup only_old
392 succ_msg "VirtualBox services started"
393}
394
395stop()
396{
397 begin_msg "Stopping VirtualBox services" console
398
399 if running vboxpci; then
400 if ! rmmod vboxpci 2>/dev/null; then
401 failure "Cannot unload module vboxpci"
402 fi
403 fi
404 if running vboxnetadp; then
405 if ! rmmod vboxnetadp 2>/dev/null; then
406 failure "Cannot unload module vboxnetadp"
407 fi
408 fi
409 if running vboxdrv; then
410 if running vboxnetflt; then
411 if ! rmmod vboxnetflt 2>/dev/null; then
412 failure "Cannot unload module vboxnetflt"
413 fi
414 fi
415 if ! rmmod vboxdrv 2>/dev/null; then
416 failure "Cannot unload module vboxdrv"
417 fi
418 if ! rm -f $DEVICE; then
419 failure "Cannot unlink $DEVICE"
420 fi
421 fi
422 succ_msg "VirtualBox services stopped"
423}
424
425# enter the following variables in /etc/default/virtualbox:
426# SHUTDOWN_USERS="foo bar"
427# check for running VMs of user foo and user bar
428# SHUTDOWN=poweroff
429# SHUTDOWN=acpibutton
430# SHUTDOWN=savestate
431# select one of these shutdown methods for running VMs
432stop_vms()
433{
434 wait=0
435 for i in $SHUTDOWN_USERS; do
436 # don't create the ipcd directory with wrong permissions!
437 if [ -d /tmp/.vbox-$i-ipc ]; then
438 export VBOX_IPC_SOCKETID="$i"
439 VMS=`$VBOXMANAGE --nologo list runningvms | sed -e 's/^".*".*{\(.*\)}/\1/' 2>/dev/null`
440 if [ -n "$VMS" ]; then
441 if [ "$SHUTDOWN" = "poweroff" ]; then
442 begin_msg "Powering off remaining VMs"
443 for v in $VMS; do
444 $VBOXMANAGE --nologo controlvm $v poweroff
445 done
446 succ_msg "Remaining VMs powered off"
447 elif [ "$SHUTDOWN" = "acpibutton" ]; then
448 begin_msg "Sending ACPI power button event to remaining VMs"
449 for v in $VMS; do
450 $VBOXMANAGE --nologo controlvm $v acpipowerbutton
451 wait=30
452 done
453 succ_msg "ACPI power button event sent to remaining VMs"
454 elif [ "$SHUTDOWN" = "savestate" ]; then
455 begin_msg "Saving state of remaining VMs"
456 for v in $VMS; do
457 $VBOXMANAGE --nologo controlvm $v savestate
458 done
459 succ_msg "State of remaining VMs saved"
460 fi
461 fi
462 fi
463 done
464 # wait for some seconds when doing ACPI shutdown
465 if [ "$wait" -ne 0 ]; then
466 begin_msg "Waiting for $wait seconds for VM shutdown"
467 sleep $wait
468 succ_msg "Waited for $wait seconds for VM shutdown"
469 fi
470}
471
472cleanup()
473{
474 # If this is set, only remove kernel modules for no longer installed
475 # kernels. Note that only generated kernel modules should be placed
476 # in /lib/modules/*/misc. Anything that we should not remove automatically
477 # should go elsewhere.
478 only_old="${1}"
479 for i in /lib/modules/*; do
480 # Check whether we are only cleaning up for uninstalled kernels.
481 test -n "${only_old}" && test -e "${i}/kernel/drivers" && continue
482 # We could just do "rm -f", but we only want to try deleting folders if
483 # we are sure they were ours, i.e. they had our modules in beforehand.
484 if test -e "${i}/misc/vboxdrv.ko" \
485 || test -e "${i}/misc/vboxnetadp.ko" \
486 || test -e "${i}/misc/vboxnetflt.ko" \
487 || test -e "${i}/misc/vboxpci.ko"; then
488 rm -f "${i}/misc/vboxdrv.ko" "${i}/misc/vboxnetadp.ko" \
489 "${i}/misc/vboxnetflt.ko" "${i}/misc/vboxpci.ko"
490 version=`expr "${i}" : "/lib/modules/\(.*\)"`
491 depmod -a "${version}"
492 sync
493 fi
494 # Remove the kernel version folder if it was empty except for us.
495 test "`echo ${i}/misc/* ${i}/misc/.?* ${i}/* ${i}/.?*`" \
496 = "${i}/misc/* ${i}/misc/.. ${i}/misc ${i}/.." &&
497 rmdir "${i}/misc" "${i}" # We used to leave empty folders.
498 done
499}
500
501# setup_script
502setup()
503{
504 begin_msg "Building VirtualBox kernel modules" console
505 log "Building the main VirtualBox module."
506 if ! myerr=`$BUILDINTMP \
507 --save-module-symvers /tmp/vboxdrv-Module.symvers \
508 --module-source "$MODULE_SRC/vboxdrv" \
509 --no-print-directory install 2>&1`; then
510 "${INSTALL_DIR}/check_module_dependencies.sh" || exit 1
511 log "Error building the module:"
512 module_build_log "$myerr"
513 failure "Look at $LOG to find out what went wrong"
514 fi
515 log "Building the net filter module."
516 if ! myerr=`$BUILDINTMP \
517 --use-module-symvers /tmp/vboxdrv-Module.symvers \
518 --module-source "$MODULE_SRC/vboxnetflt" \
519 --no-print-directory install 2>&1`; then
520 log "Error building the module:"
521 module_build_log "$myerr"
522 failure "Look at $LOG to find out what went wrong"
523 fi
524 log "Building the net adaptor module."
525 if ! myerr=`$BUILDINTMP \
526 --use-module-symvers /tmp/vboxdrv-Module.symvers \
527 --module-source "$MODULE_SRC/vboxnetadp" \
528 --no-print-directory install 2>&1`; then
529 log "Error building the module:"
530 module_build_log "$myerr"
531 failure "Look at $LOG to find out what went wrong"
532 fi
533 if test -e "$MODULE_SRC/vboxpci"; then
534 log "Building the PCI pass-through module."
535 if ! myerr=`$BUILDINTMP \
536 --use-module-symvers /tmp/vboxdrv-Module.symvers \
537 --module-source "$MODULE_SRC/vboxpci" \
538 --no-print-directory install 2>&1`; then
539 log "Error building the module:"
540 module_build_log "$myerr"
541 failure "Look at $LOG to find out what went wrong"
542 fi
543 fi
544 rm -f /etc/vbox/module_not_compiled
545 depmod -a
546 sync
547 succ_msg "VirtualBox kernel modules built"
548 # Secure boot on Ubuntu and Debian.
549 if test -n "$HAVE_SEC_BOOT" &&
550 type update-secureboot-policy >/dev/null 2>&1; then
551 SHIM_NOTRIGGER=y update-secureboot-policy --new-key
552 fi
553 if test -f "$DEB_PUB_KEY" && test -f "$DEB_PRIV_KEY"; then
554 HAVE_DEB_KEY=true
555 for i in $MODULE_LIST; do
556 kmodsign sha512 /var/lib/shim-signed/mok/MOK.priv \
557 /var/lib/shim-signed/mok/MOK.der \
558 /lib/modules/"$KERN_VER"/misc/"$i".ko
559 done
560 # update-secureboot-policy "expects" DKMS modules.
561 # Work around this and talk to the authors as soon
562 # as possible to fix it.
563 mkdir -p /var/lib/dkms/vbox-temp
564 update-secureboot-policy --enroll-key 2>/dev/null ||
565 begin_msg "Failed to enroll secure boot key." console
566 rmdir -p /var/lib/dkms/vbox-temp 2>/dev/null
567 fi
568}
569
570dmnstatus()
571{
572 if running vboxdrv; then
573 str="vboxdrv"
574 if running vboxnetflt; then
575 str="$str, vboxnetflt"
576 if running vboxnetadp; then
577 str="$str, vboxnetadp"
578 fi
579 fi
580 if running vboxpci; then
581 str="$str, vboxpci"
582 fi
583 echo "VirtualBox kernel modules ($str) are loaded."
584 for i in $SHUTDOWN_USERS; do
585 # don't create the ipcd directory with wrong permissions!
586 if [ -d /tmp/.vbox-$i-ipc ]; then
587 export VBOX_IPC_SOCKETID="$i"
588 VMS=`$VBOXMANAGE --nologo list runningvms | sed -e 's/^".*".*{\(.*\)}/\1/' 2>/dev/null`
589 if [ -n "$VMS" ]; then
590 echo "The following VMs are currently running:"
591 for v in $VMS; do
592 echo " $v"
593 done
594 fi
595 fi
596 done
597 else
598 echo "VirtualBox kernel module is not loaded."
599 fi
600}
601
602case "$1" in
603start)
604 start
605 ;;
606stop)
607 stop_vms
608 stop
609 ;;
610stop_vms)
611 stop_vms
612 ;;
613restart)
614 stop && start
615 ;;
616setup)
617 test -n "${2}" && export KERN_VER="${2}"
618 # Create udev rule and USB device nodes.
619 ## todo Wouldn't it make more sense to install the rule to /lib/udev? This
620 ## is not a user-created configuration file after all.
621 ## todo Do we need a udev rule to create /dev/vboxdrv[u] at all? We have
622 ## working fall-back code here anyway, and the "right" code is more complex
623 ## than the fall-back. Unnecessary duplication?
624 stop && cleanup
625 setup_usb "$GROUP" "$DEVICE_MODE" "$INSTALL_DIR"
626 start
627 ;;
628cleanup)
629 stop && cleanup
630 cleanup_usb
631 ;;
632force-reload)
633 stop
634 start
635 ;;
636status)
637 dmnstatus
638 ;;
639*)
640 echo "Usage: $0 {start|stop|stop_vms|restart|setup|cleanup|force-reload|status}"
641 exit 1
642esac
643
644exit 0
Note: See TracBrowser for help on using the repository browser.

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