VirtualBox

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

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

Installers/Linux: clean up logging.

  • Remove strange kernel output from kernel module build log.
  • Remove most non-error output, in particular, only print module build output in case of error.
  • Property svn:eol-style set to LF
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 16.1 KB
RevLine 
[301]1#! /bin/sh
[69327]2# $Id: vboxadd.sh 72196 2018-05-11 19:06:17Z vboxsync $
3## @file
[21412]4# Linux Additions kernel module init script ($Revision: 72196 $)
[1]5#
[21412]6
7#
[69500]8# Copyright (C) 2006-2017 Oracle Corporation
[5999]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#
[1]18
[67736]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.
[1]21
[60317]22# chkconfig: 345 10 90
[15585]23# description: VirtualBox Linux Additions kernel modules
[1]24#
25### BEGIN INIT INFO
26# Provides: vboxadd
[1520]27# Required-Start:
[1]28# Required-Stop:
[11274]29# Default-Start: 2 3 4 5
30# Default-Stop: 0 1 6
[67736]31# X-Start-Before: display-manager
32# X-Service-Type: oneshot
[15585]33# Description: VirtualBox Linux Additions kernel modules
[1]34### END INIT INFO
35
[61199]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
[66401]39# Testing:
[66423]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.
[66401]44# * Shared folders can be mounted and auto-mounts accessible to vboxsf group,
45# including on recent Fedoras with SELinux.
[66423]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.
[66413]51# * Uninstalling the Additions and re-installing them does not trigger warnings.
[66401]52
[301]53PATH=$PATH:/bin:/sbin:/usr/sbin
[24402]54PACKAGE=VBoxGuestAdditions
[25687]55MODPROBE=/sbin/modprobe
[39358]56OLDMODULES="vboxguest vboxadd vboxsf vboxvfs vboxvideo"
[63870]57SERVICE="VirtualBox Guest Additions"
[61199]58QUICKSETUP=
[63870]59## systemd logs information about service status, otherwise do that ourselves.
60QUIET=
[301]61
[68705]62setup_log()
63{
64 test -n "${LOG}" && return 0
65 # Rotate log files
66 LOG="/var/log/vboxadd-setup.log"
67 mv "${LOG}.3" "${LOG}.4" 2>/dev/null
68 mv "${LOG}.2" "${LOG}.3" 2>/dev/null
69 mv "${LOG}.1" "${LOG}.2" 2>/dev/null
70 mv "${LOG}" "${LOG}.1" 2>/dev/null
71}
[63870]72
[51193]73if $MODPROBE -c 2>/dev/null | grep -q '^allow_unsupported_modules *0'; then
[25687]74 MODPROBE="$MODPROBE --allow-unsupported-modules"
75fi
76
[25139]77# Check architecture
78cpu=`uname -m`;
79case "$cpu" in
80 i[3456789]86|x86)
81 cpu="x86"
[59180]82 ldconfig_arch="(libc6)"
[50925]83 lib_candidates="/usr/lib/i386-linux-gnu /usr/lib /lib"
[25139]84 ;;
85 x86_64|amd64)
86 cpu="amd64"
[59180]87 ldconfig_arch="(libc6,x86-64)"
[50925]88 lib_candidates="/usr/lib/x86_64-linux-gnu /usr/lib64 /usr/lib /lib64 /lib"
[25139]89 ;;
90esac
[50925]91for i in $lib_candidates; do
92 if test -d "$i/VBoxGuestAdditions"; then
93 lib_path=$i
94 break
95 fi
96done
[25139]97
[57945]98# Preamble for Gentoo
99if [ "`which $0`" = "/sbin/rc" ]; then
100 shift
[9108]101fi
[1]102
[57945]103begin()
104{
[63870]105 test -z "${QUIET}" && echo "${SERVICE}: ${1}"
[57945]106}
[1]107
[63870]108info()
[57945]109{
[63870]110 if test -z "${QUIET}"; then
111 echo "${SERVICE}: $1"
112 else
113 echo "$1"
114 fi
[57945]115}
[9108]116
[63870]117fail()
[39358]118{
[63870]119 log "${1}"
120 echo "$1" >&2
121 echo "The log file $LOG may contain further information." >&2
122 exit 1
[39358]123}
124
[63870]125log()
[39358]126{
[68705]127 setup_log
[63870]128 echo "${1}" >> "${LOG}"
[39358]129}
130
[72196]131module_build_log()
132{
133 setup_log
134 echo "${1}" | egrep -v \
135 "^test -e include/generated/autoconf.h|^echo >&2|^/bin/false)$" \
136 >> "${LOG}"
137}
138
[21412]139dev=/dev/vboxguest
[17859]140userdev=/dev/vboxuser
[39358]141config=/var/lib/VBoxGuestAdditions/config
[6969]142owner=vboxadd
143group=1
[1]144
[66401]145if test -r $config; then
146 . $config
147else
148 fail "Configuration file $config not found"
149fi
150test -n "$INSTALL_DIR" -a -n "$INSTALL_VER" ||
151 fail "Configuration file $config not complete"
152
[21412]153running_vboxguest()
[15585]154{
[21412]155 lsmod | grep -q "vboxguest[^_-]"
[1]156}
157
[24640]158running_vboxadd()
159{
160 lsmod | grep -q "vboxadd[^_-]"
161}
162
[28998]163running_vboxsf()
[15585]164{
[28998]165 lsmod | grep -q "vboxsf[^_-]"
[15585]166}
167
[43742]168running_vboxvideo()
169{
170 lsmod | grep -q "vboxvideo[^_-]"
171}
172
[35202]173do_vboxguest_non_udev()
[15585]174{
[1]175 if [ ! -c $dev ]; then
[21412]176 maj=`sed -n 's;\([0-9]\+\) vboxguest;\1;p' /proc/devices`
[423]177 if [ ! -z "$maj" ]; then
178 min=0
179 else
[21412]180 min=`sed -n 's;\([0-9]\+\) vboxguest;\1;p' /proc/misc`
[423]181 if [ ! -z "$min" ]; then
182 maj=10
183 fi
184 fi
[301]185 test -z "$maj" && {
[21412]186 rmmod vboxguest 2>/dev/null
[9108]187 fail "Cannot locate the VirtualBox device"
[1]188 }
189
[9108]190 mknod -m 0664 $dev c $maj $min || {
[21412]191 rmmod vboxguest 2>/dev/null
[9108]192 fail "Cannot create device $dev with major $maj and minor $min"
[1]193 }
194 fi
[18056]195 chown $owner:$group $dev 2>/dev/null || {
196 rm -f $dev 2>/dev/null
197 rm -f $userdev 2>/dev/null
[21412]198 rmmod vboxguest 2>/dev/null
[18056]199 fail "Cannot change owner $owner:$group for device $dev"
200 }
201
[17859]202 if [ ! -c $userdev ]; then
[17950]203 maj=10
[17859]204 min=`sed -n 's;\([0-9]\+\) vboxuser;\1;p' /proc/misc`
205 if [ ! -z "$min" ]; then
[17950]206 mknod -m 0666 $userdev c $maj $min || {
207 rm -f $dev 2>/dev/null
[21412]208 rmmod vboxguest 2>/dev/null
[17950]209 fail "Cannot create device $userdev with major $maj and minor $min"
210 }
[18056]211 chown $owner:$group $userdev 2>/dev/null || {
212 rm -f $dev 2>/dev/null
213 rm -f $userdev 2>/dev/null
[21412]214 rmmod vboxguest 2>/dev/null
[18056]215 fail "Cannot change owner $owner:$group for device $userdev"
216 }
[17859]217 fi
218 fi
[35202]219}
[6969]220
[35202]221start()
222{
[63870]223 begin "Starting."
[61199]224 # If we got this far assume that the slow set-up has been done.
225 QUICKSETUP=yes
[66423]226 if test -z "${INSTALL_NO_MODULE_BUILDS}"; then
227 uname -r | grep -q -E '^2\.6|^3|^4' 2>/dev/null &&
228 ps -A -o comm | grep -q '/*udevd$' 2>/dev/null ||
229 no_udev=1
230 running_vboxguest || {
231 rm -f $dev || {
232 fail "Cannot remove $dev"
233 }
[35202]234
[66423]235 rm -f $userdev || {
236 fail "Cannot remove $userdev"
237 }
[35202]238
[59234]239 $MODPROBE vboxguest >/dev/null 2>&1 || {
[66423]240 setup
[68709]241 $MODPROBE vboxguest >/dev/null 2>&1 ||
[66423]242 fail "modprobe vboxguest failed"
[59234]243 }
[66423]244 case "$no_udev" in 1)
245 sleep .5;;
246 esac
[35202]247 }
248 case "$no_udev" in 1)
[66423]249 do_vboxguest_non_udev;;
[35202]250 esac
251
[66423]252 running_vboxsf || {
253 $MODPROBE vboxsf > /dev/null 2>&1 || {
254 if dmesg | grep "VbglR0SfConnect failed" > /dev/null 2>&1; then
255 info "Unable to start shared folders support. Make sure that your VirtualBox build supports this feature."
256 else
257 info "modprobe vboxsf failed"
258 fi
259 }
[15585]260 }
[66423]261 fi # INSTALL_NO_MODULE_BUILDS
[15585]262
[60317]263 # Put the X.Org driver in place. This is harmless if it is not needed.
[72196]264 myerr=`"${INSTALL_DIR}/init/vboxadd-x11" setup 2>&1`
265 test -z "${myerr}" || log "${myerr}"
[59197]266 # Install the guest OpenGL drivers. For now we don't support
267 # multi-architecture installations
[62201]268 rm -f /etc/ld.so.conf.d/00vboxvideo.conf
[67736]269 rm -Rf /var/lib/VBoxGuestAdditions/lib
[61090]270 if /usr/bin/VBoxClient --check3d 2>/dev/null; then
[62551]271 mkdir -p /var/lib/VBoxGuestAdditions/lib
[60940]272 ln -sf "${INSTALL_DIR}/lib/VBoxOGL.so" /var/lib/VBoxGuestAdditions/lib/libGL.so.1
[62394]273 # SELinux for the OpenGL libraries, so that gdm can load them during the
274 # acceleration support check. This prevents an "Oh no, something has gone
275 # wrong!" error when starting EL7 guests.
276 if test -e /etc/selinux/config; then
[62749]277 if command -v semanage > /dev/null; then
278 semanage fcontext -a -t lib_t "/var/lib/VBoxGuestAdditions/lib/libGL.so.1"
[62759]279 fi
[62394]280 chcon -h -t lib_t "/var/lib/VBoxGuestAdditions/lib/libGL.so.1"
281 fi
[60940]282 echo "/var/lib/VBoxGuestAdditions/lib" > /etc/ld.so.conf.d/00vboxvideo.conf
[59180]283 fi
[60940]284 ldconfig
[43742]285
[15585]286 # Mount all shared folders from /etc/fstab. Normally this is done by some
287 # other startup script but this requires the vboxdrv kernel module loaded.
[29016]288 # This isn't necessary anymore as the vboxsf module is autoloaded.
289 # mount -a -t vboxsf
[15585]290
[1]291 return 0
292}
293
[15585]294stop()
295{
[63870]296 begin "Stopping."
[59180]297 if test -r /etc/ld.so.conf.d/00vboxvideo.conf; then
298 rm /etc/ld.so.conf.d/00vboxvideo.conf
299 ldconfig
300 fi
[22314]301 if ! umount -a -t vboxsf 2>/dev/null; then
[15585]302 fail "Cannot unmount vboxsf folders"
303 fi
[69564]304 test -n "${INSTALL_NO_MODULE_BUILDS}" ||
[63870]305 info "You may need to restart your guest system to finish removing the guest drivers."
[1]306 return 0
307}
308
[15585]309restart()
310{
[1]311 stop && start
312 return 0
313}
314
[35200]315# Remove any existing VirtualBox guest kernel modules from the disk, but not
316# from the kernel as they may still be in use
317cleanup_modules()
[15585]318{
[62676]319 for i in ${OLDMODULES}; do
320 # We no longer support DKMS, remove any leftovers.
[57969]321 rm -rf "/var/lib/dkms/${i}"*
[62676]322 # And remove old modules.
323 rm -f /lib/modules/*/misc/"${i}"*
[57969]324 done
[61176]325 # Remove leftover module folders.
326 for i in /lib/modules/*/misc; do
327 test -d "${i}" && rmdir -p "${i}" 2>/dev/null
328 done
[63738]329 rm -f /etc/depmod.d/vboxvideo-upstream.conf
[35200]330}
331
332# Build and install the VirtualBox guest kernel modules
333setup_modules()
334{
335 # don't stop the old modules here -- they might be in use
[61199]336 test -z "${QUICKSETUP}" && cleanup_modules
[61206]337 # This does not work for 2.4 series kernels. How sad.
338 test -n "${QUICKSETUP}" && test -f "${MODULE_DIR}/vboxguest.ko" && return 0
[72196]339 info "Building the VirtualBox Guest Additions kernel modules. This may take a while."
[35200]340
[63870]341 log "Building the main Guest Additions module."
[72196]342 if ! myerr=`$BUILDINTMP \
[61206]343 --save-module-symvers /tmp/vboxguest-Module.symvers \
344 --module-source $MODULE_SRC/vboxguest \
[72196]345 --no-print-directory install 2>&1`; then
[64718]346 # If check_module_dependencies.sh fails it prints a message itself.
[72196]347 log "Error building the module:"
348 module_build_log "$myerr"
[64718]349 "${INSTALL_DIR}"/other/check_module_dependencies.sh 2>&1 &&
350 info "Look at $LOG to find out what went wrong"
[66401]351 return 0
[61206]352 fi
[72196]353 log "Building the shared folder support module."
354 if ! myerr=`$BUILDINTMP \
[61206]355 --use-module-symvers /tmp/vboxguest-Module.symvers \
356 --module-source $MODULE_SRC/vboxsf \
[72196]357 --no-print-directory install 2>&1`; then
358 log "Error building the module:"
359 module_build_log "$myerr"
[63870]360 info "Look at $LOG to find out what went wrong"
[66401]361 return 0
[61206]362 fi
[72196]363 log "Building the graphics driver module."
364 if ! myerr=`$BUILDINTMP \
[61206]365 --use-module-symvers /tmp/vboxguest-Module.symvers \
366 --module-source $MODULE_SRC/vboxvideo \
[72196]367 --no-print-directory install 2>&1`; then
368 log "Error building the module:"
369 module_build_log "$myerr"
[63870]370 info "Look at $LOG to find out what went wrong"
[61206]371 fi
[65872]372 [ -d /etc/depmod.d ] || mkdir /etc/depmod.d
[64311]373 echo "override vboxguest * misc" > /etc/depmod.d/vboxvideo-upstream.conf
[64705]374 echo "override vboxsf * misc" >> /etc/depmod.d/vboxvideo-upstream.conf
375 echo "override vboxvideo * misc" >> /etc/depmod.d/vboxvideo-upstream.conf
[62844]376 depmod
[35200]377 return 0
378}
[24361]379
[66401]380create_vbox_user()
[35200]381{
[24361]382 # This is the LSB version of useradd and should work on recent
383 # distributions
384 useradd -d /var/run/vboxadd -g 1 -r -s /bin/false vboxadd >/dev/null 2>&1
385 # And for the others, we choose a UID ourselves
386 useradd -d /var/run/vboxadd -g 1 -u 501 -o -s /bin/false vboxadd >/dev/null 2>&1
387
[66401]388}
[31315]389
[66401]390create_udev_rule()
391{
[24361]392 # Create udev description file
393 if [ -d /etc/udev/rules.d ]; then
394 udev_call=""
395 udev_app=`which udevadm 2> /dev/null`
396 if [ $? -eq 0 ]; then
397 udev_call="${udev_app} version 2> /dev/null"
398 else
399 udev_app=`which udevinfo 2> /dev/null`
400 if [ $? -eq 0 ]; then
401 udev_call="${udev_app} -V 2> /dev/null"
402 fi
403 fi
404 udev_fix="="
405 if [ "${udev_call}" != "" ]; then
406 udev_out=`${udev_call}`
407 udev_ver=`expr "$udev_out" : '[^0-9]*\([0-9]*\)'`
408 if [ "$udev_ver" = "" -o "$udev_ver" -lt 55 ]; then
409 udev_fix=""
410 fi
411 fi
412 ## @todo 60-vboxadd.rules -> 60-vboxguest.rules ?
413 echo "KERNEL=${udev_fix}\"vboxguest\", NAME=\"vboxguest\", OWNER=\"vboxadd\", MODE=\"0660\"" > /etc/udev/rules.d/60-vboxadd.rules
414 echo "KERNEL=${udev_fix}\"vboxuser\", NAME=\"vboxuser\", OWNER=\"vboxadd\", MODE=\"0666\"" >> /etc/udev/rules.d/60-vboxadd.rules
415 fi
[66401]416}
[24361]417
[66401]418create_module_rebuild_script()
419{
[61199]420 # And a post-installation script for rebuilding modules when a new kernel
421 # is installed.
422 mkdir -p /etc/kernel/postinst.d /etc/kernel/prerm.d
423 cat << EOF > /etc/kernel/postinst.d/vboxadd
424#!/bin/sh
[61206]425test -d "/lib/modules/\${1}/build" || exit 0
[69086]426KERN_VER="\${1}" /sbin/rcvboxadd quicksetup
[61199]427exit 0
428EOF
429 cat << EOF > /etc/kernel/prerm.d/vboxadd
430#!/bin/sh
431for i in ${OLDMODULES}; do rm -f /lib/modules/"\${1}"/misc/"\${i}".ko; done
432rmdir -p /lib/modules/"\$1"/misc 2>/dev/null
433exit 0
434EOF
435 chmod 0755 /etc/kernel/postinst.d/vboxadd /etc/kernel/prerm.d/vboxadd
[66401]436}
437
438shared_folder_setup()
439{
440 # Add a group "vboxsf" for Shared Folders access
441 # All users which want to access the auto-mounted Shared Folders have to
442 # be added to this group.
443 groupadd -r -f vboxsf >/dev/null 2>&1
444
445 # Put the mount.vboxsf mount helper in the right place.
446 ## @todo It would be nicer if the kernel module just parsed parameters
447 # itself instead of needing a separate binary to do that.
448 ln -sf "${INSTALL_DIR}/other/mount.vboxsf" /sbin
[62394]449 # SELinux security context for the mount helper.
450 if test -e /etc/selinux/config; then
451 # This is correct. semanage maps this to the real path, and it aborts
452 # with an error, telling you what you should have typed, if you specify
[62749]453 # the real path. The "chcon" is there as a back-up for old guests.
454 command -v semanage > /dev/null &&
[63890]455 semanage fcontext -a -t mount_exec_t "${INSTALL_DIR}/other/mount.vboxsf"
456 chcon -t mount_exec_t "${INSTALL_DIR}/other/mount.vboxsf"
[62394]457 fi
[35200]458}
459
460# setup_script
461setup()
462{
[39358]463 export BUILD_TYPE
464 export USERNAME
465
466 MODULE_SRC="$INSTALL_DIR/src/vboxguest-$INSTALL_VER"
467 BUILDINTMP="$MODULE_SRC/build_in_tmp"
[39756]468 chcon -t bin_t "$BUILDINTMP" > /dev/null 2>&1
[39358]469
[66423]470 test -z "${INSTALL_NO_MODULE_BUILDS}" && setup_modules
[66401]471 create_vbox_user
472 create_udev_rule
[66423]473 test -z "${INSTALL_NO_MODULE_BUILDS}" && create_module_rebuild_script
[66401]474 test -n "${QUICKSETUP}" && return 0
475 shared_folder_setup
476 if running_vboxguest || running_vboxadd; then
477 info "Running kernel modules will not be replaced until the system is restarted"
[58820]478 fi
[66401]479 return 0
[15585]480}
481
[24361]482# cleanup_script
483cleanup()
484{
[66423]485 if test -z "${INSTALL_NO_MODULE_BUILDS}"; then
486 # Delete old versions of VBox modules.
487 cleanup_modules
488 depmod
[24361]489
[66423]490 # Remove old module sources
491 for i in $OLDMODULES; do
492 rm -rf /usr/src/$i-*
493 done
494 fi
[24531]495
[60103]496 # Clean-up X11-related bits
[72196]497 "${INSTALL_DIR}/init/vboxadd-x11" cleanup
[60103]498
[24361]499 # Remove other files
500 rm /sbin/mount.vboxsf 2>/dev/null
[66423]501 if test -z "${INSTALL_NO_MODULE_BUILDS}"; then
502 rm -f /etc/kernel/postinst.d/vboxadd /etc/kernel/prerm.d/vboxadd
503 rmdir -p /etc/kernel/postinst.d /etc/kernel/prerm.d 2>/dev/null
504 fi
[24402]505 rm /etc/udev/rules.d/60-vboxadd.rules 2>/dev/null
[24361]506}
507
[15585]508dmnstatus()
509{
[21412]510 if running_vboxguest; then
[1]511 echo "The VirtualBox Additions are currently running."
512 else
513 echo "The VirtualBox Additions are not currently running."
514 fi
515}
516
[63870]517case "$2" in quiet)
518 QUIET=yes;;
519esac
[1]520case "$1" in
521start)
522 start
523 ;;
524stop)
525 stop
526 ;;
527restart)
528 restart
529 ;;
[15585]530setup)
[66423]531 setup
[66401]532 start
[15585]533 ;;
[61199]534quicksetup)
535 QUICKSETUP=yes
[61206]536 setup
[61199]537 ;;
[66413]538cleanup)
[66423]539 cleanup
[66413]540 ;;
[1]541status)
542 dmnstatus
543 ;;
544*)
[66423]545 echo "Usage: $0 {start|stop|restart|status|setup|quicksetup|cleanup} [quiet]"
[1]546 exit 1
547esac
548
549exit
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use