VirtualBox

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

Last change on this file since 64656 was 64311, checked in by vboxsync, 8 years ago

bugref:8087: Additions/x11: support non-root X server: do not only prefer our vboxvideo kernel driver but also prefer our vboxguest and vboxsf kernel driver

  • Property svn:eol-style set to LF
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 15.2 KB
Line 
1#! /bin/sh
2#
3# Linux Additions kernel module init script ($Revision: 64311 $)
4#
5
6#
7# Copyright (C) 2006-2012 Oracle Corporation
8#
9# This file is part of VirtualBox Open Source Edition (OSE), as
10# available from http://www.virtualbox.org. This file is free software;
11# you can redistribute it and/or modify it under the terms of the GNU
12# General Public License (GPL) as published by the Free Software
13# Foundation, in version 2 as it comes in the "COPYING" file of the
14# VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15# hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16#
17
18
19# chkconfig: 345 10 90
20# description: VirtualBox Linux Additions kernel modules
21#
22### BEGIN INIT INFO
23# Provides: vboxadd
24# Required-Start:
25# Required-Stop:
26# Default-Start: 2 3 4 5
27# Default-Stop: 0 1 6
28# Description: VirtualBox Linux Additions kernel modules
29### END INIT INFO
30
31## @todo This file duplicates a lot of script with vboxdrv.sh. When making
32# changes please try to reduce differences between the two wherever possible.
33
34PATH=$PATH:/bin:/sbin:/usr/sbin
35PACKAGE=VBoxGuestAdditions
36LOG="/var/log/vboxadd-setup.log"
37MODPROBE=/sbin/modprobe
38OLDMODULES="vboxguest vboxadd vboxsf vboxvfs vboxvideo"
39SERVICE="VirtualBox Guest Additions"
40QUICKSETUP=
41## systemd logs information about service status, otherwise do that ourselves.
42QUIET=
43
44# Rotate log files
45mv "${LOG}.3" "${LOG}.4" 2>/dev/null
46mv "${LOG}.2" "${LOG}.3" 2>/dev/null
47mv "${LOG}.1" "${LOG}.2" 2>/dev/null
48mv "${LOG}" "${LOG}.1" 2>/dev/null
49
50if $MODPROBE -c 2>/dev/null | grep -q '^allow_unsupported_modules *0'; then
51 MODPROBE="$MODPROBE --allow-unsupported-modules"
52fi
53
54# Check architecture
55cpu=`uname -m`;
56case "$cpu" in
57 i[3456789]86|x86)
58 cpu="x86"
59 ldconfig_arch="(libc6)"
60 lib_candidates="/usr/lib/i386-linux-gnu /usr/lib /lib"
61 ;;
62 x86_64|amd64)
63 cpu="amd64"
64 ldconfig_arch="(libc6,x86-64)"
65 lib_candidates="/usr/lib/x86_64-linux-gnu /usr/lib64 /usr/lib /lib64 /lib"
66 ;;
67esac
68for i in $lib_candidates; do
69 if test -d "$i/VBoxGuestAdditions"; then
70 lib_path=$i
71 break
72 fi
73done
74
75# Preamble for Gentoo
76if [ "`which $0`" = "/sbin/rc" ]; then
77 shift
78fi
79
80begin()
81{
82 test -z "${QUIET}" && echo "${SERVICE}: ${1}"
83}
84
85info()
86{
87 if test -z "${QUIET}"; then
88 echo "${SERVICE}: $1"
89 else
90 echo "$1"
91 fi
92}
93
94fail()
95{
96 log "${1}"
97 echo "$1" >&2
98 echo "The log file $LOG may contain further information." >&2
99 exit 1
100}
101
102log()
103{
104 echo "${1}" >> "${LOG}"
105}
106
107dev=/dev/vboxguest
108userdev=/dev/vboxuser
109config=/var/lib/VBoxGuestAdditions/config
110owner=vboxadd
111group=1
112
113running_vboxguest()
114{
115 lsmod | grep -q "vboxguest[^_-]"
116}
117
118running_vboxadd()
119{
120 lsmod | grep -q "vboxadd[^_-]"
121}
122
123running_vboxsf()
124{
125 lsmod | grep -q "vboxsf[^_-]"
126}
127
128running_vboxvideo()
129{
130 lsmod | grep -q "vboxvideo[^_-]"
131}
132
133do_vboxguest_non_udev()
134{
135 if [ ! -c $dev ]; then
136 maj=`sed -n 's;\([0-9]\+\) vboxguest;\1;p' /proc/devices`
137 if [ ! -z "$maj" ]; then
138 min=0
139 else
140 min=`sed -n 's;\([0-9]\+\) vboxguest;\1;p' /proc/misc`
141 if [ ! -z "$min" ]; then
142 maj=10
143 fi
144 fi
145 test -z "$maj" && {
146 rmmod vboxguest 2>/dev/null
147 fail "Cannot locate the VirtualBox device"
148 }
149
150 mknod -m 0664 $dev c $maj $min || {
151 rmmod vboxguest 2>/dev/null
152 fail "Cannot create device $dev with major $maj and minor $min"
153 }
154 fi
155 chown $owner:$group $dev 2>/dev/null || {
156 rm -f $dev 2>/dev/null
157 rm -f $userdev 2>/dev/null
158 rmmod vboxguest 2>/dev/null
159 fail "Cannot change owner $owner:$group for device $dev"
160 }
161
162 if [ ! -c $userdev ]; then
163 maj=10
164 min=`sed -n 's;\([0-9]\+\) vboxuser;\1;p' /proc/misc`
165 if [ ! -z "$min" ]; then
166 mknod -m 0666 $userdev c $maj $min || {
167 rm -f $dev 2>/dev/null
168 rmmod vboxguest 2>/dev/null
169 fail "Cannot create device $userdev with major $maj and minor $min"
170 }
171 chown $owner:$group $userdev 2>/dev/null || {
172 rm -f $dev 2>/dev/null
173 rm -f $userdev 2>/dev/null
174 rmmod vboxguest 2>/dev/null
175 fail "Cannot change owner $owner:$group for device $userdev"
176 }
177 fi
178 fi
179}
180
181start()
182{
183 begin "Starting."
184 # If we got this far assume that the slow set-up has been done.
185 QUICKSETUP=yes
186 if test -r $config; then
187 . $config
188 else
189 fail "Configuration file $config not found"
190 fi
191 test -n "$INSTALL_DIR" -a -n "$INSTALL_VER" ||
192 fail "Configuration file $config not complete"
193 uname -r | grep -q -E '^2\.6|^3|^4' 2>/dev/null &&
194 ps -A -o comm | grep -q '/*udevd$' 2>/dev/null ||
195 no_udev=1
196 running_vboxguest || {
197 rm -f $dev || {
198 fail "Cannot remove $dev"
199 }
200
201 rm -f $userdev || {
202 fail "Cannot remove $userdev"
203 }
204
205 $MODPROBE vboxguest >/dev/null 2>&1 || {
206 setup
207 $MODPROBE vboxguest >/dev/null 2>&1 || {
208 "${INSTALL_DIR}/init/vboxadd-x11" cleanup 2>> "${LOG}"
209 fail "modprobe vboxguest failed"
210 }
211 }
212 case "$no_udev" in 1)
213 sleep .5;;
214 esac
215 }
216 case "$no_udev" in 1)
217 do_vboxguest_non_udev;;
218 esac
219
220 running_vboxsf || {
221 $MODPROBE vboxsf > /dev/null 2>&1 || {
222 if dmesg | grep "VbglR0SfConnect failed" > /dev/null 2>&1; then
223 info "Unable to start shared folders support. Make sure that your VirtualBox build supports this feature."
224 else
225 info "modprobe vboxsf failed"
226 fi
227 }
228 }
229
230 # Put the X.Org driver in place. This is harmless if it is not needed.
231 "${INSTALL_DIR}/init/vboxadd-x11" setup 2>> "${LOG}"
232 # Install the guest OpenGL drivers. For now we don't support
233 # multi-architecture installations
234 rm -f /etc/ld.so.conf.d/00vboxvideo.conf
235 if /usr/bin/VBoxClient --check3d 2>/dev/null; then
236 mkdir -p /var/lib/VBoxGuestAdditions/lib
237 ln -sf "${INSTALL_DIR}/lib/VBoxOGL.so" /var/lib/VBoxGuestAdditions/lib/libGL.so.1
238 ln -sf "${INSTALL_DIR}/lib/VBoxEGL.so" /var/lib/VBoxGuestAdditions/lib/libEGL.so.1
239 # SELinux for the OpenGL libraries, so that gdm can load them during the
240 # acceleration support check. This prevents an "Oh no, something has gone
241 # wrong!" error when starting EL7 guests.
242 if test -e /etc/selinux/config; then
243 if command -v semanage > /dev/null; then
244 semanage fcontext -a -t lib_t "/var/lib/VBoxGuestAdditions/lib/libGL.so.1"
245 semanage fcontext -a -t lib_t "/var/lib/VBoxGuestAdditions/lib/libEGL.so.1"
246 fi
247 chcon -h -t lib_t "/var/lib/VBoxGuestAdditions/lib/libGL.so.1"
248 chcon -h -t lib_t "/var/lib/VBoxGuestAdditions/lib/libEGL.so.1"
249 fi
250 echo "/var/lib/VBoxGuestAdditions/lib" > /etc/ld.so.conf.d/00vboxvideo.conf
251 fi
252 ldconfig
253
254 # Mount all shared folders from /etc/fstab. Normally this is done by some
255 # other startup script but this requires the vboxdrv kernel module loaded.
256 # This isn't necessary anymore as the vboxsf module is autoloaded.
257 # mount -a -t vboxsf
258
259 return 0
260}
261
262stop()
263{
264 begin "Stopping."
265 if test -r /etc/ld.so.conf.d/00vboxvideo.conf; then
266 rm /etc/ld.so.conf.d/00vboxvideo.conf
267 ldconfig
268 fi
269 if ! umount -a -t vboxsf 2>/dev/null; then
270 fail "Cannot unmount vboxsf folders"
271 fi
272 modprobe -q -r -a vboxvideo vboxsf vboxguest
273 egrep -q 'vboxguest|vboxsf|vboxvideo' /proc/modules &&
274 info "You may need to restart your guest system to finish removing the guest drivers."
275 rm -f $userdev || fail "Cannot unlink $userdev"
276 rm -f $dev || fail "Cannot unlink $dev"
277 return 0
278}
279
280restart()
281{
282 stop && start
283 return 0
284}
285
286# Remove any existing VirtualBox guest kernel modules from the disk, but not
287# from the kernel as they may still be in use
288cleanup_modules()
289{
290 log "Removing existing VirtualBox kernel modules."
291 for i in ${OLDMODULES}; do
292 # We no longer support DKMS, remove any leftovers.
293 rm -rf "/var/lib/dkms/${i}"*
294 # And remove old modules.
295 rm -f /lib/modules/*/misc/"${i}"*
296 done
297 # Remove leftover module folders.
298 for i in /lib/modules/*/misc; do
299 test -d "${i}" && rmdir -p "${i}" 2>/dev/null
300 done
301 rm -f /etc/depmod.d/vboxvideo-upstream.conf
302}
303
304# Build and install the VirtualBox guest kernel modules
305setup_modules()
306{
307 # don't stop the old modules here -- they might be in use
308 test -z "${QUICKSETUP}" && cleanup_modules
309 # This does not work for 2.4 series kernels. How sad.
310 test -n "${QUICKSETUP}" && test -f "${MODULE_DIR}/vboxguest.ko" && return 0
311 info "Building the VirtualBox Guest Additions kernel modules."
312
313 log "Building the main Guest Additions module."
314 if ! $BUILDINTMP \
315 --save-module-symvers /tmp/vboxguest-Module.symvers \
316 --module-source $MODULE_SRC/vboxguest \
317 --no-print-directory install >> $LOG 2>&1; then
318 info "Look at $LOG to find out what went wrong"
319 return 1
320 fi
321 log "Building the shared folder support module"
322 if ! $BUILDINTMP \
323 --use-module-symvers /tmp/vboxguest-Module.symvers \
324 --module-source $MODULE_SRC/vboxsf \
325 --no-print-directory install >> $LOG 2>&1; then
326 info "Look at $LOG to find out what went wrong"
327 return 1
328 fi
329 log "Building the graphics driver module"
330 if ! $BUILDINTMP \
331 --use-module-symvers /tmp/vboxguest-Module.symvers \
332 --module-source $MODULE_SRC/vboxvideo \
333 --no-print-directory install >> $LOG 2>&1; then
334 info "Look at $LOG to find out what went wrong"
335 fi
336 echo "override vboxguest * misc" > /etc/depmod.d/vboxvideo-upstream.conf
337 echo "override vboxsf * misc" > /etc/depmod.d/vboxvideo-upstream.conf
338 echo "override vboxvideo * misc" > /etc/depmod.d/vboxvideo-upstream.conf
339 depmod
340 return 0
341}
342
343# Do non-kernel bits needed for the kernel modules to work properly (user
344# creation, udev, mount helper...)
345extra_setup()
346{
347 log "Creating user for the Guest Additions."
348 # This is the LSB version of useradd and should work on recent
349 # distributions
350 useradd -d /var/run/vboxadd -g 1 -r -s /bin/false vboxadd >/dev/null 2>&1
351 # And for the others, we choose a UID ourselves
352 useradd -d /var/run/vboxadd -g 1 -u 501 -o -s /bin/false vboxadd >/dev/null 2>&1
353
354 # Add a group "vboxsf" for Shared Folders access
355 # All users which want to access the auto-mounted Shared Folders have to
356 # be added to this group.
357 groupadd -r -f vboxsf >/dev/null 2>&1
358
359 # Create udev description file
360 if [ -d /etc/udev/rules.d ]; then
361 log "Creating udev rule for the Guest Additions kernel module."
362 udev_call=""
363 udev_app=`which udevadm 2> /dev/null`
364 if [ $? -eq 0 ]; then
365 udev_call="${udev_app} version 2> /dev/null"
366 else
367 udev_app=`which udevinfo 2> /dev/null`
368 if [ $? -eq 0 ]; then
369 udev_call="${udev_app} -V 2> /dev/null"
370 fi
371 fi
372 udev_fix="="
373 if [ "${udev_call}" != "" ]; then
374 udev_out=`${udev_call}`
375 udev_ver=`expr "$udev_out" : '[^0-9]*\([0-9]*\)'`
376 if [ "$udev_ver" = "" -o "$udev_ver" -lt 55 ]; then
377 udev_fix=""
378 fi
379 fi
380 ## @todo 60-vboxadd.rules -> 60-vboxguest.rules ?
381 echo "KERNEL=${udev_fix}\"vboxguest\", NAME=\"vboxguest\", OWNER=\"vboxadd\", MODE=\"0660\"" > /etc/udev/rules.d/60-vboxadd.rules
382 echo "KERNEL=${udev_fix}\"vboxuser\", NAME=\"vboxuser\", OWNER=\"vboxadd\", MODE=\"0666\"" >> /etc/udev/rules.d/60-vboxadd.rules
383 fi
384
385 # Put mount.vboxsf in the right place
386 ln -sf "${INSTALL_DIR}/other/mount.vboxsf" /sbin
387 # And a post-installation script for rebuilding modules when a new kernel
388 # is installed.
389 mkdir -p /etc/kernel/postinst.d /etc/kernel/prerm.d
390 cat << EOF > /etc/kernel/postinst.d/vboxadd
391#!/bin/sh
392test -d "/lib/modules/\${1}/build" || exit 0
393KERN_DIR="/lib/modules/\${1}/build" MODULE_DIR="/lib/modules/\${1}/misc" \
394/sbin/rcvboxadd quicksetup
395exit 0
396EOF
397 cat << EOF > /etc/kernel/prerm.d/vboxadd
398#!/bin/sh
399for i in ${OLDMODULES}; do rm -f /lib/modules/"\${1}"/misc/"\${i}".ko; done
400rmdir -p /lib/modules/"\$1"/misc 2>/dev/null
401exit 0
402EOF
403 chmod 0755 /etc/kernel/postinst.d/vboxadd /etc/kernel/prerm.d/vboxadd
404 # SELinux security context for the mount helper.
405 if test -e /etc/selinux/config; then
406 # This is correct. semanage maps this to the real path, and it aborts
407 # with an error, telling you what you should have typed, if you specify
408 # the real path. The "chcon" is there as a back-up for old guests.
409 command -v semanage > /dev/null &&
410 semanage fcontext -a -t mount_exec_t "${INSTALL_DIR}/other/mount.vboxsf"
411 chcon -t mount_exec_t "${INSTALL_DIR}/other/mount.vboxsf"
412 fi
413}
414
415# setup_script
416setup()
417{
418 if test -r $config; then
419 . $config
420 else
421 fail "Configuration file $config not found"
422 fi
423 test -n "$INSTALL_DIR" -a -n "$INSTALL_VER" ||
424 fail "Configuration file $config not complete"
425 export BUILD_TYPE
426 export USERNAME
427
428 MODULE_SRC="$INSTALL_DIR/src/vboxguest-$INSTALL_VER"
429 BUILDINTMP="$MODULE_SRC/build_in_tmp"
430 chcon -t bin_t "$BUILDINTMP" > /dev/null 2>&1
431
432 if setup_modules; then
433 mod_succ=0
434 else
435 mod_succ=1
436 info "Please check that you have gcc, make, the header files for your Linux kernel and possibly perl installed."
437 fi
438 test -n "${QUICKSETUP}" && return "${mod_succ}"
439 extra_setup
440 if [ "$mod_succ" -eq "0" ]; then
441 if running_vboxguest || running_vboxadd; then
442 info "You should restart your guest to make sure the new modules are actually used"
443 fi
444 fi
445 return "${mod_succ}"
446}
447
448# cleanup_script
449cleanup()
450{
451 if test -r $config; then
452 . $config
453 test -n "$INSTALL_DIR" -a -n "$INSTALL_VER" ||
454 fail "Configuration file $config not complete"
455 else
456 fail "Configuration file $config not found"
457 fi
458
459 # Delete old versions of VBox modules.
460 cleanup_modules
461 depmod
462
463 # Remove old module sources
464 for i in $OLDMODULES; do
465 rm -rf /usr/src/$i-*
466 done
467
468 # Clean-up X11-related bits
469 "${INSTALL_DIR}/init/vboxadd-x11" cleanup 2>> "${LOG}"
470
471 # Remove other files
472 rm /sbin/mount.vboxsf 2>/dev/null
473 rm -f /etc/kernel/postinst.d/vboxadd /etc/kernel/prerm.d/vboxadd
474 rmdir -p /etc/kernel/postinst.d /etc/kernel/prerm.d 2>/dev/null
475 rm /etc/udev/rules.d/60-vboxadd.rules 2>/dev/null
476}
477
478dmnstatus()
479{
480 if running_vboxguest; then
481 echo "The VirtualBox Additions are currently running."
482 else
483 echo "The VirtualBox Additions are not currently running."
484 fi
485}
486
487case "$2" in quiet)
488 QUIET=yes;;
489esac
490case "$1" in
491start)
492 start
493 ;;
494stop)
495 stop
496 ;;
497restart)
498 restart
499 ;;
500setup)
501 setup && start
502 ;;
503quicksetup)
504 QUICKSETUP=yes
505 setup
506 ;;
507cleanup)
508 cleanup
509 ;;
510status)
511 dmnstatus
512 ;;
513*)
514 echo "Usage: $0 {start|stop|restart|status|setup|quicksetup|cleanup} [quiet]"
515 exit 1
516esac
517
518exit
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