[301] | 1 | #! /bin/sh
|
---|
[69327] | 2 | # $Id: vboxadd.sh 77328 2019-02-15 10:18:16Z vboxsync $
|
---|
| 3 | ## @file
|
---|
[21412] | 4 | # Linux Additions kernel module init script ($Revision: 77328 $)
|
---|
[1] | 5 | #
|
---|
[21412] | 6 |
|
---|
| 7 | #
|
---|
[76553] | 8 | # Copyright (C) 2006-2019 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 |
|
---|
[74579] | 53 | export LC_ALL=C
|
---|
[301] | 54 | PATH=$PATH:/bin:/sbin:/usr/sbin
|
---|
[24402] | 55 | PACKAGE=VBoxGuestAdditions
|
---|
[25687] | 56 | MODPROBE=/sbin/modprobe
|
---|
[39358] | 57 | OLDMODULES="vboxguest vboxadd vboxsf vboxvfs vboxvideo"
|
---|
[63870] | 58 | SERVICE="VirtualBox Guest Additions"
|
---|
| 59 | ## systemd logs information about service status, otherwise do that ourselves.
|
---|
| 60 | QUIET=
|
---|
[75839] | 61 | test -z "${TARGET_VER}" && TARGET_VER=`uname -r`
|
---|
| 62 | # Marker to ignore a particular kernel version which was already installed.
|
---|
| 63 | SKIPFILE_BASE=/var/lib/VBoxGuestAdditions/skip
|
---|
[77306] | 64 | export BUILD_TYPE
|
---|
| 65 | export USERNAME
|
---|
[301] | 66 |
|
---|
[68705] | 67 | setup_log()
|
---|
| 68 | {
|
---|
[75839] | 69 | test -z "${LOG}" || return 0
|
---|
[68705] | 70 | # Rotate log files
|
---|
| 71 | LOG="/var/log/vboxadd-setup.log"
|
---|
| 72 | mv "${LOG}.3" "${LOG}.4" 2>/dev/null
|
---|
| 73 | mv "${LOG}.2" "${LOG}.3" 2>/dev/null
|
---|
| 74 | mv "${LOG}.1" "${LOG}.2" 2>/dev/null
|
---|
| 75 | mv "${LOG}" "${LOG}.1" 2>/dev/null
|
---|
| 76 | }
|
---|
[63870] | 77 |
|
---|
[51193] | 78 | if $MODPROBE -c 2>/dev/null | grep -q '^allow_unsupported_modules *0'; then
|
---|
[25687] | 79 | MODPROBE="$MODPROBE --allow-unsupported-modules"
|
---|
| 80 | fi
|
---|
| 81 |
|
---|
[57945] | 82 | # Preamble for Gentoo
|
---|
| 83 | if [ "`which $0`" = "/sbin/rc" ]; then
|
---|
| 84 | shift
|
---|
[9108] | 85 | fi
|
---|
[1] | 86 |
|
---|
[57945] | 87 | begin()
|
---|
| 88 | {
|
---|
[75839] | 89 | test -n "${QUIET}" || echo "${SERVICE}: ${1}"
|
---|
[57945] | 90 | }
|
---|
[1] | 91 |
|
---|
[63870] | 92 | info()
|
---|
[57945] | 93 | {
|
---|
[63870] | 94 | if test -z "${QUIET}"; then
|
---|
[76912] | 95 | echo "${SERVICE}: $1" | fold -s
|
---|
[63870] | 96 | else
|
---|
[76912] | 97 | echo "$1" | fold -s
|
---|
[63870] | 98 | fi
|
---|
[57945] | 99 | }
|
---|
[9108] | 100 |
|
---|
[63870] | 101 | fail()
|
---|
[39358] | 102 | {
|
---|
[63870] | 103 | log "${1}"
|
---|
| 104 | echo "$1" >&2
|
---|
| 105 | echo "The log file $LOG may contain further information." >&2
|
---|
| 106 | exit 1
|
---|
[39358] | 107 | }
|
---|
| 108 |
|
---|
[63870] | 109 | log()
|
---|
[39358] | 110 | {
|
---|
[68705] | 111 | setup_log
|
---|
[63870] | 112 | echo "${1}" >> "${LOG}"
|
---|
[39358] | 113 | }
|
---|
| 114 |
|
---|
[72196] | 115 | module_build_log()
|
---|
| 116 | {
|
---|
[74412] | 117 | log "Error building the module. Build output follows."
|
---|
| 118 | echo ""
|
---|
| 119 | echo "${1}" >> "${LOG}"
|
---|
[72196] | 120 | }
|
---|
| 121 |
|
---|
[21412] | 122 | dev=/dev/vboxguest
|
---|
[17859] | 123 | userdev=/dev/vboxuser
|
---|
[39358] | 124 | config=/var/lib/VBoxGuestAdditions/config
|
---|
[6969] | 125 | owner=vboxadd
|
---|
| 126 | group=1
|
---|
[1] | 127 |
|
---|
[66401] | 128 | if test -r $config; then
|
---|
| 129 | . $config
|
---|
| 130 | else
|
---|
| 131 | fail "Configuration file $config not found"
|
---|
| 132 | fi
|
---|
| 133 | test -n "$INSTALL_DIR" -a -n "$INSTALL_VER" ||
|
---|
| 134 | fail "Configuration file $config not complete"
|
---|
[77306] | 135 | MODULE_SRC="$INSTALL_DIR/src/vboxguest-$INSTALL_VER"
|
---|
| 136 | BUILDINTMP="$MODULE_SRC/build_in_tmp"
|
---|
[66401] | 137 |
|
---|
[21412] | 138 | running_vboxguest()
|
---|
[15585] | 139 | {
|
---|
[21412] | 140 | lsmod | grep -q "vboxguest[^_-]"
|
---|
[1] | 141 | }
|
---|
| 142 |
|
---|
[24640] | 143 | running_vboxadd()
|
---|
| 144 | {
|
---|
| 145 | lsmod | grep -q "vboxadd[^_-]"
|
---|
| 146 | }
|
---|
| 147 |
|
---|
[28998] | 148 | running_vboxsf()
|
---|
[15585] | 149 | {
|
---|
[28998] | 150 | lsmod | grep -q "vboxsf[^_-]"
|
---|
[15585] | 151 | }
|
---|
| 152 |
|
---|
[43742] | 153 | running_vboxvideo()
|
---|
| 154 | {
|
---|
| 155 | lsmod | grep -q "vboxvideo[^_-]"
|
---|
| 156 | }
|
---|
| 157 |
|
---|
[35202] | 158 | do_vboxguest_non_udev()
|
---|
[15585] | 159 | {
|
---|
[1] | 160 | if [ ! -c $dev ]; then
|
---|
[21412] | 161 | maj=`sed -n 's;\([0-9]\+\) vboxguest;\1;p' /proc/devices`
|
---|
[423] | 162 | if [ ! -z "$maj" ]; then
|
---|
| 163 | min=0
|
---|
| 164 | else
|
---|
[21412] | 165 | min=`sed -n 's;\([0-9]\+\) vboxguest;\1;p' /proc/misc`
|
---|
[423] | 166 | if [ ! -z "$min" ]; then
|
---|
| 167 | maj=10
|
---|
| 168 | fi
|
---|
| 169 | fi
|
---|
[75839] | 170 | test -n "$maj" || {
|
---|
[21412] | 171 | rmmod vboxguest 2>/dev/null
|
---|
[9108] | 172 | fail "Cannot locate the VirtualBox device"
|
---|
[1] | 173 | }
|
---|
| 174 |
|
---|
[9108] | 175 | mknod -m 0664 $dev c $maj $min || {
|
---|
[21412] | 176 | rmmod vboxguest 2>/dev/null
|
---|
[9108] | 177 | fail "Cannot create device $dev with major $maj and minor $min"
|
---|
[1] | 178 | }
|
---|
| 179 | fi
|
---|
[18056] | 180 | chown $owner:$group $dev 2>/dev/null || {
|
---|
| 181 | rm -f $dev 2>/dev/null
|
---|
| 182 | rm -f $userdev 2>/dev/null
|
---|
[21412] | 183 | rmmod vboxguest 2>/dev/null
|
---|
[18056] | 184 | fail "Cannot change owner $owner:$group for device $dev"
|
---|
| 185 | }
|
---|
| 186 |
|
---|
[17859] | 187 | if [ ! -c $userdev ]; then
|
---|
[17950] | 188 | maj=10
|
---|
[17859] | 189 | min=`sed -n 's;\([0-9]\+\) vboxuser;\1;p' /proc/misc`
|
---|
| 190 | if [ ! -z "$min" ]; then
|
---|
[17950] | 191 | mknod -m 0666 $userdev c $maj $min || {
|
---|
| 192 | rm -f $dev 2>/dev/null
|
---|
[21412] | 193 | rmmod vboxguest 2>/dev/null
|
---|
[17950] | 194 | fail "Cannot create device $userdev with major $maj and minor $min"
|
---|
| 195 | }
|
---|
[18056] | 196 | chown $owner:$group $userdev 2>/dev/null || {
|
---|
| 197 | rm -f $dev 2>/dev/null
|
---|
| 198 | rm -f $userdev 2>/dev/null
|
---|
[21412] | 199 | rmmod vboxguest 2>/dev/null
|
---|
[18056] | 200 | fail "Cannot change owner $owner:$group for device $userdev"
|
---|
| 201 | }
|
---|
[17859] | 202 | fi
|
---|
| 203 | fi
|
---|
[35202] | 204 | }
|
---|
[6969] | 205 |
|
---|
[15585] | 206 | restart()
|
---|
| 207 | {
|
---|
[1] | 208 | stop && start
|
---|
| 209 | return 0
|
---|
| 210 | }
|
---|
| 211 |
|
---|
[74579] | 212 | ## Update the initramfs. Debian and Ubuntu put the graphics driver in, and
|
---|
| 213 | # need the touch(1) command below. Everyone else that I checked just need
|
---|
| 214 | # the right module alias file from depmod(1) and only use the initramfs to
|
---|
| 215 | # load the root filesystem, not the boot splash. update-initramfs works
|
---|
| 216 | # for the first two and dracut for every one else I checked. We are only
|
---|
| 217 | # interested in distributions recent enough to use the KMS vboxvideo driver.
|
---|
| 218 | update_initramfs()
|
---|
| 219 | {
|
---|
| 220 | ## kernel version to update for.
|
---|
| 221 | version="${1}"
|
---|
| 222 | depmod "${version}"
|
---|
| 223 | rm -f "/lib/modules/${version}/initrd/vboxvideo"
|
---|
[75839] | 224 | test ! -d "/lib/modules/${version}/initrd" ||
|
---|
| 225 | test ! -f "/lib/modules/${version}/misc/vboxvideo.ko" ||
|
---|
[74579] | 226 | touch "/lib/modules/${version}/initrd/vboxvideo"
|
---|
[74964] | 227 |
|
---|
| 228 | # Systems without systemd-inhibit probably don't need their initramfs
|
---|
| 229 | # rebuild here anyway.
|
---|
| 230 | type systemd-inhibit >/dev/null 2>&1 || return
|
---|
[74579] | 231 | if type dracut >/dev/null 2>&1; then
|
---|
[74964] | 232 | systemd-inhibit --why="Installing VirtualBox Guest Additions" \
|
---|
| 233 | dracut -f --kver "${version}"
|
---|
[74579] | 234 | elif type update-initramfs >/dev/null 2>&1; then
|
---|
[74964] | 235 | systemd-inhibit --why="Installing VirtualBox Guest Additions" \
|
---|
| 236 | update-initramfs -u -k "${version}"
|
---|
[74579] | 237 | fi
|
---|
| 238 | }
|
---|
| 239 |
|
---|
[35200] | 240 | # Remove any existing VirtualBox guest kernel modules from the disk, but not
|
---|
| 241 | # from the kernel as they may still be in use
|
---|
| 242 | cleanup_modules()
|
---|
[15585] | 243 | {
|
---|
[74579] | 244 | # Needed for Ubuntu and Debian, see update_initramfs
|
---|
| 245 | rm -f /lib/modules/*/initrd/vboxvideo
|
---|
| 246 | for i in /lib/modules/*/misc; do
|
---|
[75839] | 247 | KERN_VER="${i%/misc}"
|
---|
| 248 | KERN_VER="${KERN_VER#/lib/modules/}"
|
---|
[74579] | 249 | unset do_update
|
---|
| 250 | for j in ${OLDMODULES}; do
|
---|
| 251 | test -f "${i}/${j}.ko" && do_update=1 && rm -f "${i}/${j}.ko"
|
---|
| 252 | done
|
---|
[75839] | 253 | test -z "$do_update" || update_initramfs "$KERN_VER"
|
---|
[74579] | 254 | # Remove empty /lib/modules folders which may have been kept around
|
---|
| 255 | rmdir -p "${i}" 2>/dev/null || true
|
---|
| 256 | unset keep
|
---|
[75839] | 257 | for j in /lib/modules/"${KERN_VER}"/*; do
|
---|
[74579] | 258 | name="${j##*/}"
|
---|
| 259 | test -d "${name}" || test "${name%%.*}" != modules && keep=1
|
---|
| 260 | done
|
---|
| 261 | if test -z "${keep}"; then
|
---|
[75839] | 262 | rm -rf /lib/modules/"${KERN_VER}"
|
---|
| 263 | rm -f /boot/initrd.img-"${KERN_VER}"
|
---|
[74579] | 264 | fi
|
---|
| 265 | done
|
---|
[62676] | 266 | for i in ${OLDMODULES}; do
|
---|
| 267 | # We no longer support DKMS, remove any leftovers.
|
---|
[57969] | 268 | rm -rf "/var/lib/dkms/${i}"*
|
---|
| 269 | done
|
---|
[63738] | 270 | rm -f /etc/depmod.d/vboxvideo-upstream.conf
|
---|
[75839] | 271 | rm -f "$SKIPFILE_BASE"-*
|
---|
[35200] | 272 | }
|
---|
| 273 |
|
---|
| 274 | # Build and install the VirtualBox guest kernel modules
|
---|
| 275 | setup_modules()
|
---|
| 276 | {
|
---|
[75839] | 277 | KERN_VER="$1"
|
---|
| 278 | test -n "$KERN_VER" || return 1
|
---|
[77328] | 279 | # Match (at least): vboxguest.o; vboxguest.ko; vboxguest.ko.xz
|
---|
| 280 | set /lib/modules/"$KERN_VER"/misc/vboxguest.*o*
|
---|
| 281 | test ! -f "$1" || return 0
|
---|
[75839] | 282 | test -d /lib/modules/"$KERN_VER"/build || return 0
|
---|
| 283 | export KERN_VER
|
---|
| 284 | info "Building the modules for kernel $KERN_VER."
|
---|
[35200] | 285 |
|
---|
[75839] | 286 | log "Building the main Guest Additions module for kernel $KERN_VER."
|
---|
[72196] | 287 | if ! myerr=`$BUILDINTMP \
|
---|
[61206] | 288 | --save-module-symvers /tmp/vboxguest-Module.symvers \
|
---|
| 289 | --module-source $MODULE_SRC/vboxguest \
|
---|
[72196] | 290 | --no-print-directory install 2>&1`; then
|
---|
[64718] | 291 | # If check_module_dependencies.sh fails it prints a message itself.
|
---|
[72196] | 292 | module_build_log "$myerr"
|
---|
[64718] | 293 | "${INSTALL_DIR}"/other/check_module_dependencies.sh 2>&1 &&
|
---|
| 294 | info "Look at $LOG to find out what went wrong"
|
---|
[66401] | 295 | return 0
|
---|
[61206] | 296 | fi
|
---|
[72196] | 297 | log "Building the shared folder support module."
|
---|
| 298 | if ! myerr=`$BUILDINTMP \
|
---|
[61206] | 299 | --use-module-symvers /tmp/vboxguest-Module.symvers \
|
---|
| 300 | --module-source $MODULE_SRC/vboxsf \
|
---|
[72196] | 301 | --no-print-directory install 2>&1`; then
|
---|
| 302 | module_build_log "$myerr"
|
---|
[63870] | 303 | info "Look at $LOG to find out what went wrong"
|
---|
[66401] | 304 | return 0
|
---|
[61206] | 305 | fi
|
---|
[72196] | 306 | log "Building the graphics driver module."
|
---|
| 307 | if ! myerr=`$BUILDINTMP \
|
---|
[61206] | 308 | --use-module-symvers /tmp/vboxguest-Module.symvers \
|
---|
| 309 | --module-source $MODULE_SRC/vboxvideo \
|
---|
[72196] | 310 | --no-print-directory install 2>&1`; then
|
---|
| 311 | module_build_log "$myerr"
|
---|
[63870] | 312 | info "Look at $LOG to find out what went wrong"
|
---|
[61206] | 313 | fi
|
---|
[65872] | 314 | [ -d /etc/depmod.d ] || mkdir /etc/depmod.d
|
---|
[64311] | 315 | echo "override vboxguest * misc" > /etc/depmod.d/vboxvideo-upstream.conf
|
---|
[64705] | 316 | echo "override vboxsf * misc" >> /etc/depmod.d/vboxvideo-upstream.conf
|
---|
| 317 | echo "override vboxvideo * misc" >> /etc/depmod.d/vboxvideo-upstream.conf
|
---|
[74579] | 318 | update_initramfs "${KERN_VER}"
|
---|
[35200] | 319 | return 0
|
---|
| 320 | }
|
---|
[24361] | 321 |
|
---|
[66401] | 322 | create_vbox_user()
|
---|
[35200] | 323 | {
|
---|
[24361] | 324 | # This is the LSB version of useradd and should work on recent
|
---|
| 325 | # distributions
|
---|
[74579] | 326 | useradd -d /var/run/vboxadd -g 1 -r -s /bin/false vboxadd >/dev/null 2>&1 || true
|
---|
[24361] | 327 | # And for the others, we choose a UID ourselves
|
---|
[74579] | 328 | useradd -d /var/run/vboxadd -g 1 -u 501 -o -s /bin/false vboxadd >/dev/null 2>&1 || true
|
---|
[24361] | 329 |
|
---|
[66401] | 330 | }
|
---|
[31315] | 331 |
|
---|
[66401] | 332 | create_udev_rule()
|
---|
| 333 | {
|
---|
[24361] | 334 | # Create udev description file
|
---|
| 335 | if [ -d /etc/udev/rules.d ]; then
|
---|
| 336 | udev_call=""
|
---|
| 337 | udev_app=`which udevadm 2> /dev/null`
|
---|
| 338 | if [ $? -eq 0 ]; then
|
---|
| 339 | udev_call="${udev_app} version 2> /dev/null"
|
---|
| 340 | else
|
---|
| 341 | udev_app=`which udevinfo 2> /dev/null`
|
---|
| 342 | if [ $? -eq 0 ]; then
|
---|
| 343 | udev_call="${udev_app} -V 2> /dev/null"
|
---|
| 344 | fi
|
---|
| 345 | fi
|
---|
| 346 | udev_fix="="
|
---|
| 347 | if [ "${udev_call}" != "" ]; then
|
---|
| 348 | udev_out=`${udev_call}`
|
---|
| 349 | udev_ver=`expr "$udev_out" : '[^0-9]*\([0-9]*\)'`
|
---|
| 350 | if [ "$udev_ver" = "" -o "$udev_ver" -lt 55 ]; then
|
---|
| 351 | udev_fix=""
|
---|
| 352 | fi
|
---|
| 353 | fi
|
---|
| 354 | ## @todo 60-vboxadd.rules -> 60-vboxguest.rules ?
|
---|
| 355 | echo "KERNEL=${udev_fix}\"vboxguest\", NAME=\"vboxguest\", OWNER=\"vboxadd\", MODE=\"0660\"" > /etc/udev/rules.d/60-vboxadd.rules
|
---|
| 356 | echo "KERNEL=${udev_fix}\"vboxuser\", NAME=\"vboxuser\", OWNER=\"vboxadd\", MODE=\"0666\"" >> /etc/udev/rules.d/60-vboxadd.rules
|
---|
| 357 | fi
|
---|
[66401] | 358 | }
|
---|
[24361] | 359 |
|
---|
[75963] | 360 | create_module_rebuild_script()
|
---|
| 361 | {
|
---|
| 362 | # And a post-installation script for rebuilding modules when a new kernel
|
---|
| 363 | # is installed.
|
---|
| 364 | mkdir -p /etc/kernel/postinst.d /etc/kernel/prerm.d
|
---|
| 365 | cat << EOF > /etc/kernel/postinst.d/vboxadd
|
---|
| 366 | #!/bin/sh
|
---|
| 367 | # This only works correctly on Debian derivatives - Red Hat calls it before
|
---|
| 368 | # installing the right header files.
|
---|
| 369 | /sbin/rcvboxadd quicksetup "\${1}"
|
---|
| 370 | exit 0
|
---|
| 371 | EOF
|
---|
| 372 | cat << EOF > /etc/kernel/prerm.d/vboxadd
|
---|
| 373 | #!/bin/sh
|
---|
| 374 | for i in ${OLDMODULES}; do rm -f /lib/modules/"\${1}"/misc/"\${i}".ko; done
|
---|
[77306] | 375 | rmdir -p /lib/modules/"\$1"/misc 2>/dev/null || true
|
---|
[75963] | 376 | exit 0
|
---|
| 377 | EOF
|
---|
| 378 | chmod 0755 /etc/kernel/postinst.d/vboxadd /etc/kernel/prerm.d/vboxadd
|
---|
| 379 | }
|
---|
| 380 |
|
---|
[66401] | 381 | shared_folder_setup()
|
---|
| 382 | {
|
---|
| 383 | # Add a group "vboxsf" for Shared Folders access
|
---|
| 384 | # All users which want to access the auto-mounted Shared Folders have to
|
---|
| 385 | # be added to this group.
|
---|
| 386 | groupadd -r -f vboxsf >/dev/null 2>&1
|
---|
| 387 |
|
---|
| 388 | # Put the mount.vboxsf mount helper in the right place.
|
---|
| 389 | ## @todo It would be nicer if the kernel module just parsed parameters
|
---|
| 390 | # itself instead of needing a separate binary to do that.
|
---|
| 391 | ln -sf "${INSTALL_DIR}/other/mount.vboxsf" /sbin
|
---|
[62394] | 392 | # SELinux security context for the mount helper.
|
---|
| 393 | if test -e /etc/selinux/config; then
|
---|
| 394 | # This is correct. semanage maps this to the real path, and it aborts
|
---|
| 395 | # with an error, telling you what you should have typed, if you specify
|
---|
[62749] | 396 | # the real path. The "chcon" is there as a back-up for old guests.
|
---|
| 397 | command -v semanage > /dev/null &&
|
---|
[63890] | 398 | semanage fcontext -a -t mount_exec_t "${INSTALL_DIR}/other/mount.vboxsf"
|
---|
[77049] | 399 | chcon -t mount_exec_t "${INSTALL_DIR}/other/mount.vboxsf" 2>/dev/null
|
---|
[62394] | 400 | fi
|
---|
[35200] | 401 | }
|
---|
| 402 |
|
---|
| 403 | # setup_script
|
---|
| 404 | setup()
|
---|
| 405 | {
|
---|
[77049] | 406 | # chcon is needed on old Fedora/Redhat systems. No one remembers which.
|
---|
[75839] | 407 | test ! -e /etc/selinux/config ||
|
---|
[77049] | 408 | chcon -t bin_t "$BUILDINTMP" 2>/dev/null
|
---|
[39358] | 409 |
|
---|
[75839] | 410 | if test -z "$INSTALL_NO_MODULE_BUILDS"; then
|
---|
[77306] | 411 | info "Building the VirtualBox Guest Additions kernel modules. This may take a while."
|
---|
| 412 | info "To build modules for other installed kernels, run"
|
---|
| 413 | info " /sbin/rcvboxadd quicksetup <version>"
|
---|
| 414 | info "or"
|
---|
| 415 | info " /sbin/rcvboxadd quicksetup all"
|
---|
| 416 | if test -d /lib/modules/"$TARGET_VER"/build; then
|
---|
| 417 | setup_modules "$TARGET_VER"
|
---|
| 418 | depmod
|
---|
| 419 | else
|
---|
[76912] | 420 | info "Kernel headers not found for target kernel $TARGET_VER. \
|
---|
| 421 | Please install them and execute
|
---|
| 422 | /sbin/rcvboxadd setup"
|
---|
[77306] | 423 | fi
|
---|
[75839] | 424 | fi
|
---|
[66401] | 425 | create_vbox_user
|
---|
| 426 | create_udev_rule
|
---|
[75963] | 427 | test -n "${INSTALL_NO_MODULE_BUILDS}" || create_module_rebuild_script
|
---|
[66401] | 428 | shared_folder_setup
|
---|
| 429 | if running_vboxguest || running_vboxadd; then
|
---|
| 430 | info "Running kernel modules will not be replaced until the system is restarted"
|
---|
[58820] | 431 | fi
|
---|
[77306] | 432 |
|
---|
| 433 | # Put the X.Org driver in place. This is harmless if it is not needed.
|
---|
| 434 | # Also set up the OpenGL library.
|
---|
| 435 | myerr=`"${INSTALL_DIR}/init/vboxadd-x11" setup 2>&1`
|
---|
| 436 | test -z "${myerr}" || log "${myerr}"
|
---|
| 437 |
|
---|
[66401] | 438 | return 0
|
---|
[15585] | 439 | }
|
---|
| 440 |
|
---|
[24361] | 441 | # cleanup_script
|
---|
| 442 | cleanup()
|
---|
| 443 | {
|
---|
[66423] | 444 | if test -z "${INSTALL_NO_MODULE_BUILDS}"; then
|
---|
| 445 | # Delete old versions of VBox modules.
|
---|
| 446 | cleanup_modules
|
---|
| 447 | depmod
|
---|
[24361] | 448 |
|
---|
[66423] | 449 | # Remove old module sources
|
---|
| 450 | for i in $OLDMODULES; do
|
---|
| 451 | rm -rf /usr/src/$i-*
|
---|
| 452 | done
|
---|
| 453 | fi
|
---|
[24531] | 454 |
|
---|
[60103] | 455 | # Clean-up X11-related bits
|
---|
[72196] | 456 | "${INSTALL_DIR}/init/vboxadd-x11" cleanup
|
---|
[60103] | 457 |
|
---|
[24361] | 458 | # Remove other files
|
---|
[75963] | 459 | if test -z "${INSTALL_NO_MODULE_BUILDS}"; then
|
---|
| 460 | rm -f /etc/kernel/postinst.d/vboxadd /etc/kernel/prerm.d/vboxadd
|
---|
[77306] | 461 | rmdir -p /etc/kernel/postinst.d /etc/kernel/prerm.d 2>/dev/null || true
|
---|
[75963] | 462 | fi
|
---|
[77306] | 463 | rm -f /sbin/mount.vboxsf 2>/dev/null
|
---|
| 464 | rm -f /etc/udev/rules.d/60-vboxadd.rules 2>/dev/null
|
---|
[24361] | 465 | }
|
---|
| 466 |
|
---|
[77306] | 467 | start()
|
---|
| 468 | {
|
---|
| 469 | begin "Starting."
|
---|
| 470 | if test -z "${INSTALL_NO_MODULE_BUILDS}"; then
|
---|
| 471 | # We want to build modules for newly installed kernels on shutdown, so
|
---|
| 472 | # mark the ones already present. These will be ignored on shutdown.
|
---|
| 473 | rm -f "$SKIPFILE_BASE"-*
|
---|
| 474 | for setupi in /lib/modules/*; do
|
---|
| 475 | KERN_VER="${setupi##*/}"
|
---|
| 476 | # For a full setup, mark kernels we do not want to build.
|
---|
| 477 | touch "$SKIPFILE_BASE"-"$KERN_VER"
|
---|
| 478 | done
|
---|
| 479 | fi
|
---|
| 480 | setup
|
---|
| 481 | if test -z "${INSTALL_NO_MODULE_BUILDS}"; then
|
---|
| 482 | test -d /sys &&
|
---|
| 483 | ps -A -o comm | grep -q '/*udevd$' 2>/dev/null ||
|
---|
| 484 | no_udev=1
|
---|
| 485 | running_vboxguest || {
|
---|
| 486 | rm -f $dev || {
|
---|
| 487 | fail "Cannot remove $dev"
|
---|
| 488 | }
|
---|
| 489 | rm -f $userdev || {
|
---|
| 490 | fail "Cannot remove $userdev"
|
---|
| 491 | }
|
---|
| 492 | $MODPROBE vboxguest >/dev/null 2>&1 ||
|
---|
| 493 | fail "modprobe vboxguest failed"
|
---|
| 494 | case "$no_udev" in 1)
|
---|
| 495 | sleep .5;;
|
---|
| 496 | esac
|
---|
| 497 | $MODPROBE vboxsf > /dev/null 2>&1 ||
|
---|
| 498 | info "modprobe vboxsf failed"
|
---|
| 499 | }
|
---|
| 500 | case "$no_udev" in 1)
|
---|
| 501 | do_vboxguest_non_udev;;
|
---|
| 502 | esac
|
---|
| 503 | fi # INSTALL_NO_MODULE_BUILDS
|
---|
| 504 |
|
---|
| 505 | return 0
|
---|
| 506 | }
|
---|
| 507 |
|
---|
| 508 | stop()
|
---|
| 509 | {
|
---|
| 510 | begin "Stopping."
|
---|
| 511 | if test -z "${INSTALL_NO_MODULE_BUILDS}"; then
|
---|
| 512 | # We want to build modules for newly installed kernels on shutdown, so
|
---|
| 513 | # check which we marked at start-up.
|
---|
| 514 | for setupi in /lib/modules/*; do
|
---|
| 515 | KERN_VER="${setupi##*/}"
|
---|
| 516 | # For a full setup, mark kernels we do not want to build.
|
---|
| 517 | test -f "$SKIPFILE_BASE"-"$KERN_VER" || setup_modules "$KERN_VER"
|
---|
| 518 | done
|
---|
| 519 | fi
|
---|
| 520 | if test -r /etc/ld.so.conf.d/00vboxvideo.conf; then
|
---|
| 521 | rm /etc/ld.so.conf.d/00vboxvideo.conf
|
---|
| 522 | ldconfig
|
---|
| 523 | fi
|
---|
| 524 | if ! umount -a -t vboxsf 2>/dev/null; then
|
---|
| 525 | fail "Cannot unmount vboxsf folders"
|
---|
| 526 | fi
|
---|
| 527 | test -n "${INSTALL_NO_MODULE_BUILDS}" ||
|
---|
| 528 | info "You may need to restart your guest system to finish removing guest drivers."
|
---|
| 529 | return 0
|
---|
| 530 | }
|
---|
| 531 |
|
---|
[15585] | 532 | dmnstatus()
|
---|
| 533 | {
|
---|
[21412] | 534 | if running_vboxguest; then
|
---|
[1] | 535 | echo "The VirtualBox Additions are currently running."
|
---|
| 536 | else
|
---|
| 537 | echo "The VirtualBox Additions are not currently running."
|
---|
| 538 | fi
|
---|
| 539 | }
|
---|
| 540 |
|
---|
[77306] | 541 | for i; do
|
---|
| 542 | case "$i" in quiet) QUIET=yes;; esac
|
---|
| 543 | done
|
---|
[1] | 544 | case "$1" in
|
---|
[77306] | 545 | # Does setup without clean-up first and marks all kernels currently found on the
|
---|
| 546 | # system so that we can see later if any were added.
|
---|
[1] | 547 | start)
|
---|
| 548 | start
|
---|
| 549 | ;;
|
---|
[77306] | 550 | # Tries to build kernel modules for kernels added since start. Tries to unmount
|
---|
| 551 | # shared folders. Uninstalls our Chromium 3D libraries since we can't always do
|
---|
| 552 | # this fast enough at start time if we discover we do not want to use them.
|
---|
[1] | 553 | stop)
|
---|
| 554 | stop
|
---|
| 555 | ;;
|
---|
| 556 | restart)
|
---|
| 557 | restart
|
---|
| 558 | ;;
|
---|
[77306] | 559 | # Setup does a clean-up (see below) and re-does all Additions-specific
|
---|
| 560 | # configuration of the guest system, including building kernel modules for the
|
---|
| 561 | # current kernel.
|
---|
[15585] | 562 | setup)
|
---|
[77306] | 563 | cleanup && start
|
---|
[15585] | 564 | ;;
|
---|
[77306] | 565 | # Builds kernel modules for the specified kernels if they are not already built.
|
---|
[61199] | 566 | quicksetup)
|
---|
[77306] | 567 | if test x"$2" = xall; then
|
---|
[77307] | 568 | for topi in /lib/modules/*; do
|
---|
| 569 | KERN_VER="${topi%/misc}"
|
---|
[77306] | 570 | KERN_VER="${KERN_VER#/lib/modules/}"
|
---|
| 571 | setup_modules "$KERN_VER"
|
---|
| 572 | done
|
---|
| 573 | elif test -n "$2"; then
|
---|
| 574 | setup_modules "$2"
|
---|
| 575 | else
|
---|
| 576 | setup_modules "$TARGET_VER"
|
---|
| 577 | fi
|
---|
[61199] | 578 | ;;
|
---|
[77306] | 579 | # Clean-up removes all Additions-specific configuration of the guest system,
|
---|
| 580 | # including all kernel modules.
|
---|
[66413] | 581 | cleanup)
|
---|
[66423] | 582 | cleanup
|
---|
[66413] | 583 | ;;
|
---|
[1] | 584 | status)
|
---|
| 585 | dmnstatus
|
---|
| 586 | ;;
|
---|
| 587 | *)
|
---|
[66423] | 588 | echo "Usage: $0 {start|stop|restart|status|setup|quicksetup|cleanup} [quiet]"
|
---|
[1] | 589 | exit 1
|
---|
| 590 | esac
|
---|
| 591 |
|
---|
| 592 | exit
|
---|