VirtualBox

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

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

Installer: Linux: Temporary add diagnostic logging to vboxdrv.sh (2) (to be reverted).

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 21.8 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)"
162echo diagnostics: cut: $(which cut) $([ -x $(which cut) ] && echo 1)
163echo diagnostics: VBOXMANAGE: $VBOXMANAGE $([ -x "$VBOXMANAGE" ] && echo 1)
164echo diagnostics: VBOX_VERSION = .$VBOX_VERSION.
165echo diagnostics: VBOX_REVISION = .$VBOX_REVISION.
166if test -z "$VBOX_VERSION" -o "$VBOX_REVISION" = "r"; then
167 failure 'Cannot detect VirtualBox version'
168fi
169
170## Output the vboxdrv part of our udev rule. This is redirected to the right file.
171udev_write_vboxdrv() {
172 VBOXDRV_GRP="$1"
173 VBOXDRV_MODE="$2"
174
175 echo "KERNEL==\"vboxdrv\", NAME=\"vboxdrv\", OWNER=\"root\", GROUP=\"$VBOXDRV_GRP\", MODE=\"$VBOXDRV_MODE\""
176 echo "KERNEL==\"vboxdrvu\", NAME=\"vboxdrvu\", OWNER=\"root\", GROUP=\"root\", MODE=\"0666\""
177 echo "KERNEL==\"vboxnetctl\", NAME=\"vboxnetctl\", OWNER=\"root\", GROUP=\"$VBOXDRV_GRP\", MODE=\"$VBOXDRV_MODE\""
178}
179
180## Output the USB part of our udev rule. This is redirected to the right file.
181udev_write_usb() {
182 INSTALLATION_DIR="$1"
183 USB_GROUP="$2"
184
185 echo "SUBSYSTEM==\"usb_device\", ACTION==\"add\", RUN+=\"$INSTALLATION_DIR/VBoxCreateUSBNode.sh \$major \$minor \$attr{bDeviceClass}${USB_GROUP}\""
186 echo "SUBSYSTEM==\"usb\", ACTION==\"add\", ENV{DEVTYPE}==\"usb_device\", RUN+=\"$INSTALLATION_DIR/VBoxCreateUSBNode.sh \$major \$minor \$attr{bDeviceClass}${USB_GROUP}\""
187 echo "SUBSYSTEM==\"usb_device\", ACTION==\"remove\", RUN+=\"$INSTALLATION_DIR/VBoxCreateUSBNode.sh --remove \$major \$minor\""
188 echo "SUBSYSTEM==\"usb\", ACTION==\"remove\", ENV{DEVTYPE}==\"usb_device\", RUN+=\"$INSTALLATION_DIR/VBoxCreateUSBNode.sh --remove \$major \$minor\""
189}
190
191## Generate our udev rule file. This takes a change in udev rule syntax in
192## version 55 into account. It only creates rules for USB for udev versions
193## recent enough to support USB device nodes.
194generate_udev_rule() {
195 VBOXDRV_GRP="$1" # The group owning the vboxdrv device
196 VBOXDRV_MODE="$2" # The access mode for the vboxdrv device
197 INSTALLATION_DIR="$3" # The directory VirtualBox is installed in
198 USB_GROUP="$4" # The group that has permission to access USB devices
199 NO_INSTALL="$5" # Set this to "1" to remove but not re-install rules
200
201 # Extra space!
202 case "$USB_GROUP" in ?*) USB_GROUP=" $USB_GROUP" ;; esac
203 case "$NO_INSTALL" in "1") return ;; esac
204 udev_write_vboxdrv "$VBOXDRV_GRP" "$VBOXDRV_MODE"
205 udev_write_usb "$INSTALLATION_DIR" "$USB_GROUP"
206}
207
208## Install udev rule (disable with INSTALL_NO_UDEV=1 in
209## /etc/default/virtualbox).
210install_udev() {
211 VBOXDRV_GRP="$1" # The group owning the vboxdrv device
212 VBOXDRV_MODE="$2" # The access mode for the vboxdrv device
213 INSTALLATION_DIR="$3" # The directory VirtualBox is installed in
214 USB_GROUP="$4" # The group that has permission to access USB devices
215 NO_INSTALL="$5" # Set this to "1" to remove but not re-install rules
216
217 if test -d /etc/udev/rules.d; then
218 generate_udev_rule "$VBOXDRV_GRP" "$VBOXDRV_MODE" "$INSTALLATION_DIR" \
219 "$USB_GROUP" "$NO_INSTALL"
220 fi
221 # Remove old udev description file
222 rm -f /etc/udev/rules.d/10-vboxdrv.rules 2> /dev/null
223}
224
225## Create a usb device node for a given sysfs path to a USB device.
226install_create_usb_node_for_sysfs() {
227 path="$1" # sysfs path for the device
228 usb_createnode="$2" # Path to the USB device node creation script
229 usb_group="$3" # The group to give ownership of the node to
230 if test -r "${path}/dev"; then
231 dev="`cat "${path}/dev" 2> /dev/null`"
232 major="`expr "$dev" : '\(.*\):' 2> /dev/null`"
233 minor="`expr "$dev" : '.*:\(.*\)' 2> /dev/null`"
234 class="`cat ${path}/bDeviceClass 2> /dev/null`"
235 sh "${usb_createnode}" "$major" "$minor" "$class" \
236 "${usb_group}" 2>/dev/null
237 fi
238}
239
240udev_rule_file=/etc/udev/rules.d/60-vboxdrv.rules
241sysfs_usb_devices="/sys/bus/usb/devices/*"
242
243## Install udev rules and create device nodes for usb access
244setup_usb() {
245 VBOXDRV_GRP="$1" # The group that should own /dev/vboxdrv
246 VBOXDRV_MODE="$2" # The mode to be used for /dev/vboxdrv
247 INSTALLATION_DIR="$3" # The directory VirtualBox is installed in
248 USB_GROUP="$4" # The group that should own the /dev/vboxusb device
249 # nodes unless INSTALL_NO_GROUP=1 in
250 # /etc/default/virtualbox. Optional.
251 usb_createnode="$INSTALLATION_DIR/VBoxCreateUSBNode.sh"
252 # install udev rule (disable with INSTALL_NO_UDEV=1 in
253 # /etc/default/virtualbox)
254 if [ "$INSTALL_NO_GROUP" != "1" ]; then
255 usb_group=$USB_GROUP
256 vboxdrv_group=$VBOXDRV_GRP
257 else
258 usb_group=root
259 vboxdrv_group=root
260 fi
261 install_udev "${vboxdrv_group}" "$VBOXDRV_MODE" \
262 "$INSTALLATION_DIR" "${usb_group}" \
263 "$INSTALL_NO_UDEV" > ${udev_rule_file}
264 # Build our device tree
265 for i in ${sysfs_usb_devices}; do # This line intentionally without quotes.
266 install_create_usb_node_for_sysfs "$i" "${usb_createnode}" \
267 "${usb_group}"
268 done
269}
270
271cleanup_usb()
272{
273 # Remove udev description file
274 rm -f /etc/udev/rules.d/60-vboxdrv.rules
275 rm -f /etc/udev/rules.d/10-vboxdrv.rules
276
277 # Remove our USB device tree
278 rm -rf /dev/vboxusb
279}
280
281# Returns module version if module is available or empty string.
282module_version()
283{
284 mod="$1"
285 [ -n "$mod" ] || return
286
287 modinfo "$mod" 2>/dev/null | grep -e "^version:" | tr -s ' ' | cut -d " " -f2
288}
289
290# Returns module revision if module is available in the system or empty string.
291module_revision()
292{
293 mod="$1"
294 [ -n "$mod" ] || return
295
296 modinfo "$mod" 2>/dev/null | grep -e "^version:" | tr -s ' ' | cut -d " " -f3
297}
298
299# Returns "1" if module is available in the system and its version and revision
300# number do match to current VirtualBox installation. Or empty string otherwise.
301module_available()
302{
303 mod="$1"
304 [ -n "$mod" ] || return
305
306 [ "$VBOX_VERSION" = "$(module_version $mod)" ] || return
307 [ "$VBOX_REVISION" = "$(module_revision $mod)" ] || return
308
309 echo "1"
310}
311
312# Check if required modules are installed in the system and versions match.
313setup_complete()
314{
315 [ "$(module_available vboxdrv)" = "1" ] || return
316 [ "$(module_available vboxnetflt)" = "1" ] || return
317 [ "$(module_available vboxnetadp)" = "1" ] || return
318
319 # All modules are in place.
320 echo "1"
321}
322
323start()
324{
325 begin_msg "Starting VirtualBox services" console
326 if [ -d /proc/xen ]; then
327 failure "Running VirtualBox in a Xen environment is not supported"
328 fi
329 if test -n "$HAVE_SEC_BOOT" && test -z "$DEB_KEY_ENROLLED"; then
330 if test -n "$HAVE_DEB_KEY"; then
331 begin_msg "You must re-start your system to finish Debian secure boot set-up." console
332 else
333 begin_msg "You must sign these kernel modules before using VirtualBox:
334 $MODULE_LIST
335See the documenatation for your Linux distribution." console
336 fi
337 fi
338
339 # Check if system already has matching modules installed.
340 [ "$(setup_complete)" = "1" ] || setup
341
342 if ! running vboxdrv; then
343 if ! rm -f $DEVICE; then
344 failure "Cannot remove $DEVICE"
345 fi
346 if ! $MODPROBE vboxdrv > /dev/null 2>&1; then
347 failure "modprobe vboxdrv failed. Please use 'dmesg' to find out why"
348 fi
349 sleep .2
350 fi
351 # ensure the character special exists
352 if [ ! -c $DEVICE ]; then
353 MAJOR=`sed -n 's;\([0-9]\+\) vboxdrv$;\1;p' /proc/devices`
354 if [ ! -z "$MAJOR" ]; then
355 MINOR=0
356 else
357 MINOR=`sed -n 's;\([0-9]\+\) vboxdrv$;\1;p' /proc/misc`
358 if [ ! -z "$MINOR" ]; then
359 MAJOR=10
360 fi
361 fi
362 if [ -z "$MAJOR" ]; then
363 rmmod vboxdrv 2>/dev/null
364 failure "Cannot locate the VirtualBox device"
365 fi
366 if ! mknod -m 0660 $DEVICE c $MAJOR $MINOR 2>/dev/null; then
367 rmmod vboxdrv 2>/dev/null
368 failure "Cannot create device $DEVICE with major $MAJOR and minor $MINOR"
369 fi
370 fi
371 # ensure permissions
372 if ! chown :"${GROUP}" $DEVICE 2>/dev/null; then
373 rmmod vboxpci 2>/dev/null
374 rmmod vboxnetadp 2>/dev/null
375 rmmod vboxnetflt 2>/dev/null
376 rmmod vboxdrv 2>/dev/null
377 failure "Cannot change group ${GROUP} for device $DEVICE"
378 fi
379 if ! $MODPROBE vboxnetflt > /dev/null 2>&1; then
380 failure "modprobe vboxnetflt failed. Please use 'dmesg' to find out why"
381 fi
382 if ! $MODPROBE vboxnetadp > /dev/null 2>&1; then
383 failure "modprobe vboxnetadp failed. Please use 'dmesg' to find out why"
384 fi
385 if test -e "${MODULE_SRC}/vboxpci" && ! $MODPROBE vboxpci > /dev/null 2>&1; then
386 failure "modprobe vboxpci failed. Please use 'dmesg' to find out why"
387 fi
388 # Create the /dev/vboxusb directory if the host supports that method
389 # of USB access. The USB code checks for the existance of that path.
390 if grep -q usb_device /proc/devices; then
391 mkdir -p -m 0750 /dev/vboxusb 2>/dev/null
392 chown root:vboxusers /dev/vboxusb 2>/dev/null
393 fi
394 # Remove any kernel modules left over from previously installed kernels.
395 cleanup only_old
396 succ_msg "VirtualBox services started"
397}
398
399stop()
400{
401 begin_msg "Stopping VirtualBox services" console
402
403 if running vboxpci; then
404 if ! rmmod vboxpci 2>/dev/null; then
405 failure "Cannot unload module vboxpci"
406 fi
407 fi
408 if running vboxnetadp; then
409 if ! rmmod vboxnetadp 2>/dev/null; then
410 failure "Cannot unload module vboxnetadp"
411 fi
412 fi
413 if running vboxdrv; then
414 if running vboxnetflt; then
415 if ! rmmod vboxnetflt 2>/dev/null; then
416 failure "Cannot unload module vboxnetflt"
417 fi
418 fi
419 if ! rmmod vboxdrv 2>/dev/null; then
420 failure "Cannot unload module vboxdrv"
421 fi
422 if ! rm -f $DEVICE; then
423 failure "Cannot unlink $DEVICE"
424 fi
425 fi
426 succ_msg "VirtualBox services stopped"
427}
428
429# enter the following variables in /etc/default/virtualbox:
430# SHUTDOWN_USERS="foo bar"
431# check for running VMs of user foo and user bar
432# SHUTDOWN=poweroff
433# SHUTDOWN=acpibutton
434# SHUTDOWN=savestate
435# select one of these shutdown methods for running VMs
436stop_vms()
437{
438 wait=0
439 for i in $SHUTDOWN_USERS; do
440 # don't create the ipcd directory with wrong permissions!
441 if [ -d /tmp/.vbox-$i-ipc ]; then
442 export VBOX_IPC_SOCKETID="$i"
443 VMS=`$VBOXMANAGE --nologo list runningvms | sed -e 's/^".*".*{\(.*\)}/\1/' 2>/dev/null`
444 if [ -n "$VMS" ]; then
445 if [ "$SHUTDOWN" = "poweroff" ]; then
446 begin_msg "Powering off remaining VMs"
447 for v in $VMS; do
448 $VBOXMANAGE --nologo controlvm $v poweroff
449 done
450 succ_msg "Remaining VMs powered off"
451 elif [ "$SHUTDOWN" = "acpibutton" ]; then
452 begin_msg "Sending ACPI power button event to remaining VMs"
453 for v in $VMS; do
454 $VBOXMANAGE --nologo controlvm $v acpipowerbutton
455 wait=30
456 done
457 succ_msg "ACPI power button event sent to remaining VMs"
458 elif [ "$SHUTDOWN" = "savestate" ]; then
459 begin_msg "Saving state of remaining VMs"
460 for v in $VMS; do
461 $VBOXMANAGE --nologo controlvm $v savestate
462 done
463 succ_msg "State of remaining VMs saved"
464 fi
465 fi
466 fi
467 done
468 # wait for some seconds when doing ACPI shutdown
469 if [ "$wait" -ne 0 ]; then
470 begin_msg "Waiting for $wait seconds for VM shutdown"
471 sleep $wait
472 succ_msg "Waited for $wait seconds for VM shutdown"
473 fi
474}
475
476cleanup()
477{
478 # If this is set, only remove kernel modules for no longer installed
479 # kernels. Note that only generated kernel modules should be placed
480 # in /lib/modules/*/misc. Anything that we should not remove automatically
481 # should go elsewhere.
482 only_old="${1}"
483 for i in /lib/modules/*; do
484 # Check whether we are only cleaning up for uninstalled kernels.
485 test -n "${only_old}" && test -e "${i}/kernel/drivers" && continue
486 # We could just do "rm -f", but we only want to try deleting folders if
487 # we are sure they were ours, i.e. they had our modules in beforehand.
488 if test -e "${i}/misc/vboxdrv.ko" \
489 || test -e "${i}/misc/vboxnetadp.ko" \
490 || test -e "${i}/misc/vboxnetflt.ko" \
491 || test -e "${i}/misc/vboxpci.ko"; then
492 rm -f "${i}/misc/vboxdrv.ko" "${i}/misc/vboxnetadp.ko" \
493 "${i}/misc/vboxnetflt.ko" "${i}/misc/vboxpci.ko"
494 version=`expr "${i}" : "/lib/modules/\(.*\)"`
495 depmod -a "${version}"
496 sync
497 fi
498 # Remove the kernel version folder if it was empty except for us.
499 test "`echo ${i}/misc/* ${i}/misc/.?* ${i}/* ${i}/.?*`" \
500 = "${i}/misc/* ${i}/misc/.. ${i}/misc ${i}/.." &&
501 rmdir "${i}/misc" "${i}" # We used to leave empty folders.
502 done
503}
504
505# setup_script
506setup()
507{
508 begin_msg "Building VirtualBox kernel modules" console
509 log "Building the main VirtualBox module."
510 if ! myerr=`$BUILDINTMP \
511 --save-module-symvers /tmp/vboxdrv-Module.symvers \
512 --module-source "$MODULE_SRC/vboxdrv" \
513 --no-print-directory install 2>&1`; then
514 "${INSTALL_DIR}/check_module_dependencies.sh" || exit 1
515 log "Error building the module:"
516 module_build_log "$myerr"
517 failure "Look at $LOG to find out what went wrong"
518 fi
519 log "Building the net filter module."
520 if ! myerr=`$BUILDINTMP \
521 --use-module-symvers /tmp/vboxdrv-Module.symvers \
522 --module-source "$MODULE_SRC/vboxnetflt" \
523 --no-print-directory install 2>&1`; then
524 log "Error building the module:"
525 module_build_log "$myerr"
526 failure "Look at $LOG to find out what went wrong"
527 fi
528 log "Building the net adaptor module."
529 if ! myerr=`$BUILDINTMP \
530 --use-module-symvers /tmp/vboxdrv-Module.symvers \
531 --module-source "$MODULE_SRC/vboxnetadp" \
532 --no-print-directory install 2>&1`; then
533 log "Error building the module:"
534 module_build_log "$myerr"
535 failure "Look at $LOG to find out what went wrong"
536 fi
537 if test -e "$MODULE_SRC/vboxpci"; then
538 log "Building the PCI pass-through module."
539 if ! myerr=`$BUILDINTMP \
540 --use-module-symvers /tmp/vboxdrv-Module.symvers \
541 --module-source "$MODULE_SRC/vboxpci" \
542 --no-print-directory install 2>&1`; then
543 log "Error building the module:"
544 module_build_log "$myerr"
545 failure "Look at $LOG to find out what went wrong"
546 fi
547 fi
548 rm -f /etc/vbox/module_not_compiled
549 depmod -a
550 sync
551 succ_msg "VirtualBox kernel modules built"
552 # Secure boot on Ubuntu and Debian.
553 if test -n "$HAVE_SEC_BOOT" &&
554 type update-secureboot-policy >/dev/null 2>&1; then
555 SHIM_NOTRIGGER=y update-secureboot-policy --new-key
556 fi
557 if test -f "$DEB_PUB_KEY" && test -f "$DEB_PRIV_KEY"; then
558 HAVE_DEB_KEY=true
559 for i in $MODULE_LIST; do
560 kmodsign sha512 /var/lib/shim-signed/mok/MOK.priv \
561 /var/lib/shim-signed/mok/MOK.der \
562 /lib/modules/"$KERN_VER"/misc/"$i".ko
563 done
564 # update-secureboot-policy "expects" DKMS modules.
565 # Work around this and talk to the authors as soon
566 # as possible to fix it.
567 mkdir -p /var/lib/dkms/vbox-temp
568 update-secureboot-policy --enroll-key 2>/dev/null ||
569 begin_msg "Failed to enroll secure boot key." console
570 rmdir -p /var/lib/dkms/vbox-temp 2>/dev/null
571 fi
572}
573
574dmnstatus()
575{
576 if running vboxdrv; then
577 str="vboxdrv"
578 if running vboxnetflt; then
579 str="$str, vboxnetflt"
580 if running vboxnetadp; then
581 str="$str, vboxnetadp"
582 fi
583 fi
584 if running vboxpci; then
585 str="$str, vboxpci"
586 fi
587 echo "VirtualBox kernel modules ($str) are loaded."
588 for i in $SHUTDOWN_USERS; do
589 # don't create the ipcd directory with wrong permissions!
590 if [ -d /tmp/.vbox-$i-ipc ]; then
591 export VBOX_IPC_SOCKETID="$i"
592 VMS=`$VBOXMANAGE --nologo list runningvms | sed -e 's/^".*".*{\(.*\)}/\1/' 2>/dev/null`
593 if [ -n "$VMS" ]; then
594 echo "The following VMs are currently running:"
595 for v in $VMS; do
596 echo " $v"
597 done
598 fi
599 fi
600 done
601 else
602 echo "VirtualBox kernel module is not loaded."
603 fi
604}
605
606case "$1" in
607start)
608 start
609 ;;
610stop)
611 stop_vms
612 stop
613 ;;
614stop_vms)
615 stop_vms
616 ;;
617restart)
618 stop && start
619 ;;
620setup)
621 test -n "${2}" && export KERN_VER="${2}"
622 # Create udev rule and USB device nodes.
623 ## todo Wouldn't it make more sense to install the rule to /lib/udev? This
624 ## is not a user-created configuration file after all.
625 ## todo Do we need a udev rule to create /dev/vboxdrv[u] at all? We have
626 ## working fall-back code here anyway, and the "right" code is more complex
627 ## than the fall-back. Unnecessary duplication?
628 stop && cleanup
629 setup_usb "$GROUP" "$DEVICE_MODE" "$INSTALL_DIR"
630 start
631 ;;
632cleanup)
633 stop && cleanup
634 cleanup_usb
635 ;;
636force-reload)
637 stop
638 start
639 ;;
640status)
641 dmnstatus
642 ;;
643*)
644 echo "Usage: $0 {start|stop|stop_vms|restart|setup|cleanup|force-reload|status}"
645 exit 1
646esac
647
648exit 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