VirtualBox

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

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

Linux Additions: do not try to remove kernel modules on clean-up.
bugref:3809: Linux installer maintenance

When we uninstall Linux Additions it is normally not possible to unload all
kernel modules. However we generally succeeded in removing vboxsf. When
upgrading this resulted in an error message when trying to load the new
version and further meant that shared folder functionality was guaranteed
not to be available until the next guest restart. This change drops the
unload attempt.

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

© 2023 Oracle
ContactPrivacy policyTerms of Use