VirtualBox

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

Last change on this file since 63781 was 63738, checked in by vboxsync, 8 years ago

bugref:8087: Additions/x11: support non-root X server: if the guest provides its own vboxvideo kernel driver, use ours instead.

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