VirtualBox

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

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

Additions/linux/installer: only enable 3D for X.Org Server 1.19 or earlier.
bugref:9281: 3D acceleration reported broken on Ubuntu 18.10...
We previously tried to fix this by disabling 3D if Xwayland was found, except
for Ubuntu 18.04 where we wanted to keep 3D enabled. This was a bad idea
because EL7.6 has X.Org Server 1.20 without Wayland. So just do the simple
thing and enable 3D if an X server older than 1.20 is found, and only then.

  • Property svn:eol-style set to LF
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 17.8 KB
Line 
1#! /bin/sh
2# $Id: vboxadd.sh 75428 2018-11-13 17:03:46Z vboxsync $
3## @file
4# Linux Additions kernel module init script ($Revision: 75428 $)
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 # Also set up the OpenGL library.
266 myerr=`"${INSTALL_DIR}/init/vboxadd-x11" setup 2>&1`
267 test -z "${myerr}" || log "${myerr}"
268
269 # Mount all shared folders from /etc/fstab. Normally this is done by some
270 # other startup script but this requires the vboxdrv kernel module loaded.
271 # This isn't necessary anymore as the vboxsf module is autoloaded.
272 # mount -a -t vboxsf
273
274 return 0
275}
276
277stop()
278{
279 begin "Stopping."
280 if test -r /etc/ld.so.conf.d/00vboxvideo.conf; then
281 rm /etc/ld.so.conf.d/00vboxvideo.conf
282 ldconfig
283 fi
284 if ! umount -a -t vboxsf 2>/dev/null; then
285 fail "Cannot unmount vboxsf folders"
286 fi
287 test -n "${INSTALL_NO_MODULE_BUILDS}" ||
288 info "You may need to restart your guest system to finish removing the guest drivers."
289 return 0
290}
291
292restart()
293{
294 stop && start
295 return 0
296}
297
298## Update the initramfs. Debian and Ubuntu put the graphics driver in, and
299# need the touch(1) command below. Everyone else that I checked just need
300# the right module alias file from depmod(1) and only use the initramfs to
301# load the root filesystem, not the boot splash. update-initramfs works
302# for the first two and dracut for every one else I checked. We are only
303# interested in distributions recent enough to use the KMS vboxvideo driver.
304update_initramfs()
305{
306 ## kernel version to update for.
307 version="${1}"
308 depmod "${version}"
309 rm -f "/lib/modules/${version}/initrd/vboxvideo"
310 test -d "/lib/modules/${version}/initrd" &&
311 test -f "/lib/modules/${version}/misc/vboxvideo.ko" &&
312 touch "/lib/modules/${version}/initrd/vboxvideo"
313
314 # Systems without systemd-inhibit probably don't need their initramfs
315 # rebuild here anyway.
316 type systemd-inhibit >/dev/null 2>&1 || return
317 if type dracut >/dev/null 2>&1; then
318 systemd-inhibit --why="Installing VirtualBox Guest Additions" \
319 dracut -f --kver "${version}"
320 elif type update-initramfs >/dev/null 2>&1; then
321 systemd-inhibit --why="Installing VirtualBox Guest Additions" \
322 update-initramfs -u -k "${version}"
323 fi
324}
325
326# Remove any existing VirtualBox guest kernel modules from the disk, but not
327# from the kernel as they may still be in use
328cleanup_modules()
329{
330 test "x${1}" = x--skip && skip_ver="${2}"
331 # Needed for Ubuntu and Debian, see update_initramfs
332 rm -f /lib/modules/*/initrd/vboxvideo
333 for i in /lib/modules/*/misc; do
334 kern_ver="${i%/misc}"
335 kern_ver="${kern_ver#/lib/modules/}"
336 unset do_update
337 for j in ${OLDMODULES}; do
338 test -f "${i}/${j}.ko" && do_update=1 && rm -f "${i}/${j}.ko"
339 done
340 test -n "${do_update}" && test "x${kern_ver}" != "x${skip_ver}" &&
341 update_initramfs "${kern_ver}"
342 # Remove empty /lib/modules folders which may have been kept around
343 rmdir -p "${i}" 2>/dev/null || true
344 unset keep
345 for j in /lib/modules/"${kern_ver}"/*; do
346 name="${j##*/}"
347 test -d "${name}" || test "${name%%.*}" != modules && keep=1
348 done
349 if test -z "${keep}"; then
350 rm -rf /lib/modules/"${kern_ver}"
351 rm -f /boot/initrd.img-"${kern_ver}"
352 fi
353 done
354 for i in ${OLDMODULES}; do
355 # We no longer support DKMS, remove any leftovers.
356 rm -rf "/var/lib/dkms/${i}"*
357 done
358 rm -f /etc/depmod.d/vboxvideo-upstream.conf
359}
360
361# Build and install the VirtualBox guest kernel modules
362setup_modules()
363{
364 # don't stop the old modules here -- they might be in use
365 test -z "${QUICKSETUP}" && cleanup_modules --skip "${KERN_VER}"
366 # This does not work for 2.4 series kernels. How sad.
367 test -n "${QUICKSETUP}" && test -f "${MODULE_DIR}/vboxguest.ko" && return 0
368 info "Building the VirtualBox Guest Additions kernel modules. This may take a while."
369
370 # If the kernel headers are not there, wait at bit in case they get
371 # installed. Package managers have been known to trigger module rebuilds
372 # before actually installing the headers.
373 for delay in 60 60 60 60 60 300 30 300 300; do
374 test "x${QUICKSETUP}" = xyes || break
375 test -d "/lib/modules/${KERN_VER}/build" && break
376 printf "Kernel modules not yet installed, waiting %s seconds." "${delay}"
377 sleep "${delay}"
378 done
379
380 # Inhibit shutdown for up to ten minutes if possible.
381 systemd-inhibit 600 2>/dev/null &
382 log "Building the main Guest Additions module."
383 if ! myerr=`$BUILDINTMP \
384 --save-module-symvers /tmp/vboxguest-Module.symvers \
385 --module-source $MODULE_SRC/vboxguest \
386 --no-print-directory install 2>&1`; then
387 # If check_module_dependencies.sh fails it prints a message itself.
388 module_build_log "$myerr"
389 "${INSTALL_DIR}"/other/check_module_dependencies.sh 2>&1 &&
390 info "Look at $LOG to find out what went wrong"
391 kill $! 2>/dev/null
392 return 0
393 fi
394 log "Building the shared folder support module."
395 if ! myerr=`$BUILDINTMP \
396 --use-module-symvers /tmp/vboxguest-Module.symvers \
397 --module-source $MODULE_SRC/vboxsf \
398 --no-print-directory install 2>&1`; then
399 module_build_log "$myerr"
400 info "Look at $LOG to find out what went wrong"
401 kill $! 2>/dev/null
402 return 0
403 fi
404 log "Building the graphics driver module."
405 if ! myerr=`$BUILDINTMP \
406 --use-module-symvers /tmp/vboxguest-Module.symvers \
407 --module-source $MODULE_SRC/vboxvideo \
408 --no-print-directory install 2>&1`; then
409 module_build_log "$myerr"
410 info "Look at $LOG to find out what went wrong"
411 fi
412 [ -d /etc/depmod.d ] || mkdir /etc/depmod.d
413 echo "override vboxguest * misc" > /etc/depmod.d/vboxvideo-upstream.conf
414 echo "override vboxsf * misc" >> /etc/depmod.d/vboxvideo-upstream.conf
415 echo "override vboxvideo * misc" >> /etc/depmod.d/vboxvideo-upstream.conf
416 update_initramfs "${KERN_VER}"
417 depmod
418 kill $! 2>/dev/null
419 return 0
420}
421
422create_vbox_user()
423{
424 # This is the LSB version of useradd and should work on recent
425 # distributions
426 useradd -d /var/run/vboxadd -g 1 -r -s /bin/false vboxadd >/dev/null 2>&1 || true
427 # And for the others, we choose a UID ourselves
428 useradd -d /var/run/vboxadd -g 1 -u 501 -o -s /bin/false vboxadd >/dev/null 2>&1 || true
429
430}
431
432create_udev_rule()
433{
434 # Create udev description file
435 if [ -d /etc/udev/rules.d ]; then
436 udev_call=""
437 udev_app=`which udevadm 2> /dev/null`
438 if [ $? -eq 0 ]; then
439 udev_call="${udev_app} version 2> /dev/null"
440 else
441 udev_app=`which udevinfo 2> /dev/null`
442 if [ $? -eq 0 ]; then
443 udev_call="${udev_app} -V 2> /dev/null"
444 fi
445 fi
446 udev_fix="="
447 if [ "${udev_call}" != "" ]; then
448 udev_out=`${udev_call}`
449 udev_ver=`expr "$udev_out" : '[^0-9]*\([0-9]*\)'`
450 if [ "$udev_ver" = "" -o "$udev_ver" -lt 55 ]; then
451 udev_fix=""
452 fi
453 fi
454 ## @todo 60-vboxadd.rules -> 60-vboxguest.rules ?
455 echo "KERNEL=${udev_fix}\"vboxguest\", NAME=\"vboxguest\", OWNER=\"vboxadd\", MODE=\"0660\"" > /etc/udev/rules.d/60-vboxadd.rules
456 echo "KERNEL=${udev_fix}\"vboxuser\", NAME=\"vboxuser\", OWNER=\"vboxadd\", MODE=\"0666\"" >> /etc/udev/rules.d/60-vboxadd.rules
457 fi
458}
459
460create_module_rebuild_script()
461{
462 # And a post-installation script for rebuilding modules when a new kernel
463 # is installed.
464 mkdir -p /etc/kernel/postinst.d /etc/kernel/prerm.d
465 cat << EOF > /etc/kernel/postinst.d/vboxadd
466#!/bin/sh
467# Run in the background so that we can wait in case the package installer has
468# not yet installed the kernel headers we need.
469KERN_VER="\${1}" /sbin/rcvboxadd quicksetup &
470exit 0
471EOF
472 cat << EOF > /etc/kernel/prerm.d/vboxadd
473#!/bin/sh
474for i in ${OLDMODULES}; do rm -f /lib/modules/"\${1}"/misc/"\${i}".ko; done
475rmdir -p /lib/modules/"\$1"/misc 2>/dev/null
476exit 0
477EOF
478 chmod 0755 /etc/kernel/postinst.d/vboxadd /etc/kernel/prerm.d/vboxadd
479}
480
481shared_folder_setup()
482{
483 # Add a group "vboxsf" for Shared Folders access
484 # All users which want to access the auto-mounted Shared Folders have to
485 # be added to this group.
486 groupadd -r -f vboxsf >/dev/null 2>&1
487
488 # Put the mount.vboxsf mount helper in the right place.
489 ## @todo It would be nicer if the kernel module just parsed parameters
490 # itself instead of needing a separate binary to do that.
491 ln -sf "${INSTALL_DIR}/other/mount.vboxsf" /sbin
492 # SELinux security context for the mount helper.
493 if test -e /etc/selinux/config; then
494 # This is correct. semanage maps this to the real path, and it aborts
495 # with an error, telling you what you should have typed, if you specify
496 # the real path. The "chcon" is there as a back-up for old guests.
497 command -v semanage > /dev/null &&
498 semanage fcontext -a -t mount_exec_t "${INSTALL_DIR}/other/mount.vboxsf"
499 chcon -t mount_exec_t "${INSTALL_DIR}/other/mount.vboxsf"
500 fi
501}
502
503# setup_script
504setup()
505{
506 export BUILD_TYPE
507 export USERNAME
508
509 MODULE_SRC="$INSTALL_DIR/src/vboxguest-$INSTALL_VER"
510 BUILDINTMP="$MODULE_SRC/build_in_tmp"
511 test -e /etc/selinux/config &&
512 chcon -t bin_t "$BUILDINTMP"
513
514 test -z "${INSTALL_NO_MODULE_BUILDS}" && setup_modules
515 create_vbox_user
516 create_udev_rule
517 test -z "${INSTALL_NO_MODULE_BUILDS}" && create_module_rebuild_script
518 test -n "${QUICKSETUP}" && return 0
519 shared_folder_setup
520 if running_vboxguest || running_vboxadd; then
521 info "Running kernel modules will not be replaced until the system is restarted"
522 fi
523 return 0
524}
525
526# cleanup_script
527cleanup()
528{
529 if test -z "${INSTALL_NO_MODULE_BUILDS}"; then
530 # Delete old versions of VBox modules.
531 cleanup_modules
532 depmod
533
534 # Remove old module sources
535 for i in $OLDMODULES; do
536 rm -rf /usr/src/$i-*
537 done
538 fi
539
540 # Clean-up X11-related bits
541 "${INSTALL_DIR}/init/vboxadd-x11" cleanup
542
543 # Remove other files
544 rm /sbin/mount.vboxsf 2>/dev/null
545 if test -z "${INSTALL_NO_MODULE_BUILDS}"; then
546 rm -f /etc/kernel/postinst.d/vboxadd /etc/kernel/prerm.d/vboxadd
547 rmdir -p /etc/kernel/postinst.d /etc/kernel/prerm.d 2>/dev/null
548 fi
549 rm /etc/udev/rules.d/60-vboxadd.rules 2>/dev/null
550}
551
552dmnstatus()
553{
554 if running_vboxguest; then
555 echo "The VirtualBox Additions are currently running."
556 else
557 echo "The VirtualBox Additions are not currently running."
558 fi
559}
560
561case "$2" in quiet)
562 QUIET=yes;;
563esac
564case "$1" in
565start)
566 start
567 ;;
568stop)
569 stop
570 ;;
571restart)
572 restart
573 ;;
574setup)
575 setup
576 start
577 ;;
578quicksetup)
579 QUICKSETUP=yes
580 setup
581 ;;
582cleanup)
583 cleanup
584 ;;
585status)
586 dmnstatus
587 ;;
588*)
589 echo "Usage: $0 {start|stop|restart|status|setup|quicksetup|cleanup} [quiet]"
590 exit 1
591esac
592
593exit
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