VirtualBox

source: vbox/trunk/src/VBox/Additions/linux/installer/vboxadd.sh

Last change on this file was 109051, checked in by vboxsync, 10 days ago

Linux: Adjust startup scripts for building kernel modules for UEK8 on OL9 distribution, bugdbref:37834896.

  • Property svn:eol-style set to LF
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 43.8 KB
Line 
1#! /bin/sh
2# $Id: vboxadd.sh 109051 2025-04-22 10:49:38Z vboxsync $
3## @file
4# Linux Additions kernel module init script ($Revision: 109051 $)
5#
6
7#
8# Copyright (C) 2006-2024 Oracle and/or its affiliates.
9#
10# This file is part of VirtualBox base platform packages, as
11# available from https://www.virtualbox.org.
12#
13# This program is free software; you can redistribute it and/or
14# modify it under the terms of the GNU General Public License
15# as published by the Free Software Foundation, in version 3 of the
16# License.
17#
18# This program is distributed in the hope that it will be useful, but
19# WITHOUT ANY WARRANTY; without even the implied warranty of
20# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21# General Public License for more details.
22#
23# You should have received a copy of the GNU General Public License
24# along with this program; if not, see <https://www.gnu.org/licenses>.
25#
26# SPDX-License-Identifier: GPL-3.0-only
27#
28
29# X-Start-Before is a Debian Addition which we use when converting to
30# a systemd unit. X-Service-Type is our own invention, also for systemd.
31
32# chkconfig: 345 10 90
33# description: VirtualBox Linux Additions kernel modules
34#
35### BEGIN INIT INFO
36# Provides: vboxadd
37# Required-Start:
38# Required-Stop:
39# Default-Start: 2 3 4 5
40# Default-Stop: 0 1 6
41# X-Start-Before: display-manager
42# X-Service-Type: oneshot
43# Description: VirtualBox Linux Additions kernel modules
44### END INIT INFO
45
46## @todo This file duplicates a lot of script with vboxdrv.sh. When making
47# changes please try to reduce differences between the two wherever possible.
48
49# Testing:
50# * Should fail if the configuration file is missing or missing INSTALL_DIR or
51# INSTALL_VER entries.
52# * vboxadd, vboxsf and vboxdrmipc user groups should be created if they do not exist - test
53# by removing them before installing.
54# * Shared folders can be mounted and auto-mounts accessible to vboxsf group,
55# including on recent Fedoras with SELinux.
56# * Setting INSTALL_NO_MODULE_BUILDS inhibits modules and module automatic
57# rebuild script creation; otherwise modules, user, group, rebuild script,
58# udev rule and shared folder mount helper should be created/set up.
59# * Setting INSTALL_NO_MODULE_BUILDS inhibits module load and unload on start
60# and stop.
61# * Uninstalling the Additions and re-installing them does not trigger warnings.
62
63export LC_ALL=C
64PATH=$PATH:/bin:/sbin:/usr/sbin
65PACKAGE=VBoxGuestAdditions
66MODPROBE=/sbin/modprobe
67OLDMODULES="vboxguest vboxadd vboxsf vboxvfs vboxvideo"
68SERVICE="VirtualBox Guest Additions"
69VBOXSERVICE_PIDFILE="/var/run/vboxadd-service.sh"
70## systemd logs information about service status, otherwise do that ourselves.
71QUIET=
72test -z "${TARGET_VER}" && TARGET_VER=`uname -r`
73
74export VBOX_KBUILD_TYPE
75export USERNAME
76
77setup_log()
78{
79 test -z "${LOG}" || return 0
80 # Rotate log files
81 LOG="/var/log/vboxadd-setup.log"
82 mv -f "${LOG}.3" "${LOG}.4" 2>/dev/null
83 mv -f "${LOG}.2" "${LOG}.3" 2>/dev/null
84 mv -f "${LOG}.1" "${LOG}.2" 2>/dev/null
85 mv -f "${LOG}" "${LOG}.1" 2>/dev/null
86}
87
88if $MODPROBE -c 2>/dev/null | grep -q '^allow_unsupported_modules *0'; then
89 MODPROBE="$MODPROBE --allow-unsupported-modules"
90fi
91
92# Preamble for Gentoo
93if [ "`which $0`" = "/sbin/rc" ]; then
94 shift
95fi
96
97begin()
98{
99 test -n "${QUIET}" || echo "${SERVICE}: ${1}"
100}
101
102info()
103{
104 if test -z "${QUIET}"; then
105 echo "${SERVICE}: $1" | fold -s
106 else
107 echo "$1" | fold -s
108 fi
109}
110
111# When script is running as non-root, it does not have access to log
112# files in /var. In this case, lets print error message to stdout and
113# exit with bad status.
114early_fail()
115{
116 echo "$1" >&2
117 exit 1
118}
119
120fail()
121{
122 log "${1}"
123 echo "${SERVICE}: $1" >&2
124 echo "The log file $LOG may contain further information." >&2
125 exit 1
126}
127
128log()
129{
130 setup_log
131 echo "${1}" >> "${LOG}"
132}
133
134module_build_log()
135{
136 log "Error building the module. Build output follows."
137 echo ""
138 echo "${1}" >> "${LOG}"
139}
140
141dev=/dev/vboxguest
142userdev=/dev/vboxuser
143config=/var/lib/VBoxGuestAdditions/config
144user_config=/etc/virtualbox-guest-additions.conf
145owner=vboxadd
146group=1
147
148# Include custom user configuration file.
149[ -r "$user_config" ] && . "$user_config"
150
151if test -r $config; then
152 . $config
153else
154 fail "Configuration file $config not found"
155fi
156test -n "$INSTALL_DIR" -a -n "$INSTALL_VER" ||
157 fail "Configuration file $config not complete"
158MODULE_SRC="$INSTALL_DIR/src/vboxguest-$INSTALL_VER"
159BUILDINTMP="$MODULE_SRC/build_in_tmp"
160
161# Path to VBoxService control script.
162VBOX_SERVICE_SCRIPT="/sbin/rcvboxadd-service"
163
164# Attempt to detect VirtualBox Guest Additions version and revision information.
165VBOXCONTROL="${INSTALL_DIR}/bin/VBoxControl"
166VBOX_VERSION="`"$VBOXCONTROL" --version | cut -d r -f1`"
167[ -n "$VBOX_VERSION" ] || VBOX_VERSION='unknown'
168VBOX_REVISION="r`"$VBOXCONTROL" --version | cut -d r -f2`"
169[ "$VBOX_REVISION" != "r" ] || VBOX_REVISION='unknown'
170
171# Returns if a specific module is running or not.
172#
173# Input $1: Module name to check running status for.
174#
175# Returns true if the module is running, false if not.
176running_module()
177{
178 mod="$1"
179 [ -d "/sys/module/$mod" ]
180}
181
182# Returns the version string of a currently running kernel module.
183#
184# Input $1: Module name to check.
185#
186# Returns the module version string if found, or none if not found.
187running_module_version()
188{
189 mod="$1"
190 version_string_path="/sys/module/$mod/version"
191
192 [ -n "$mod" ] || return
193 if [ -r "$version_string_path" ]; then
194 cat "$version_string_path"
195 else
196 echo "unknown"
197 fi
198}
199
200# Checks if a loaded kernel module version matches to the currently installed Guest Additions version and revision.
201#
202# Input $1: Module name to check.
203#
204# Returns "1" if the module matches the installed Guest Additions, or none if not.
205check_running_module_version()
206{
207 mod=$1
208 expected="$VBOX_VERSION $VBOX_REVISION"
209
210 [ -n "$mod" ] || return
211 [ -n "$expected" ] || return
212
213 [ "$expected" = "$(running_module_version "$mod")" ] || return
214}
215
216do_vboxguest_non_udev()
217{
218 if [ ! -c $dev ]; then
219 maj=`sed -n 's;\([0-9]\+\) vboxguest;\1;p' /proc/devices`
220 if [ ! -z "$maj" ]; then
221 min=0
222 else
223 min=`sed -n 's;\([0-9]\+\) vboxguest;\1;p' /proc/misc`
224 if [ ! -z "$min" ]; then
225 maj=10
226 fi
227 fi
228 test -n "$maj" || {
229 rmmod vboxguest 2>/dev/null
230 fail "Cannot locate the VirtualBox device"
231 }
232
233 mknod -m 0664 $dev c $maj $min || {
234 rmmod vboxguest 2>/dev/null
235 fail "Cannot create device $dev with major $maj and minor $min"
236 }
237 fi
238 chown $owner:$group $dev 2>/dev/null || {
239 rm -f $dev 2>/dev/null
240 rm -f $userdev 2>/dev/null
241 rmmod vboxguest 2>/dev/null
242 fail "Cannot change owner $owner:$group for device $dev"
243 }
244
245 if [ ! -c $userdev ]; then
246 maj=10
247 min=`sed -n 's;\([0-9]\+\) vboxuser;\1;p' /proc/misc`
248 if [ ! -z "$min" ]; then
249 mknod -m 0666 $userdev c $maj $min || {
250 rm -f $dev 2>/dev/null
251 rmmod vboxguest 2>/dev/null
252 fail "Cannot create device $userdev with major $maj and minor $min"
253 }
254 chown $owner:$group $userdev 2>/dev/null || {
255 rm -f $dev 2>/dev/null
256 rm -f $userdev 2>/dev/null
257 rmmod vboxguest 2>/dev/null
258 fail "Cannot change owner $owner:$group for device $userdev"
259 }
260 fi
261 fi
262}
263
264restart()
265{
266 stop && start
267 return 0
268}
269
270## Updates the initramfs. Debian and Ubuntu put the graphics driver in, and
271# need the touch(1) command below. Everyone else that I checked just need
272# the right module alias file from depmod(1) and only use the initramfs to
273# load the root filesystem, not the boot splash. update-initramfs works
274# for the first two and dracut for every one else I checked. We are only
275# interested in distributions recent enough to use the KMS vboxvideo driver.
276update_initramfs()
277{
278 ## kernel version to update for.
279 version="${1}"
280 depmod "${version}"
281 rm -f "/lib/modules/${version}/initrd/vboxvideo"
282 test ! -d "/lib/modules/${version}/initrd" ||
283 test ! -f "/lib/modules/${version}/misc/vboxvideo.ko" ||
284 touch "/lib/modules/${version}/initrd/vboxvideo"
285
286 # Systems without systemd-inhibit probably don't need their initramfs
287 # rebuild here anyway.
288 type systemd-inhibit >/dev/null 2>&1 || return
289 if type dracut >/dev/null 2>&1; then
290 systemd-inhibit --why="Installing VirtualBox Guest Additions" \
291 dracut -f --kver "${version}"
292 elif type update-initramfs >/dev/null 2>&1; then
293 systemd-inhibit --why="Installing VirtualBox Guest Additions" \
294 update-initramfs -u -k "${version}"
295 fi
296}
297
298# Removes any existing VirtualBox guest kernel modules from the disk, but not
299# from the kernel as they may still be in use
300cleanup_modules()
301{
302 # Needed for Ubuntu and Debian, see update_initramfs
303 rm -f /lib/modules/*/initrd/vboxvideo
304 for i in /lib/modules/*/misc; do
305 KERN_VER="${i%/misc}"
306 KERN_VER="${KERN_VER#/lib/modules/}"
307 unset do_update
308 for j in ${OLDMODULES}; do
309 for mod_ext in ko ko.gz ko.xz ko.zst; do
310 test -f "${i}/${j}.${mod_ext}" && do_update=1 && rm -f "${i}/${j}.${mod_ext}"
311 done
312 done
313 test -z "$do_update" || update_initramfs "$KERN_VER"
314 # Remove empty /lib/modules folders which may have been kept around
315 rmdir -p "${i}" 2>/dev/null || true
316 unset keep
317 for j in /lib/modules/"${KERN_VER}"/*; do
318 name="${j##*/}"
319 test -d "${name}" || test "${name%%.*}" != modules && keep=1
320 done
321 if test -z "${keep}"; then
322 rm -rf /lib/modules/"${KERN_VER}"
323 rm -f /boot/initrd.img-"${KERN_VER}"
324 fi
325 done
326 for i in ${OLDMODULES}; do
327 # We no longer support DKMS, remove any leftovers.
328 rm -rf "/var/lib/dkms/${i}"*
329 done
330 rm -f /etc/depmod.d/vboxvideo-upstream.conf
331}
332
333# Secure boot state.
334case "`mokutil --sb-state 2>/dev/null`" in
335 *"disabled in shim"*) unset HAVE_SEC_BOOT;;
336 *"SecureBoot enabled"*) HAVE_SEC_BOOT=true;;
337 *) unset HAVE_SEC_BOOT;;
338esac
339# So far we can only sign modules on Ubuntu and on Debian 10 and later.
340DEB_PUB_KEY=/var/lib/shim-signed/mok/MOK.der
341DEB_PRIV_KEY=/var/lib/shim-signed/mok/MOK.priv
342# Check if key already enrolled.
343unset HAVE_DEB_KEY
344case "`mokutil --test-key "$DEB_PUB_KEY" 2>/dev/null`" in
345 *"is already"*) DEB_KEY_ENROLLED=true;;
346 *) unset DEB_KEY_ENROLLED;;
347esac
348
349# Checks if update-secureboot-policy tool supports required commandline options.
350update_secureboot_policy_supports()
351{
352 opt_name="$1"
353 [ -n "$opt_name" ] || return
354
355 [ -z "$(update-secureboot-policy --help 2>&1 | grep "$opt_name")" ] && return
356 echo "1"
357}
358
359HAVE_UPDATE_SECUREBOOT_POLICY_TOOL=
360if type update-secureboot-policy >/dev/null 2>&1; then
361 [ "$(update_secureboot_policy_supports new-key)" = "1" -a "$(update_secureboot_policy_supports enroll-key)" = "1" ] && \
362 HAVE_UPDATE_SECUREBOOT_POLICY_TOOL=true
363fi
364
365# Reads kernel configuration option.
366kernel_get_config_opt()
367{
368 kern_ver="$1"
369 opt_name="$2"
370
371 [ -n "$kern_ver" ] || return
372 [ -n "$opt_name" ] || return
373
374 # Check if there is a kernel tool which can extract config option.
375 if test -x /lib/modules/"$kern_ver"/build/scripts/config; then
376 /lib/modules/"$kern_ver"/build/scripts/config \
377 --file /lib/modules/"$kern_ver"/build/.config \
378 --state "$opt_name" 2>/dev/null
379 elif test -f /lib/modules/"$kern_ver"/build/.config; then
380 # Extract config option manually.
381 grep "$opt_name=" /lib/modules/"$kern_ver"/build/.config | sed -e "s/^$opt_name=//" -e "s/\"//g"
382 fi
383}
384
385# Reads CONFIG_MODULE_SIG_HASH from kernel config.
386kernel_module_sig_hash()
387{
388 kern_ver="$1"
389 [ -n "$kern_ver" ] || return
390
391 kernel_get_config_opt "$kern_ver" "CONFIG_MODULE_SIG_HASH"
392}
393
394# Returns "1" if kernel module signature hash algorithm
395# is supported by us. Or empty string otherwise.
396module_sig_hash_supported()
397{
398 sig_hashalgo="$1"
399 [ -n "$sig_hashalgo" ] || return
400
401 # Go through supported list.
402 [ "$sig_hashalgo" = "sha1" \
403 -o "$sig_hashalgo" = "sha224" \
404 -o "$sig_hashalgo" = "sha256" \
405 -o "$sig_hashalgo" = "sha384" \
406 -o "$sig_hashalgo" = "sha512" ] || return
407
408 echo "1"
409}
410
411# Check if kernel configuration requires modules signature.
412kernel_requires_module_signature()
413{
414 kern_ver="$1"
415 vbox_sys_lockdown_path="/sys/kernel/security/lockdown"
416
417 [ -n "$kern_ver" ] || return
418
419 requires=""
420 # We consider that if kernel is running in the following configurations,
421 # it will require modules to be signed.
422 if [ "$(kernel_get_config_opt "$kern_ver" "CONFIG_MODULE_SIG")" = "y" ]; then
423
424 # Modules signature verification is hardcoded in kernel config.
425 [ "$(kernel_get_config_opt "$kern_ver" "CONFIG_MODULE_SIG_FORCE")" = "y" ] && requires="1"
426
427 # Unsigned modules loading is restricted by "lockdown" feature in runtime.
428 if [ "$(kernel_get_config_opt "$kern_ver" "CONFIG_LOCK_DOWN_KERNEL")" = "y" \
429 -o "$(kernel_get_config_opt "$kern_ver" "CONFIG_SECURITY_LOCKDOWN_LSM")" = "y" \
430 -o "$(kernel_get_config_opt "$kern_ver" "CONFIG_SECURITY_LOCKDOWN_LSM_EARLY")" = "y" ]; then
431
432 # Once lockdown level is set to something different from "none" (e.g., "integrity"
433 # or "confidentiality"), kernel will reject unsigned modules loading.
434 if [ -r "$vbox_sys_lockdown_path" ]; then
435 [ -n "$(cat "$vbox_sys_lockdown_path" | grep "\[integrity\]")" ] && requires="1"
436 [ -n "$(cat "$vbox_sys_lockdown_path" | grep "\[confidentiality\]")" ] && requires="1"
437 fi
438
439 # This configuration is used by a number of modern Linux distributions and restricts
440 # unsigned modules loading when Secure Boot mode is enabled.
441 [ "$(kernel_get_config_opt "$kern_ver" "CONFIG_LOCK_DOWN_IN_EFI_SECURE_BOOT")" = "y" -a -n "$HAVE_SEC_BOOT" ] && requires="1"
442 fi
443 fi
444
445 [ -n "$requires" ] && echo "1"
446}
447
448sign_modules()
449{
450 KERN_VER="$1"
451 test -n "$KERN_VER" || return 1
452
453 # Make list of mudules to sign.
454 MODULE_LIST="vboxguest vboxsf"
455 # vboxvideo might not present on for older kernels.
456 [ -f "/lib/modules/"$KERN_VER"/misc/vboxvideo.ko" ] && MODULE_LIST="$MODULE_LIST vboxvideo"
457
458 # Sign kernel modules if kernel configuration requires it.
459 if test "$(kernel_requires_module_signature $KERN_VER)" = "1"; then
460 begin "Signing VirtualBox Guest Additions kernel modules"
461
462 # Generate new signing key if needed.
463 [ -n "$HAVE_UPDATE_SECUREBOOT_POLICY_TOOL" ] && SHIM_NOTRIGGER=y update-secureboot-policy --new-key
464
465 # Check if signing keys are in place.
466 if test ! -f "$DEB_PUB_KEY" || ! test -f "$DEB_PRIV_KEY"; then
467 # update-secureboot-policy tool present in the system, but keys were not generated.
468 [ -n "$HAVE_UPDATE_SECUREBOOT_POLICY_TOOL" ] && info "
469
470update-secureboot-policy tool does not generate signing keys
471in your distribution, see below on how to generate them manually."
472 # update-secureboot-policy not present in the system, recommend generate keys manually.
473 fail "
474
475System is running in Secure Boot mode, however your distribution
476does not provide tools for automatic generation of keys needed for
477modules signing. Please consider to generate and enroll them manually:
478
479 sudo mkdir -p /var/lib/shim-signed/mok
480 sudo openssl req -nodes -new -x509 -newkey rsa:2048 -outform DER -addext \"extendedKeyUsage=codeSigning\" -keyout $DEB_PRIV_KEY -out $DEB_PUB_KEY
481 sudo mokutil --import $DEB_PUB_KEY
482 sudo reboot
483
484Restart \"rcvboxadd setup\" after system is rebooted.
485"
486 fi
487
488 # Get kernel signature hash algorithm from kernel config and validate it.
489 sig_hashalgo=$(kernel_module_sig_hash "$KERN_VER")
490 [ "$(module_sig_hash_supported $sig_hashalgo)" = "1" ] \
491 || fail "Unsupported kernel signature hash algorithm $sig_hashalgo"
492
493 # Sign modules.
494 for i in $MODULE_LIST; do
495
496 # Try to find a tool for modules signing.
497 SIGN_TOOL=$(which kmodsign 2>/dev/null)
498 # Attempt to use in-kernel signing tool if kmodsign not found.
499 if test -z "$SIGN_TOOL"; then
500 if test -x "/lib/modules/$KERN_VER/build/scripts/sign-file"; then
501 SIGN_TOOL="/lib/modules/$KERN_VER/build/scripts/sign-file"
502 fi
503 fi
504
505 # Check if signing tool is available.
506 [ -n "$SIGN_TOOL" ] || fail "Unable to find signing tool"
507
508 "$SIGN_TOOL" "$sig_hashalgo" "$DEB_PRIV_KEY" "$DEB_PUB_KEY" \
509 /lib/modules/"$KERN_VER"/misc/"$i".ko || fail "Unable to sign $i.ko"
510 done
511 # Enroll signing key if needed.
512 if test -n "$HAVE_UPDATE_SECUREBOOT_POLICY_TOOL"; then
513 # update-secureboot-policy "expects" DKMS modules.
514 # Work around this and talk to the authors as soon
515 # as possible to fix it.
516 mkdir -p /var/lib/dkms/vbox-temp
517 update-secureboot-policy --enroll-key 2>/dev/null ||
518 fail "Failed to enroll secure boot key."
519 rmdir -p /var/lib/dkms/vbox-temp 2>/dev/null
520
521 # Indicate that key has been enrolled and reboot is needed.
522 HAVE_DEB_KEY=true
523 fi
524 fi
525}
526
527# Build and install the VirtualBox guest kernel modules
528setup_modules()
529{
530 KERN_VER="$1"
531 test -n "$KERN_VER" || return 1
532 # Match (at least): vboxguest.o; vboxguest.ko; vboxguest.ko.xz
533 set /lib/modules/"$KERN_VER"/misc/vboxguest.*o*
534 #test ! -f "$1" || return 0
535 test -d /lib/modules/"$KERN_VER"/build || return 0
536 export KERN_VER
537 info "Building the modules for kernel $KERN_VER."
538
539 # Prepend PATH for building UEK on OL8/9 distributions.
540 case "$KERN_VER" in
541 5.15.0-*.el8uek*) PATH="/opt/rh/gcc-toolset-11/root/usr/bin:$PATH";;
542 6.12.0-*.el9uek*)PATH="/opt/rh/gcc-toolset-14/root/usr/bin:$PATH";;
543 esac
544
545 # Detect if kernel was built with clang.
546 unset LLVM
547 vbox_cc_is_clang=$(kernel_get_config_opt "$KERN_VER" "CONFIG_CC_IS_CLANG")
548 if test "${vbox_cc_is_clang}" = "y"; then
549 info "Using clang compiler."
550 export LLVM=1
551 fi
552
553 log "Building the main Guest Additions $INSTALL_VER module for kernel $KERN_VER."
554 if ! myerr=`$BUILDINTMP \
555 --save-module-symvers /tmp/vboxguest-Module.symvers \
556 --module-source $MODULE_SRC/vboxguest \
557 --no-print-directory install 2>&1`; then
558 # If check_module_dependencies.sh fails it prints a message itself.
559 module_build_log "$myerr"
560 "${INSTALL_DIR}"/other/check_module_dependencies.sh 2>&1 &&
561 info "Look at $LOG to find out what went wrong"
562 return 0
563 fi
564 log "Building the shared folder support module."
565 if ! myerr=`$BUILDINTMP \
566 --use-module-symvers /tmp/vboxguest-Module.symvers \
567 --module-source $MODULE_SRC/vboxsf \
568 --no-print-directory install 2>&1`; then
569 module_build_log "$myerr"
570 info "Look at $LOG to find out what went wrong"
571 return 0
572 fi
573 log "Building the graphics driver module."
574 if ! myerr=`$BUILDINTMP \
575 --use-module-symvers /tmp/vboxguest-Module.symvers \
576 --module-source $MODULE_SRC/vboxvideo \
577 --no-print-directory install 2>&1`; then
578 module_build_log "$myerr"
579 info "Look at $LOG to find out what went wrong"
580 fi
581 [ -d /etc/depmod.d ] || mkdir /etc/depmod.d
582 echo "override vboxguest * misc" > /etc/depmod.d/vboxvideo-upstream.conf
583 echo "override vboxsf * misc" >> /etc/depmod.d/vboxvideo-upstream.conf
584 echo "override vboxvideo * misc" >> /etc/depmod.d/vboxvideo-upstream.conf
585
586 sign_modules "${KERN_VER}"
587
588 update_initramfs "${KERN_VER}"
589
590 return 0
591}
592
593create_vbox_user()
594{
595 # This is the LSB version of useradd and should work on recent
596 # distributions
597 useradd -d /var/run/vboxadd -g 1 -r -s /bin/false vboxadd >/dev/null 2>&1 || true
598 # And for the others, we choose a UID ourselves
599 useradd -d /var/run/vboxadd -g 1 -u 501 -o -s /bin/false vboxadd >/dev/null 2>&1 || true
600
601}
602
603create_udev_rule()
604{
605 # Create udev description file
606 if [ -d /etc/udev/rules.d ]; then
607 udev_call=""
608 udev_app=`which udevadm 2> /dev/null`
609 if [ $? -eq 0 ]; then
610 udev_call="${udev_app} version 2> /dev/null"
611 else
612 udev_app=`which udevinfo 2> /dev/null`
613 if [ $? -eq 0 ]; then
614 udev_call="${udev_app} -V 2> /dev/null"
615 fi
616 fi
617 udev_fix="="
618 if [ "${udev_call}" != "" ]; then
619 udev_out=`${udev_call}`
620 udev_ver=`expr "$udev_out" : '[^0-9]*\([0-9]*\)'`
621 if [ "$udev_ver" = "" -o "$udev_ver" -lt 55 ]; then
622 udev_fix=""
623 fi
624 fi
625 ## @todo 60-vboxadd.rules -> 60-vboxguest.rules ?
626 echo "KERNEL=${udev_fix}\"vboxguest\", NAME=\"vboxguest\", OWNER=\"vboxadd\", MODE=\"0660\"" > /etc/udev/rules.d/60-vboxadd.rules
627 echo "KERNEL=${udev_fix}\"vboxuser\", NAME=\"vboxuser\", OWNER=\"vboxadd\", MODE=\"0666\"" >> /etc/udev/rules.d/60-vboxadd.rules
628 # Make sure the new rule is noticed.
629 udevadm control --reload >/dev/null 2>&1 || true
630 udevcontrol reload_rules >/dev/null 2>&1 || true
631 fi
632}
633
634create_module_rebuild_script()
635{
636 # And a post-installation script for rebuilding modules when a new kernel
637 # is installed.
638 mkdir -p /etc/kernel/postinst.d /etc/kernel/prerm.d
639 cat << EOF > /etc/kernel/postinst.d/vboxadd
640#!/bin/sh
641# This only works correctly on Debian derivatives - Red Hat calls it before
642# installing the right header files.
643/sbin/rcvboxadd quicksetup "\${1}"
644exit 0
645EOF
646 cat << EOF > /etc/kernel/prerm.d/vboxadd
647#!/bin/sh
648for i in ${OLDMODULES}; do rm -f /lib/modules/"\${1}"/misc/"\${i}".ko; done
649rmdir -p /lib/modules/"\$1"/misc 2>/dev/null || true
650exit 0
651EOF
652 chmod 0755 /etc/kernel/postinst.d/vboxadd /etc/kernel/prerm.d/vboxadd
653}
654
655shared_folder_setup()
656{
657 # Add a group "vboxsf" for Shared Folders access
658 # All users which want to access the auto-mounted Shared Folders have to
659 # be added to this group.
660 groupadd -r -f vboxsf >/dev/null 2>&1
661
662 # Put the mount.vboxsf mount helper in the right place.
663 ## @todo It would be nicer if the kernel module just parsed parameters
664 # itself instead of needing a separate binary to do that.
665 ln -sf "${INSTALL_DIR}/other/mount.vboxsf" /sbin
666 # SELinux security context for the mount helper.
667 if test -e /etc/selinux/config; then
668 # This is correct. semanage maps this to the real path, and it aborts
669 # with an error, telling you what you should have typed, if you specify
670 # the real path. The "chcon" is there as a back-up for old guests.
671 command -v semanage > /dev/null &&
672 semanage fcontext -a -t mount_exec_t "${INSTALL_DIR}/other/mount.vboxsf"
673 chcon -t mount_exec_t "${INSTALL_DIR}/other/mount.vboxsf" 2>/dev/null
674 fi
675}
676
677# Returns path to a module file as seen by modinfo(8), or none if not found.
678#
679# Input $1: Module name to get path for.
680#
681# Returns the module path as a string.
682module_path()
683{
684 mod="$1"
685 [ -n "$mod" ] || return
686
687 modinfo "$mod" 2>/dev/null | grep -e "^filename:" | tr -s ' ' | cut -d " " -f2
688}
689
690# Returns module version if module is available, or none if not found.
691#
692# Input $1: Module name to get version for.
693#
694# Returns the module version as a string.
695module_version()
696{
697 mod="$1"
698 [ -n "$mod" ] || return
699
700 modinfo "$mod" 2>/dev/null | grep -e "^version:" | tr -s ' ' | cut -d " " -f2
701}
702
703# Returns the module revision if module is available in the system, or none if not found.
704#
705# Input $1: Module name to get revision for.
706#
707# Returns the module revision as a string.
708module_revision()
709{
710 mod="$1"
711 [ -n "$mod" ] || return
712
713 modinfo "$mod" 2>/dev/null | grep -e "^version:" | tr -s ' ' | cut -d " " -f3
714}
715
716# Checks if a given kernel module is properly signed or not.
717#
718# Input $1: Module name to check.
719#
720# Returns "1" if module is signed and signature can be verified
721# with public key provided in DEB_PUB_KEY, or none otherwise.
722module_signed()
723{
724 mod="$1"
725 [ -n "$mod" ] || return
726
727 # Be nice with distributions which do not provide tools which we
728 # use in order to verify module signature. This variable needs to
729 # be explicitly set by administrator. This script will look for it
730 # in /etc/virtualbox-guest-additions.conf. Make sure that you know
731 # what you do!
732 if [ "$VBOX_BYPASS_MODULES_SIGNATURE_CHECK" = "1" ]; then
733 echo "1"
734 return
735 fi
736
737 extraction_tool=/lib/modules/"$(uname -r)"/build/scripts/extract-module-sig.pl
738 mod_path=$(module_path "$mod" 2>/dev/null)
739 openssl_tool=$(which openssl 2>/dev/null)
740 # Do not use built-in printf!
741 printf_tool=$(which printf 2>/dev/null)
742
743 # Make sure all the tools required for signature validation are available.
744 [ -x "$extraction_tool" ] || return
745 [ -n "$mod_path" ] || return
746 [ -n "$openssl_tool" ] || return
747 [ -n "$printf_tool" ] || return
748
749 # Make sure openssl can handle hash algorithm.
750 sig_hashalgo=$(modinfo -F sig_hashalgo "$mod" 2>/dev/null)
751 [ "$(module_sig_hash_supported $sig_hashalgo)" = "1" ] || return
752
753 # Generate file names for temporary stuff.
754 mod_pub_key=$(mktemp -u)
755 mod_signature=$(mktemp -u)
756 mod_unsigned=$(mktemp -u)
757
758 # Convert public key in DER format into X509 certificate form.
759 "$openssl_tool" x509 -pubkey -inform DER -in "$DEB_PUB_KEY" -out "$mod_pub_key" 2>/dev/null
760 # Extract raw module signature and convert it into binary format.
761 "$printf_tool" \\x$(modinfo -F signature "$mod" | sed -z 's/[ \t\n]//g' | sed -e "s/:/\\\x/g") 2>/dev/null > "$mod_signature"
762 # Extract unsigned module for further digest calculation.
763 "$extraction_tool" -0 "$mod_path" 2>/dev/null > "$mod_unsigned"
764
765 # Verify signature.
766 rc=""
767 "$openssl_tool" dgst "-$sig_hashalgo" -binary -verify "$mod_pub_key" -signature "$mod_signature" "$mod_unsigned" 2>&1 >/dev/null && rc="1"
768 # Clean up.
769 rm -f $mod_pub_key $mod_signature $mod_unsigned
770
771 # Check result.
772 [ "$rc" = "1" ] || return
773
774 echo "1"
775}
776
777# Checks if a given kernel module matches the installed VirtualBox Guest Additions version.
778#
779# Input $1: Module name to check.
780#
781# Returns "1" if externally built module is available in the system and its
782# version and revision number do match to current VirtualBox installation.
783# None otherwise.
784module_available()
785{
786 mod="$1"
787 [ -n "$mod" ] || return
788
789 [ "$VBOX_VERSION" = "$(module_version "$mod")" ] || return
790 [ "$VBOX_REVISION" = "$(module_revision "$mod")" ] || return
791
792 # Check if module belongs to VirtualBox installation.
793 #
794 # We have a convention that only modules from /lib/modules/*/misc
795 # belong to us. Modules from other locations are treated as
796 # externally built.
797 mod_path="$(module_path "$mod")"
798
799 # If module path points to a symbolic link, resolve actual file location.
800 [ -L "$mod_path" ] && mod_path="$(readlink -e -- "$mod_path")"
801
802 # File exists?
803 [ -f "$mod_path" ] || return
804
805 # Extract last component of module path and check whether it is located
806 # outside of /lib/modules/*/misc.
807 mod_dir="$(dirname "$mod_path" | sed 's;^.*/;;')"
808 [ "$mod_dir" = "misc" ] || return
809
810 # In case if kernel configuration (for currently loaded kernel) requires
811 # module signature, check if module is signed.
812 if test "$(kernel_requires_module_signature $(uname -r))" = "1"; then
813 [ "$(module_signed "$mod")" = "1" ] || return
814 fi
815
816 echo "1"
817}
818
819# Check if required modules are installed in the system and versions match.
820#
821# Returns "1" on success, none otherwise.
822setup_complete()
823{
824 [ "$(module_available vboxguest)" = "1" ] || return
825 [ "$(module_available vboxsf)" = "1" ] || return
826
827 # All modules are in place.
828 echo "1"
829}
830
831# setup_script
832setup()
833{
834 info "Setting up modules"
835
836 # chcon is needed on old Fedora/Redhat systems. No one remembers which.
837 test ! -e /etc/selinux/config ||
838 chcon -t bin_t "$BUILDINTMP" 2>/dev/null
839
840 if test -z "$INSTALL_NO_MODULE_BUILDS"; then
841 # Check whether modules setup is already complete for currently running kernel.
842 # Prevent unnecessary rebuilding in order to speed up booting process.
843 if test "$(setup_complete)" = "1"; then
844 info "VirtualBox Guest Additions kernel modules $VBOX_VERSION $VBOX_REVISION are \
845already available for kernel $TARGET_VER and do not require to be rebuilt."
846 else
847 info "Building the VirtualBox Guest Additions kernel modules. This may take a while."
848 info "To build modules for other installed kernels, run"
849 info " /sbin/rcvboxadd quicksetup <version>"
850 info "or"
851 info " /sbin/rcvboxadd quicksetup all"
852 if test -d /lib/modules/"$TARGET_VER"/build; then
853 setup_modules "$TARGET_VER"
854 depmod
855 else
856 info "Kernel headers not found for target kernel $TARGET_VER. \
857Please install them and execute
858 /sbin/rcvboxadd setup"
859 fi
860 fi
861 fi
862 create_vbox_user
863 create_udev_rule
864 test -n "${INSTALL_NO_MODULE_BUILDS}" || create_module_rebuild_script
865 shared_folder_setup
866 # Create user group which will have permissive access to DRP IPC server socket.
867 groupadd -r -f vboxdrmipc >/dev/null 2>&1
868
869 if running_module "vboxguest"; then
870 # Only warn user if currently loaded modules version do not match Guest Additions Installation.
871 check_running_module_version "vboxguest" || info "Running kernel modules will not be replaced until the system is restarted or 'rcvboxadd reload' triggered"
872 fi
873
874 # Put the X.Org driver in place. This is harmless if it is not needed.
875 # Also set up the OpenGL library.
876 myerr=`"${INSTALL_DIR}/init/vboxadd-x11" setup 2>&1`
877 test -z "${myerr}" || log "${myerr}"
878
879 return 0
880}
881
882# cleanup_script
883cleanup()
884{
885 if test -z "${INSTALL_NO_MODULE_BUILDS}"; then
886 # Delete old versions of VBox modules.
887 cleanup_modules
888 depmod
889
890 # Remove old module sources
891 for i in $OLDMODULES; do
892 rm -rf /usr/src/$i-*
893 done
894 fi
895
896 # Clean-up X11-related bits
897 "${INSTALL_DIR}/init/vboxadd-x11" cleanup
898
899 # Remove other files
900 if test -z "${INSTALL_NO_MODULE_BUILDS}"; then
901 rm -f /etc/kernel/postinst.d/vboxadd /etc/kernel/prerm.d/vboxadd
902 rmdir -p /etc/kernel/postinst.d /etc/kernel/prerm.d 2>/dev/null || true
903 fi
904 rm -f /sbin/mount.vboxsf 2>/dev/null
905 rm -f /etc/udev/rules.d/60-vboxadd.rules 2>/dev/null
906 udevadm control --reload >/dev/null 2>&1 || true
907 udevcontrol reload_rules >/dev/null 2>&1 || true
908}
909
910start()
911{
912 begin "Starting."
913
914 # Check if kernel modules for currently running kernel are ready
915 # and rebuild them if needed.
916 test "$(setup_complete)" = "1" || setup
917
918 # Warn if Secure Boot setup not yet complete.
919 if test "$(kernel_requires_module_signature)" = "1" && test -z "$DEB_KEY_ENROLLED"; then
920 if test -n "$HAVE_DEB_KEY"; then
921 info "You must re-start your system to finish secure boot set-up."
922 else
923 info "You must sign vboxguest, vboxsf and
924vboxvideo (if present) kernel modules before using
925VirtualBox Guest Additions. See the documentation
926for your Linux distribution."
927 fi
928 fi
929
930 if test -z "${INSTALL_NO_MODULE_BUILDS}"; then
931 test -d /sys &&
932 ps -A -o comm | grep -q '/*udevd$' 2>/dev/null ||
933 no_udev=1
934 check_running_module_version "vboxguest" || {
935 rm -f $dev || {
936 fail "Cannot remove $dev"
937 }
938 rm -f $userdev || {
939 fail "Cannot remove $userdev"
940 }
941 # Assuming modules were just (re-)built, try to reload everything.
942 reload
943 }
944 case "$no_udev" in 1)
945 do_vboxguest_non_udev;;
946 esac
947 fi # INSTALL_NO_MODULE_BUILDS
948
949 return 0
950}
951
952stop()
953{
954 begin "Stopping."
955
956 if test -r /etc/ld.so.conf.d/00vboxvideo.conf; then
957 rm /etc/ld.so.conf.d/00vboxvideo.conf
958 ldconfig
959 fi
960 if ! umount -a -t vboxsf 2>/dev/null; then
961 # Make sure we only fail, if there are truly no more vboxsf
962 # mounts in the system.
963 [ -n "$(findmnt -t vboxsf)" ] && fail "Cannot unmount vboxsf folders"
964 fi
965 test -n "${INSTALL_NO_MODULE_BUILDS}" ||
966 info "You may need to restart your guest system to finish removing guest drivers or consider running 'rcvboxadd reload'."
967 return 0
968}
969
970check_root()
971{
972 # Check if script is running with root privileges and exit if it does not.
973 [ `id -u` -eq 0 ] || early_fail "root privileges are required"
974}
975
976# Check if process with this PID is running.
977check_pid()
978{
979 pid="$1"
980
981 test -n "$pid" -a -d "/proc/$pid"
982}
983
984# A wrapper for check_running_module_version.
985# Verify if module is loaded and its version matches
986# to current Additions installation version.
987check_running_module()
988{
989 mod="$1"
990
991 # Check args.
992 [ -n "$mod" ] || return
993
994 # During reload action it may take some time for module
995 # to be fully loaded, so make a few attempts while checking this.
996 for attempt in 1 2 3 4 5; do
997
998 # Wait before the next attempt.
999 [ -n "$vbox_add_wait" -a $? -ne 0 ] && sleep 1
1000
1001 running_module "$mod"
1002 if [ $? -eq 0 ]; then
1003 mod_is_running="1"
1004 check_running_module_version "$mod"
1005 [ $? -eq 0 ] && break
1006 else
1007 mod_is_running=""
1008 false
1009 fi
1010
1011 done
1012
1013 # In case of error, try to print out proper reason of failure.
1014 if [ $? -ne 0 ]; then
1015 # Was module loaded?
1016 if [ -z "$mod_is_running" ]; then
1017 info "module $mod is not loaded"
1018 else
1019 # If module was loaded it means that it has incorrect version.
1020 info "currently loaded module $mod version ($(running_module_version "$mod")) does not match to VirtualBox Guest Additions installation version ($VBOX_VERSION $VBOX_REVISION)"
1021 fi
1022
1023 # Set "bad" rc.
1024 false
1025 fi
1026}
1027
1028# Go through list of Additions modules and check
1029# if they were properly loaded.
1030check_status_kernel()
1031{
1032 # Module vboxguest should be loaded unconditionally once Guest Additions were installed.
1033 check_running_module "vboxguest"
1034
1035 # Module vboxsf module might not be loaded if VM has no Shared Folder mappings.
1036 # Check that first and then verify the module.
1037 if [ $? -eq 0 ]; then
1038 VBoxControl sharedfolder list >/dev/null 2>&1
1039 if [ $? -eq 0 ]; then
1040 check_running_module "vboxsf"
1041 else
1042 # Do not spoil $?.
1043 true
1044 fi
1045 fi
1046
1047 # Module vboxvideo is optional and expected to be loaded only when VM is
1048 # running VBoxVGA or VBoxSVGA graphics.
1049 if [ $? -eq 0 ]; then
1050 gpu_vendor=$(lspci | grep 'VGA compatible controller' | cut -d ' ' -f 5 2>/dev/null)
1051 if [ "$gpu_vendor" = "InnoTek" ]; then
1052 check_running_module "vboxvideo"
1053 else
1054 # Do not spoil $?.
1055 true
1056 fi
1057 else
1058 false
1059 fi
1060}
1061
1062# Check whether user-land processes are running.
1063# Currently only check for VBoxService.
1064check_status_user()
1065{
1066 [ -r "$VBOXSERVICE_PIDFILE" ] && check_pid "$(cat $VBOXSERVICE_PIDFILE)" >/dev/null 2>&1
1067}
1068
1069send_signal_by_pidfile()
1070{
1071 sig="$1"
1072 pidfile="$2"
1073
1074 if [ -f "$pidfile" ]; then
1075 check_pid $(cat "$pidfile")
1076 if [ $? -eq 0 ]; then
1077 kill "$sig" $(cat "$pidfile") >/dev/null 2>&1
1078 else
1079 # Do not spoil $?.
1080 true
1081 fi
1082 else
1083 # Do not spoil $?.
1084 true
1085 fi
1086}
1087
1088# SIGUSR1 is used in order to notify VBoxClient processes that system
1089# update is started or kernel modules are going to be reloaded,
1090# so VBoxClient can release vboxguest.ko resources and then restart itself.
1091send_signal()
1092{
1093 sig="$1"
1094 # Specify whether we sending signal to VBoxClient parent (control)
1095 # process or a child (actual service) process.
1096 process_type="$2"
1097
1098 pidfile_postfix=""
1099 [ -z "$process_type" ] || pidfile_postfix="-$process_type"
1100
1101 for user_name in $(getent passwd | cut -d ':' -f 1); do
1102
1103 # Filter out empty login names (paranoia).
1104 [ -n "$user_name" ] || continue
1105
1106 user_shell=$(getent passwd "$user_name" | cut -d ':' -f 7)
1107
1108 # Filter out login names with not specified shells (paranoia).
1109 [ -n "$user_shell" ] || continue
1110
1111 # Filter out know non-login account names.
1112 case "$user_shell" in
1113 *nologin) skip_user_home="1";;
1114 *sync) skip_user_home="1";;
1115 *shutdown) skip_user_home="1";;
1116 *halt) skip_user_home="1";;
1117 *) skip_user_home=""
1118 esac
1119 [ -z "$skip_user_home" ] || continue;
1120
1121 user_home=$(getent passwd "$user_name" | cut -d ':' -f 6)
1122
1123 for pid_file in "$user_home"/.vboxclient-*"$pidfile_postfix".pid; do
1124
1125 [ -r "$pid_file" ] || continue
1126
1127 # If process type was not specified, we assume that signal supposed
1128 # to be sent to legacy VBoxClient processes which have different
1129 # pidfile name pattern (it does not contain "control" or "service").
1130 # Skip those pidfiles who has.
1131 [ -z "$process_type" -a -n "$(echo "$pid_file" | grep "control")" ] && continue
1132 [ -z "$process_type" -a -n "$(echo "$pid_file" | grep "service")" ] && continue
1133
1134 send_signal_by_pidfile -USR1 "$pid_file"
1135
1136 done
1137 done
1138}
1139
1140# Helper function which executes a command, prints error message if command fails,
1141# and preserves command execution status for further processing.
1142try_load_preserve_rc()
1143{
1144 cmd="$1"
1145 msg="$2"
1146
1147 $cmd >/dev/null 2>&1
1148
1149 rc=$?
1150 [ $rc -eq 0 ] || info "$msg"
1151
1152 return $rc
1153}
1154
1155reload()
1156{
1157 begin "reloading kernel modules and services"
1158
1159 # Stop VBoxService if running.
1160 $VBOX_SERVICE_SCRIPT status >/dev/null 2>&1
1161 if [ $? -eq 0 ]; then
1162 $VBOX_SERVICE_SCRIPT stop >/dev/null 2>&1 || fail "unable to stop VBoxService"
1163 fi
1164
1165 # Unmount Shared Folders.
1166 umount -a -t vboxsf >/dev/null 2>&1 || fail "unable to unmount shared folders, mount point(s) might be still in use"
1167
1168 # Stop VBoxDRMClient.
1169 send_signal_by_pidfile "-USR1" "/var/run/VBoxDRMClient" || fail "unable to stop VBoxDRMClient"
1170
1171 if [ $? -eq 0 ]; then
1172 # Tell legacy VBoxClient processes to release vboxguest.ko references.
1173 send_signal "-USR1" ""
1174
1175 # Tell compatible VBoxClient processes to release vboxguest.ko references.
1176 send_signal "-USR1" "service"
1177
1178 # Try unload.
1179 for attempt in 1 2 3 4 5; do
1180
1181 # Give VBoxClient processes some time to close reference to vboxguest module.
1182 [ $? -ne 0 ] && sleep 1
1183
1184 # Try unload drivers unconditionally (ignore previous command exit code).
1185 # If final goal of unloading vboxguest.ko won't be met, we will fail on
1186 # the next step anyway.
1187 running_module "vboxsf" && modprobe -r vboxsf >/dev/null 2>&1
1188 running_module "vboxguest"
1189 if [ $? -eq 0 ]; then
1190 modprobe -r vboxguest >/dev/null 2>&1
1191 [ $? -eq 0 ] && break
1192 else
1193 # Do not spoil $?.
1194 true
1195 fi
1196 done
1197
1198 # Check if we succeeded with unloading vboxguest after several attempts.
1199 running_module "vboxguest"
1200 if [ $? -eq 0 ]; then
1201 info "cannot reload kernel modules: one or more module(s) is still in use"
1202 false
1203 else
1204 # Do not spoil $?.
1205 true
1206 fi
1207
1208 # Load drivers (skip vboxvideo since it is not loaded for very old guests).
1209 [ $? -eq 0 ] && try_load_preserve_rc "modprobe vboxguest" "unable to load vboxguest kernel module, see dmesg"
1210 [ $? -eq 0 ] && try_load_preserve_rc "modprobe vboxsf" "unable to load vboxsf kernel module, see dmesg"
1211
1212 # Start VBoxService and VBoxDRMClient.
1213 [ $? -eq 0 ] && try_load_preserve_rc "$VBOX_SERVICE_SCRIPT start" "unable to start VBoxService"
1214
1215 # Reload VBoxClient processes.
1216 [ $? -eq 0 ] && try_load_preserve_rc "send_signal -USR1 control" "unable to reload user session services"
1217
1218 # Check if we just loaded modules of correct version.
1219 [ $? -eq 0 ] && try_load_preserve_rc "check_status_kernel" "kernel modules were not reloaded"
1220
1221 # Check if user-land processes were restarted as well.
1222 [ $? -eq 0 ] && try_load_preserve_rc "check_status_user" "user-land services were not started"
1223
1224 if [ $? -eq 0 ]; then
1225 # Take reported version of running Guest Additions from running vboxguest module (as a paranoia check).
1226 info "kernel modules and services $(running_module_version "vboxguest") reloaded"
1227 info "NOTE: you may still consider to re-login if some user session specific services (Shared Clipboard, Drag and Drop, Seamless or Guest Screen Resize) were not restarted automatically"
1228 else
1229 # In case of failure, sent SIGTERM to abandoned control processes to remove leftovers from failed reloading.
1230 send_signal "-TERM" "control"
1231
1232 fail "kernel modules and services were not reloaded"
1233 fi
1234 else
1235 fail "cannot stop user services"
1236 fi
1237}
1238
1239dmnstatus()
1240{
1241 if running_module "vboxguest"; then
1242 echo "The VirtualBox Additions are currently running."
1243 else
1244 echo "The VirtualBox Additions are not currently running."
1245 fi
1246}
1247
1248for i; do
1249 case "$i" in quiet) QUIET=yes;; esac
1250done
1251case "$1" in
1252# Does setup without clean-up first and marks all kernels currently found on the
1253# system so that we can see later if any were added.
1254start)
1255 check_root
1256 start
1257 ;;
1258# Tries to build kernel modules for kernels added since start. Tries to unmount
1259# shared folders. Uninstalls our Chromium 3D libraries since we can't always do
1260# this fast enough at start time if we discover we do not want to use them.
1261stop)
1262 check_root
1263 stop
1264 ;;
1265restart)
1266 check_root
1267 restart
1268 ;;
1269# Tries to reload kernel modules and restart user processes.
1270reload)
1271 check_root
1272 # reload() we will call modprobe(8) in order to reload kernel
1273 # modules. This operation is asynchronous and requires some time for
1274 # modules to be loaded in most of the cases. By setting this variable, we
1275 # ask check_running_module() to wait a bit before making a decision
1276 # whether modules were loaded or not.
1277 vbox_add_wait=1
1278 reload
1279 ;;
1280# Setup does a clean-up (see below) and re-does all Additions-specific
1281# configuration of the guest system, including building kernel modules for the
1282# current kernel.
1283setup)
1284 check_root
1285 cleanup && start
1286 ;;
1287# Builds kernel modules for the specified kernels if they are not already built.
1288quicksetup)
1289 check_root
1290 if test x"$2" = xall; then
1291 for topi in /lib/modules/*; do
1292 KERN_VER="${topi%/misc}"
1293 KERN_VER="${KERN_VER#/lib/modules/}"
1294 setup_modules "$KERN_VER"
1295 done
1296 elif test -n "$2"; then
1297 setup_modules "$2"
1298 else
1299 setup_modules "$TARGET_VER"
1300 fi
1301 ;;
1302# Clean-up removes all Additions-specific configuration of the guest system,
1303# including all kernel modules.
1304cleanup)
1305 check_root
1306 cleanup
1307 ;;
1308status)
1309 dmnstatus
1310 ;;
1311status-kernel)
1312 check_root
1313 check_status_kernel
1314 if [ $? -eq 0 ]; then
1315 info "kernel modules $VBOX_VERSION $VBOX_REVISION are loaded"
1316 else
1317 info "kernel modules $VBOX_VERSION $VBOX_REVISION were not loaded"
1318 false
1319 fi
1320 ;;
1321status-user)
1322 check_root
1323 check_status_user
1324 if [ $? -eq 0 ]; then
1325 info "user-land services $VBOX_VERSION $VBOX_REVISION are running"
1326 else
1327 info "user-land services $VBOX_VERSION $VBOX_REVISION are not running"
1328 false
1329 fi
1330 ;;
1331*)
1332 echo "Usage: $0 {start|stop|restart|reload|status|status-kernel|status-user|setup|quicksetup|cleanup} [quiet]"
1333 exit 1
1334esac
1335
1336exit
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