VirtualBox

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

Last change on this file since 75399 was 75323, checked in by vboxsync, 6 years ago

Additions/linux: disable 3D for guests using Wayland.
ticketref:18116: Linux guests with X.Org Server 1.20 and 3D enabled fail...
Our 3D pass-through on Linux guests was designed for an X11 world where GLX
was the only way of accessing OpenGL. It does not work with Wayland clients
or compositors, and can actively cause problems for EGL with OpenGL. Case in
point, guests with X.Org Server 1.20 installed do not boot to desktop with
3D enabled. Rather than working around that for the few remaining GLX
applications on the desktop, just disable 3D when Wayland is in use.

  • Property svn:eol-style set to LF
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 19.1 KB
Line 
1#! /bin/sh
2# $Id: vboxadd.sh 75323 2018-11-08 15:29:56Z vboxsync $
3## @file
4# Linux Additions kernel module init script ($Revision: 75323 $)
5#
6
7#
8# Copyright (C) 2006-2017 Oracle Corporation
9#
10# This file is part of VirtualBox Open Source Edition (OSE), as
11# available from http://www.virtualbox.org. This file is free software;
12# you can redistribute it and/or modify it under the terms of the GNU
13# General Public License (GPL) as published by the Free Software
14# Foundation, in version 2 as it comes in the "COPYING" file of the
15# VirtualBox OSE distribution. VirtualBox OSE is distributed in the
16# hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
17#
18
19# X-Start-Before is a Debian Addition which we use when converting to
20# a systemd unit. X-Service-Type is our own invention, also for systemd.
21
22# chkconfig: 345 10 90
23# description: VirtualBox Linux Additions kernel modules
24#
25### BEGIN INIT INFO
26# Provides: vboxadd
27# Required-Start:
28# Required-Stop:
29# Default-Start: 2 3 4 5
30# Default-Stop: 0 1 6
31# X-Start-Before: display-manager
32# X-Service-Type: oneshot
33# Description: VirtualBox Linux Additions kernel modules
34### END INIT INFO
35
36## @todo This file duplicates a lot of script with vboxdrv.sh. When making
37# changes please try to reduce differences between the two wherever possible.
38
39# Testing:
40# * Should fail if the configuration file is missing or missing INSTALL_DIR or
41# INSTALL_VER entries.
42# * vboxadd user and vboxsf groups should be created if they do not exist - test
43# by removing them before installing.
44# * Shared folders can be mounted and auto-mounts accessible to vboxsf group,
45# including on recent Fedoras with SELinux.
46# * Setting INSTALL_NO_MODULE_BUILDS inhibits modules and module automatic
47# rebuild script creation; otherwise modules, user, group, rebuild script,
48# udev rule and shared folder mount helper should be created/set up.
49# * Setting INSTALL_NO_MODULE_BUILDS inhibits module load and unload on start
50# and stop.
51# * Uninstalling the Additions and re-installing them does not trigger warnings.
52
53export LC_ALL=C
54PATH=$PATH:/bin:/sbin:/usr/sbin
55PACKAGE=VBoxGuestAdditions
56MODPROBE=/sbin/modprobe
57OLDMODULES="vboxguest vboxadd vboxsf vboxvfs vboxvideo"
58SERVICE="VirtualBox Guest Additions"
59QUICKSETUP=
60## systemd logs information about service status, otherwise do that ourselves.
61QUIET=
62test -z "${KERN_VER}" && KERN_VER=`uname -r`
63
64setup_log()
65{
66 test -n "${LOG}" && return 0
67 # Rotate log files
68 LOG="/var/log/vboxadd-setup.log"
69 mv "${LOG}.3" "${LOG}.4" 2>/dev/null
70 mv "${LOG}.2" "${LOG}.3" 2>/dev/null
71 mv "${LOG}.1" "${LOG}.2" 2>/dev/null
72 mv "${LOG}" "${LOG}.1" 2>/dev/null
73}
74
75if $MODPROBE -c 2>/dev/null | grep -q '^allow_unsupported_modules *0'; then
76 MODPROBE="$MODPROBE --allow-unsupported-modules"
77fi
78
79# Check architecture
80cpu=`uname -m`;
81case "$cpu" in
82 i[3456789]86|x86)
83 cpu="x86"
84 ldconfig_arch="(libc6)"
85 lib_candidates="/usr/lib/i386-linux-gnu /usr/lib /lib"
86 ;;
87 x86_64|amd64)
88 cpu="amd64"
89 ldconfig_arch="(libc6,x86-64)"
90 lib_candidates="/usr/lib/x86_64-linux-gnu /usr/lib64 /usr/lib /lib64 /lib"
91 ;;
92esac
93for i in $lib_candidates; do
94 if test -d "$i/VBoxGuestAdditions"; then
95 lib_path=$i
96 break
97 fi
98done
99
100# Preamble for Gentoo
101if [ "`which $0`" = "/sbin/rc" ]; then
102 shift
103fi
104
105begin()
106{
107 test -z "${QUIET}" && echo "${SERVICE}: ${1}"
108}
109
110info()
111{
112 if test -z "${QUIET}"; then
113 echo "${SERVICE}: $1"
114 else
115 echo "$1"
116 fi
117}
118
119fail()
120{
121 log "${1}"
122 echo "$1" >&2
123 echo "The log file $LOG may contain further information." >&2
124 exit 1
125}
126
127log()
128{
129 setup_log
130 echo "${1}" >> "${LOG}"
131}
132
133module_build_log()
134{
135 log "Error building the module. Build output follows."
136 echo ""
137 echo "${1}" >> "${LOG}"
138}
139
140dev=/dev/vboxguest
141userdev=/dev/vboxuser
142config=/var/lib/VBoxGuestAdditions/config
143owner=vboxadd
144group=1
145
146if test -r $config; then
147 . $config
148else
149 fail "Configuration file $config not found"
150fi
151test -n "$INSTALL_DIR" -a -n "$INSTALL_VER" ||
152 fail "Configuration file $config not complete"
153
154running_vboxguest()
155{
156 lsmod | grep -q "vboxguest[^_-]"
157}
158
159running_vboxadd()
160{
161 lsmod | grep -q "vboxadd[^_-]"
162}
163
164running_vboxsf()
165{
166 lsmod | grep -q "vboxsf[^_-]"
167}
168
169running_vboxvideo()
170{
171 lsmod | grep -q "vboxvideo[^_-]"
172}
173
174do_vboxguest_non_udev()
175{
176 if [ ! -c $dev ]; then
177 maj=`sed -n 's;\([0-9]\+\) vboxguest;\1;p' /proc/devices`
178 if [ ! -z "$maj" ]; then
179 min=0
180 else
181 min=`sed -n 's;\([0-9]\+\) vboxguest;\1;p' /proc/misc`
182 if [ ! -z "$min" ]; then
183 maj=10
184 fi
185 fi
186 test -z "$maj" && {
187 rmmod vboxguest 2>/dev/null
188 fail "Cannot locate the VirtualBox device"
189 }
190
191 mknod -m 0664 $dev c $maj $min || {
192 rmmod vboxguest 2>/dev/null
193 fail "Cannot create device $dev with major $maj and minor $min"
194 }
195 fi
196 chown $owner:$group $dev 2>/dev/null || {
197 rm -f $dev 2>/dev/null
198 rm -f $userdev 2>/dev/null
199 rmmod vboxguest 2>/dev/null
200 fail "Cannot change owner $owner:$group for device $dev"
201 }
202
203 if [ ! -c $userdev ]; then
204 maj=10
205 min=`sed -n 's;\([0-9]\+\) vboxuser;\1;p' /proc/misc`
206 if [ ! -z "$min" ]; then
207 mknod -m 0666 $userdev c $maj $min || {
208 rm -f $dev 2>/dev/null
209 rmmod vboxguest 2>/dev/null
210 fail "Cannot create device $userdev with major $maj and minor $min"
211 }
212 chown $owner:$group $userdev 2>/dev/null || {
213 rm -f $dev 2>/dev/null
214 rm -f $userdev 2>/dev/null
215 rmmod vboxguest 2>/dev/null
216 fail "Cannot change owner $owner:$group for device $userdev"
217 }
218 fi
219 fi
220}
221
222start()
223{
224 begin "Starting."
225 # If we got this far assume that the slow set-up has been done.
226 QUICKSETUP=start
227 if test -z "${INSTALL_NO_MODULE_BUILDS}"; then
228 uname -r | grep -q -E '^2\.6|^3|^4' 2>/dev/null &&
229 ps -A -o comm | grep -q '/*udevd$' 2>/dev/null ||
230 no_udev=1
231 running_vboxguest || {
232 rm -f $dev || {
233 fail "Cannot remove $dev"
234 }
235
236 rm -f $userdev || {
237 fail "Cannot remove $userdev"
238 }
239
240 $MODPROBE vboxguest >/dev/null 2>&1 || {
241 setup
242 $MODPROBE vboxguest >/dev/null 2>&1 ||
243 fail "modprobe vboxguest failed"
244 }
245 case "$no_udev" in 1)
246 sleep .5;;
247 esac
248 }
249 case "$no_udev" in 1)
250 do_vboxguest_non_udev;;
251 esac
252
253 running_vboxsf || {
254 $MODPROBE vboxsf > /dev/null 2>&1 || {
255 if dmesg | grep "VbglR0SfConnect failed" > /dev/null 2>&1; then
256 info "Unable to start shared folders support. Make sure that your VirtualBox build supports this feature."
257 else
258 info "modprobe vboxsf failed"
259 fi
260 }
261 }
262 fi # INSTALL_NO_MODULE_BUILDS
263
264 # Put the X.Org driver in place. This is harmless if it is not needed.
265 myerr=`"${INSTALL_DIR}/init/vboxadd-x11" setup 2>&1`
266 test -z "${myerr}" || log "${myerr}"
267 # Install the guest OpenGL drivers. For now we don't support
268 # multi-architecture installations
269 rm -f /etc/ld.so.conf.d/00vboxvideo.conf
270 rm -Rf /var/lib/VBoxGuestAdditions/lib
271 if /usr/bin/VBoxClient --check3d 2>/dev/null; then
272 setup_gl=true;
273 else
274 unset setup_gl
275 fi
276 # Disable 3D if Xwayland is found, except on Ubuntu 18.04.
277 if type Xwayland >/dev/null 2>&1; then
278 unset PRETTY_NAME
279 . /etc/os-release 2>/dev/null
280 case "${PRETTY_NAME}" in
281 "Ubuntu 18.04"*) ;;
282 *) unset setup_gl ;;
283 esac
284 fi
285 if test -n "${setup_gl}"; then
286 mkdir -p /var/lib/VBoxGuestAdditions/lib
287 ln -sf "${INSTALL_DIR}/lib/VBoxOGL.so" /var/lib/VBoxGuestAdditions/lib/libGL.so.1
288 # SELinux for the OpenGL libraries, so that gdm can load them during the
289 # acceleration support check. This prevents an "Oh no, something has gone
290 # wrong!" error when starting EL7 guests.
291 if test -e /etc/selinux/config; then
292 if command -v semanage > /dev/null; then
293 semanage fcontext -a -t lib_t "/var/lib/VBoxGuestAdditions/lib/libGL.so.1"
294 fi
295 chcon -h -t lib_t "/var/lib/VBoxGuestAdditions/lib/libGL.so.1"
296 fi
297 echo "/var/lib/VBoxGuestAdditions/lib" > /etc/ld.so.conf.d/00vboxvideo.conf
298 fi
299 ldconfig
300
301 # Mount all shared folders from /etc/fstab. Normally this is done by some
302 # other startup script but this requires the vboxdrv kernel module loaded.
303 # This isn't necessary anymore as the vboxsf module is autoloaded.
304 # mount -a -t vboxsf
305
306 return 0
307}
308
309stop()
310{
311 begin "Stopping."
312 if test -r /etc/ld.so.conf.d/00vboxvideo.conf; then
313 rm /etc/ld.so.conf.d/00vboxvideo.conf
314 ldconfig
315 fi
316 if ! umount -a -t vboxsf 2>/dev/null; then
317 fail "Cannot unmount vboxsf folders"
318 fi
319 test -n "${INSTALL_NO_MODULE_BUILDS}" ||
320 info "You may need to restart your guest system to finish removing the guest drivers."
321 return 0
322}
323
324restart()
325{
326 stop && start
327 return 0
328}
329
330## Update the initramfs. Debian and Ubuntu put the graphics driver in, and
331# need the touch(1) command below. Everyone else that I checked just need
332# the right module alias file from depmod(1) and only use the initramfs to
333# load the root filesystem, not the boot splash. update-initramfs works
334# for the first two and dracut for every one else I checked. We are only
335# interested in distributions recent enough to use the KMS vboxvideo driver.
336update_initramfs()
337{
338 ## kernel version to update for.
339 version="${1}"
340 depmod "${version}"
341 rm -f "/lib/modules/${version}/initrd/vboxvideo"
342 test -d "/lib/modules/${version}/initrd" &&
343 test -f "/lib/modules/${version}/misc/vboxvideo.ko" &&
344 touch "/lib/modules/${version}/initrd/vboxvideo"
345
346 # Systems without systemd-inhibit probably don't need their initramfs
347 # rebuild here anyway.
348 type systemd-inhibit >/dev/null 2>&1 || return
349 if type dracut >/dev/null 2>&1; then
350 systemd-inhibit --why="Installing VirtualBox Guest Additions" \
351 dracut -f --kver "${version}"
352 elif type update-initramfs >/dev/null 2>&1; then
353 systemd-inhibit --why="Installing VirtualBox Guest Additions" \
354 update-initramfs -u -k "${version}"
355 fi
356}
357
358# Remove any existing VirtualBox guest kernel modules from the disk, but not
359# from the kernel as they may still be in use
360cleanup_modules()
361{
362 test "x${1}" = x--skip && skip_ver="${2}"
363 # Needed for Ubuntu and Debian, see update_initramfs
364 rm -f /lib/modules/*/initrd/vboxvideo
365 for i in /lib/modules/*/misc; do
366 kern_ver="${i%/misc}"
367 kern_ver="${kern_ver#/lib/modules/}"
368 unset do_update
369 for j in ${OLDMODULES}; do
370 test -f "${i}/${j}.ko" && do_update=1 && rm -f "${i}/${j}.ko"
371 done
372 test -n "${do_update}" && test "x${kern_ver}" != "x${skip_ver}" &&
373 update_initramfs "${kern_ver}"
374 # Remove empty /lib/modules folders which may have been kept around
375 rmdir -p "${i}" 2>/dev/null || true
376 unset keep
377 for j in /lib/modules/"${kern_ver}"/*; do
378 name="${j##*/}"
379 test -d "${name}" || test "${name%%.*}" != modules && keep=1
380 done
381 if test -z "${keep}"; then
382 rm -rf /lib/modules/"${kern_ver}"
383 rm -f /boot/initrd.img-"${kern_ver}"
384 fi
385 done
386 for i in ${OLDMODULES}; do
387 # We no longer support DKMS, remove any leftovers.
388 rm -rf "/var/lib/dkms/${i}"*
389 done
390 rm -f /etc/depmod.d/vboxvideo-upstream.conf
391}
392
393# Build and install the VirtualBox guest kernel modules
394setup_modules()
395{
396 # don't stop the old modules here -- they might be in use
397 test -z "${QUICKSETUP}" && cleanup_modules --skip "${KERN_VER}"
398 # This does not work for 2.4 series kernels. How sad.
399 test -n "${QUICKSETUP}" && test -f "${MODULE_DIR}/vboxguest.ko" && return 0
400 info "Building the VirtualBox Guest Additions kernel modules. This may take a while."
401
402 # If the kernel headers are not there, wait at bit in case they get
403 # installed. Package managers have been known to trigger module rebuilds
404 # before actually installing the headers.
405 for delay in 60 60 60 60 60 300 30 300 300; do
406 test "x${QUICKSETUP}" = xyes || break
407 test -d "/lib/modules/${KERN_VER}/build" && break
408 printf "Kernel modules not yet installed, waiting %s seconds." "${delay}"
409 sleep "${delay}"
410 done
411
412 # Inhibit shutdown for up to ten minutes if possible.
413 systemd-inhibit 600 2>/dev/null &
414 log "Building the main Guest Additions module."
415 if ! myerr=`$BUILDINTMP \
416 --save-module-symvers /tmp/vboxguest-Module.symvers \
417 --module-source $MODULE_SRC/vboxguest \
418 --no-print-directory install 2>&1`; then
419 # If check_module_dependencies.sh fails it prints a message itself.
420 module_build_log "$myerr"
421 "${INSTALL_DIR}"/other/check_module_dependencies.sh 2>&1 &&
422 info "Look at $LOG to find out what went wrong"
423 kill $! 2>/dev/null
424 return 0
425 fi
426 log "Building the shared folder support module."
427 if ! myerr=`$BUILDINTMP \
428 --use-module-symvers /tmp/vboxguest-Module.symvers \
429 --module-source $MODULE_SRC/vboxsf \
430 --no-print-directory install 2>&1`; then
431 module_build_log "$myerr"
432 info "Look at $LOG to find out what went wrong"
433 kill $! 2>/dev/null
434 return 0
435 fi
436 log "Building the graphics driver module."
437 if ! myerr=`$BUILDINTMP \
438 --use-module-symvers /tmp/vboxguest-Module.symvers \
439 --module-source $MODULE_SRC/vboxvideo \
440 --no-print-directory install 2>&1`; then
441 module_build_log "$myerr"
442 info "Look at $LOG to find out what went wrong"
443 fi
444 [ -d /etc/depmod.d ] || mkdir /etc/depmod.d
445 echo "override vboxguest * misc" > /etc/depmod.d/vboxvideo-upstream.conf
446 echo "override vboxsf * misc" >> /etc/depmod.d/vboxvideo-upstream.conf
447 echo "override vboxvideo * misc" >> /etc/depmod.d/vboxvideo-upstream.conf
448 update_initramfs "${KERN_VER}"
449 depmod
450 kill $! 2>/dev/null
451 return 0
452}
453
454create_vbox_user()
455{
456 # This is the LSB version of useradd and should work on recent
457 # distributions
458 useradd -d /var/run/vboxadd -g 1 -r -s /bin/false vboxadd >/dev/null 2>&1 || true
459 # And for the others, we choose a UID ourselves
460 useradd -d /var/run/vboxadd -g 1 -u 501 -o -s /bin/false vboxadd >/dev/null 2>&1 || true
461
462}
463
464create_udev_rule()
465{
466 # Create udev description file
467 if [ -d /etc/udev/rules.d ]; then
468 udev_call=""
469 udev_app=`which udevadm 2> /dev/null`
470 if [ $? -eq 0 ]; then
471 udev_call="${udev_app} version 2> /dev/null"
472 else
473 udev_app=`which udevinfo 2> /dev/null`
474 if [ $? -eq 0 ]; then
475 udev_call="${udev_app} -V 2> /dev/null"
476 fi
477 fi
478 udev_fix="="
479 if [ "${udev_call}" != "" ]; then
480 udev_out=`${udev_call}`
481 udev_ver=`expr "$udev_out" : '[^0-9]*\([0-9]*\)'`
482 if [ "$udev_ver" = "" -o "$udev_ver" -lt 55 ]; then
483 udev_fix=""
484 fi
485 fi
486 ## @todo 60-vboxadd.rules -> 60-vboxguest.rules ?
487 echo "KERNEL=${udev_fix}\"vboxguest\", NAME=\"vboxguest\", OWNER=\"vboxadd\", MODE=\"0660\"" > /etc/udev/rules.d/60-vboxadd.rules
488 echo "KERNEL=${udev_fix}\"vboxuser\", NAME=\"vboxuser\", OWNER=\"vboxadd\", MODE=\"0666\"" >> /etc/udev/rules.d/60-vboxadd.rules
489 fi
490}
491
492create_module_rebuild_script()
493{
494 # And a post-installation script for rebuilding modules when a new kernel
495 # is installed.
496 mkdir -p /etc/kernel/postinst.d /etc/kernel/prerm.d
497 cat << EOF > /etc/kernel/postinst.d/vboxadd
498#!/bin/sh
499# Run in the background so that we can wait in case the package installer has
500# not yet installed the kernel headers we need.
501KERN_VER="\${1}" /sbin/rcvboxadd quicksetup &
502exit 0
503EOF
504 cat << EOF > /etc/kernel/prerm.d/vboxadd
505#!/bin/sh
506for i in ${OLDMODULES}; do rm -f /lib/modules/"\${1}"/misc/"\${i}".ko; done
507rmdir -p /lib/modules/"\$1"/misc 2>/dev/null
508exit 0
509EOF
510 chmod 0755 /etc/kernel/postinst.d/vboxadd /etc/kernel/prerm.d/vboxadd
511}
512
513shared_folder_setup()
514{
515 # Add a group "vboxsf" for Shared Folders access
516 # All users which want to access the auto-mounted Shared Folders have to
517 # be added to this group.
518 groupadd -r -f vboxsf >/dev/null 2>&1
519
520 # Put the mount.vboxsf mount helper in the right place.
521 ## @todo It would be nicer if the kernel module just parsed parameters
522 # itself instead of needing a separate binary to do that.
523 ln -sf "${INSTALL_DIR}/other/mount.vboxsf" /sbin
524 # SELinux security context for the mount helper.
525 if test -e /etc/selinux/config; then
526 # This is correct. semanage maps this to the real path, and it aborts
527 # with an error, telling you what you should have typed, if you specify
528 # the real path. The "chcon" is there as a back-up for old guests.
529 command -v semanage > /dev/null &&
530 semanage fcontext -a -t mount_exec_t "${INSTALL_DIR}/other/mount.vboxsf"
531 chcon -t mount_exec_t "${INSTALL_DIR}/other/mount.vboxsf"
532 fi
533}
534
535# setup_script
536setup()
537{
538 export BUILD_TYPE
539 export USERNAME
540
541 MODULE_SRC="$INSTALL_DIR/src/vboxguest-$INSTALL_VER"
542 BUILDINTMP="$MODULE_SRC/build_in_tmp"
543 test -e /etc/selinux/config &&
544 chcon -t bin_t "$BUILDINTMP"
545
546 test -z "${INSTALL_NO_MODULE_BUILDS}" && setup_modules
547 create_vbox_user
548 create_udev_rule
549 test -z "${INSTALL_NO_MODULE_BUILDS}" && create_module_rebuild_script
550 test -n "${QUICKSETUP}" && return 0
551 shared_folder_setup
552 if running_vboxguest || running_vboxadd; then
553 info "Running kernel modules will not be replaced until the system is restarted"
554 fi
555 return 0
556}
557
558# cleanup_script
559cleanup()
560{
561 if test -z "${INSTALL_NO_MODULE_BUILDS}"; then
562 # Delete old versions of VBox modules.
563 cleanup_modules
564 depmod
565
566 # Remove old module sources
567 for i in $OLDMODULES; do
568 rm -rf /usr/src/$i-*
569 done
570 fi
571
572 # Clean-up X11-related bits
573 "${INSTALL_DIR}/init/vboxadd-x11" cleanup
574
575 # Remove other files
576 rm /sbin/mount.vboxsf 2>/dev/null
577 if test -z "${INSTALL_NO_MODULE_BUILDS}"; then
578 rm -f /etc/kernel/postinst.d/vboxadd /etc/kernel/prerm.d/vboxadd
579 rmdir -p /etc/kernel/postinst.d /etc/kernel/prerm.d 2>/dev/null
580 fi
581 rm /etc/udev/rules.d/60-vboxadd.rules 2>/dev/null
582}
583
584dmnstatus()
585{
586 if running_vboxguest; then
587 echo "The VirtualBox Additions are currently running."
588 else
589 echo "The VirtualBox Additions are not currently running."
590 fi
591}
592
593case "$2" in quiet)
594 QUIET=yes;;
595esac
596case "$1" in
597start)
598 start
599 ;;
600stop)
601 stop
602 ;;
603restart)
604 restart
605 ;;
606setup)
607 setup
608 start
609 ;;
610quicksetup)
611 QUICKSETUP=yes
612 setup
613 ;;
614cleanup)
615 cleanup
616 ;;
617status)
618 dmnstatus
619 ;;
620*)
621 echo "Usage: $0 {start|stop|restart|status|setup|quicksetup|cleanup} [quiet]"
622 exit 1
623esac
624
625exit
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