VirtualBox

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

Last change on this file since 59963 was 59963, checked in by vboxsync, 9 years ago

bugref:8087: Additions/x11: support non-root X server: only build the kernel graphics driver on sufficiently recent kernels, and print a more detailed error message if it fails.

  • Property svn:eol-style set to LF
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 13.9 KB
Line 
1#! /bin/sh
2#
3# Linux Additions kernel module init script ($Revision: 59963 $)
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 30 70
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
31PATH=$PATH:/bin:/sbin:/usr/sbin
32PACKAGE=VBoxGuestAdditions
33LOG="/var/log/vboxadd-install.log"
34MODPROBE=/sbin/modprobe
35OLDMODULES="vboxguest vboxadd vboxsf vboxvfs vboxvideo"
36SCRIPTNAME=vboxadd.sh
37
38if $MODPROBE -c 2>/dev/null | grep -q '^allow_unsupported_modules *0'; then
39 MODPROBE="$MODPROBE --allow-unsupported-modules"
40fi
41
42# Check architecture
43cpu=`uname -m`;
44case "$cpu" in
45 i[3456789]86|x86)
46 cpu="x86"
47 ldconfig_arch="(libc6)"
48 lib_candidates="/usr/lib/i386-linux-gnu /usr/lib /lib"
49 ;;
50 x86_64|amd64)
51 cpu="amd64"
52 ldconfig_arch="(libc6,x86-64)"
53 lib_candidates="/usr/lib/x86_64-linux-gnu /usr/lib64 /usr/lib /lib64 /lib"
54 ;;
55esac
56for i in $lib_candidates; do
57 if test -d "$i/VBoxGuestAdditions"; then
58 lib_path=$i
59 break
60 fi
61done
62
63# Preamble for Gentoo
64if [ "`which $0`" = "/sbin/rc" ]; then
65 shift
66fi
67
68begin()
69{
70 test -n "${2}" && echo "${SCRIPTNAME}: ${1}."
71 logger -t "${SCRIPTNAME}" "${1}."
72}
73
74succ_msg()
75{
76 logger -t "${SCRIPTNAME}" "${1}."
77}
78
79show_error()
80{
81 echo "${SCRIPTNAME}: failed: ${1}." >&2
82 logger -t "${SCRIPTNAME}" "${1}."
83}
84
85fail()
86{
87 show_error "$1"
88 exit 1
89}
90
91dev=/dev/vboxguest
92userdev=/dev/vboxuser
93config=/var/lib/VBoxGuestAdditions/config
94owner=vboxadd
95group=1
96
97running_vboxguest()
98{
99 lsmod | grep -q "vboxguest[^_-]"
100}
101
102running_vboxadd()
103{
104 lsmod | grep -q "vboxadd[^_-]"
105}
106
107running_vboxsf()
108{
109 lsmod | grep -q "vboxsf[^_-]"
110}
111
112running_vboxvideo()
113{
114 lsmod | grep -q "vboxvideo[^_-]"
115}
116
117do_vboxguest_non_udev()
118{
119 if [ ! -c $dev ]; then
120 maj=`sed -n 's;\([0-9]\+\) vboxguest;\1;p' /proc/devices`
121 if [ ! -z "$maj" ]; then
122 min=0
123 else
124 min=`sed -n 's;\([0-9]\+\) vboxguest;\1;p' /proc/misc`
125 if [ ! -z "$min" ]; then
126 maj=10
127 fi
128 fi
129 test -z "$maj" && {
130 rmmod vboxguest 2>/dev/null
131 fail "Cannot locate the VirtualBox device"
132 }
133
134 mknod -m 0664 $dev c $maj $min || {
135 rmmod vboxguest 2>/dev/null
136 fail "Cannot create device $dev with major $maj and minor $min"
137 }
138 fi
139 chown $owner:$group $dev 2>/dev/null || {
140 rm -f $dev 2>/dev/null
141 rm -f $userdev 2>/dev/null
142 rmmod vboxguest 2>/dev/null
143 fail "Cannot change owner $owner:$group for device $dev"
144 }
145
146 if [ ! -c $userdev ]; then
147 maj=10
148 min=`sed -n 's;\([0-9]\+\) vboxuser;\1;p' /proc/misc`
149 if [ ! -z "$min" ]; then
150 mknod -m 0666 $userdev c $maj $min || {
151 rm -f $dev 2>/dev/null
152 rmmod vboxguest 2>/dev/null
153 fail "Cannot create device $userdev with major $maj and minor $min"
154 }
155 chown $owner:$group $userdev 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 $userdev"
160 }
161 fi
162 fi
163}
164
165start()
166{
167 begin "Starting the VirtualBox Guest Additions" console;
168 if test -r $config; then
169 . $config
170 else
171 fail "Configuration file $config not found"
172 fi
173 test -n "$INSTALL_DIR" -a -n "$INSTALL_VER" ||
174 fail "Configuration file $config not complete"
175 uname -r | grep -q -E '^2\.6|^3|^4' 2>/dev/null &&
176 ps -A -o comm | grep -q '/*udevd$' 2>/dev/null ||
177 no_udev=1
178 running_vboxguest || {
179 rm -f $dev || {
180 fail "Cannot remove $dev"
181 }
182
183 rm -f $userdev || {
184 fail "Cannot remove $userdev"
185 }
186
187 $MODPROBE vboxguest >/dev/null 2>&1 || {
188 setup
189 $MODPROBE vboxguest >/dev/null 2>&1 || {
190 /sbin/rcvboxadd-x11 cleanup
191 fail "modprobe vboxguest failed"
192 }
193 }
194 case "$no_udev" in 1)
195 sleep .5;;
196 esac
197 }
198 case "$no_udev" in 1)
199 do_vboxguest_non_udev;;
200 esac
201
202 running_vboxsf || {
203 $MODPROBE vboxsf > /dev/null 2>&1 || {
204 if dmesg | grep "vboxConnect failed" > /dev/null 2>&1; then
205 show_error "Unable to start shared folders support. Make sure that your VirtualBox build"
206 show_error "supports this feature."
207 exit 1
208 fi
209 fail "modprobe vboxsf failed"
210 }
211 }
212
213 /sbin/rcvboxadd-x11 setup
214 # Install the guest OpenGL drivers. For now we don't support
215 # multi-architecture installations
216 rm -rf /etc/ld.so.conf.d/00vboxvideo.conf
217 ldconfig
218 if /usr/bin/VBoxClient --check3d; then
219 rm -r /tmp/VBoxOGL
220 mkdir -m 0755 /tmp/VBoxOGL
221 mkdir -m 0755 /tmp/VBoxOGL/system
222 ldconfig -p | while read -r line; do
223 case "${line}" in "libGL.so.1 ${ldconfig_arch} => "*)
224 ln -s "${line#libGL.so.1 ${ldconfig_arch} => }" /tmp/VBoxOGL/system/libGL.so.1
225 break
226 esac
227 done
228 ldconfig -p | while read -r line; do
229 case "${line}" in "libEGL.so.1 ${ldconfig_arch} => "*)
230 ln -s "${line#libEGL.so.1 ${ldconfig_arch} => }" /tmp/VBoxOGL/system/libEGL.so.1
231 break
232 esac
233 done
234 echo "/tmp/VBoxOGL" > /etc/ld.so.conf.d/00vboxvideo.conf
235 ln -s "${INSTALL_DIR}/lib/VBoxOGL.so" /tmp/VBoxOGL/libGL.so.1
236 ln -s "${INSTALL_DIR}/lib/VBoxEGL.so" /tmp/VBoxOGL/libEGL.so.1
237 ldconfig
238 fi
239
240 # Mount all shared folders from /etc/fstab. Normally this is done by some
241 # other startup script but this requires the vboxdrv kernel module loaded.
242 # This isn't necessary anymore as the vboxsf module is autoloaded.
243 # mount -a -t vboxsf
244
245 succ_msg
246 return 0
247}
248
249stop()
250{
251 begin "Stopping VirtualBox Additions" console;
252 if test -r /etc/ld.so.conf.d/00vboxvideo.conf; then
253 rm /etc/ld.so.conf.d/00vboxvideo.conf
254 ldconfig
255 fi
256 if ! umount -a -t vboxsf 2>/dev/null; then
257 fail "Cannot unmount vboxsf folders"
258 fi
259 if running_vboxsf; then
260 rmmod vboxsf 2>/dev/null || fail "Cannot unload module vboxsf"
261 fi
262 if running_vboxguest; then
263 rmmod vboxguest 2>/dev/null || fail "Cannot unload module vboxguest"
264 rm -f $userdev || fail "Cannot unlink $userdev"
265 rm -f $dev || fail "Cannot unlink $dev"
266 fi
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 # We no longer support DKMS, remove any leftovers.
283 for i in vboxguest vboxadd vboxsf vboxvfs vboxvideo; do
284 rm -rf "/var/lib/dkms/${i}"*
285 done
286 for i in $OLDMODULES; do
287 find /lib/modules -name $i\* | xargs rm 2>/dev/null
288 done
289 succ_msg
290}
291
292# Build and install the VirtualBox guest kernel modules
293setup_modules()
294{
295 # don't stop the old modules here -- they might be in use
296 cleanup_modules
297 begin "Building the VirtualBox Guest Additions kernel modules"
298
299 begin "Building the main Guest Additions module"
300 if ! $BUILDINTMP \
301 --save-module-symvers /tmp/vboxguest-Module.symvers \
302 --module-source $MODULE_SRC/vboxguest \
303 --no-print-directory install >> $LOG 2>&1; then
304 show_error "Look at $LOG to find out what went wrong"
305 return 1
306 fi
307 succ_msg
308 begin "Building the shared folder support module"
309 if ! $BUILDINTMP \
310 --use-module-symvers /tmp/vboxguest-Module.symvers \
311 --module-source $MODULE_SRC/vboxsf \
312 --no-print-directory install >> $LOG 2>&1; then
313 show_error "Look at $LOG to find out what went wrong"
314 return 1
315 fi
316 succ_msg
317 if expr `uname -r` '<' '3.11' > /dev/null; then
318 echo "Not building the VirtualBox kernel graphics driver as this Linux version is"
319 echo "too old to use it."
320 else
321 begin "Building the graphics driver module"
322 if ! $BUILDINTMP \
323 --use-module-symvers /tmp/vboxguest-Module.symvers \
324 --module-source $MODULE_SRC/vboxvideo \
325 --no-print-directory install >> $LOG 2>&1; then
326 show_error "Building the graphics driver module failed. Look at $LOG to find out what went wrong. All other modules were built successfully."
327 else
328 succ_msg
329 fi
330 fi
331 depmod
332 return 0
333}
334
335# Do non-kernel bits needed for the kernel modules to work properly (user
336# creation, udev, mount helper...)
337extra_setup()
338{
339 begin "Doing non-kernel setup of the Guest Additions"
340 echo "Creating user for the Guest Additions." >> $LOG
341 # This is the LSB version of useradd and should work on recent
342 # distributions
343 useradd -d /var/run/vboxadd -g 1 -r -s /bin/false vboxadd >/dev/null 2>&1
344 # And for the others, we choose a UID ourselves
345 useradd -d /var/run/vboxadd -g 1 -u 501 -o -s /bin/false vboxadd >/dev/null 2>&1
346
347 # Add a group "vboxsf" for Shared Folders access
348 # All users which want to access the auto-mounted Shared Folders have to
349 # be added to this group.
350 groupadd -r -f vboxsf >/dev/null 2>&1
351
352 # Create udev description file
353 if [ -d /etc/udev/rules.d ]; then
354 echo "Creating udev rule for the Guest Additions kernel module." >> $LOG
355 udev_call=""
356 udev_app=`which udevadm 2> /dev/null`
357 if [ $? -eq 0 ]; then
358 udev_call="${udev_app} version 2> /dev/null"
359 else
360 udev_app=`which udevinfo 2> /dev/null`
361 if [ $? -eq 0 ]; then
362 udev_call="${udev_app} -V 2> /dev/null"
363 fi
364 fi
365 udev_fix="="
366 if [ "${udev_call}" != "" ]; then
367 udev_out=`${udev_call}`
368 udev_ver=`expr "$udev_out" : '[^0-9]*\([0-9]*\)'`
369 if [ "$udev_ver" = "" -o "$udev_ver" -lt 55 ]; then
370 udev_fix=""
371 fi
372 fi
373 ## @todo 60-vboxadd.rules -> 60-vboxguest.rules ?
374 echo "KERNEL=${udev_fix}\"vboxguest\", NAME=\"vboxguest\", OWNER=\"vboxadd\", MODE=\"0660\"" > /etc/udev/rules.d/60-vboxadd.rules
375 echo "KERNEL=${udev_fix}\"vboxuser\", NAME=\"vboxuser\", OWNER=\"vboxadd\", MODE=\"0666\"" >> /etc/udev/rules.d/60-vboxadd.rules
376 fi
377
378 # Put mount.vboxsf in the right place
379 ln -sf "$lib_path/$PACKAGE/mount.vboxsf" /sbin
380 # And an rc file to re-build the kernel modules and re-set-up the X server.
381 ln -sf "$lib_path/$PACKAGE/vboxadd" /sbin/rcvboxadd
382 ln -sf "$lib_path/$PACKAGE/vboxadd-x11" /sbin/rcvboxadd-x11
383 # At least Fedora 11 and Fedora 12 require the correct security context when
384 # executing this command from service scripts. Shouldn't hurt for other
385 # distributions.
386 chcon -u system_u -t mount_exec_t "$lib_path/$PACKAGE/mount.vboxsf" > /dev/null 2>&1
387 # And at least Fedora 15 needs this for the acceleration support check to
388 # work
389 redhat_release=`cat /etc/redhat-release 2> /dev/null`
390 case "$redhat_release" in Fedora\ release\ 15* )
391 for i in "$lib_path"/*.so
392 do
393 restorecon "$i" >/dev/null
394 done
395 ;;
396 esac
397
398 succ_msg
399}
400
401# setup_script
402setup()
403{
404 begin "Building Guest Additions kernel modules" console
405 if test -r $config; then
406 . $config
407 else
408 fail "Configuration file $config not found"
409 fi
410 test -n "$INSTALL_DIR" -a -n "$INSTALL_VER" ||
411 fail "Configuration file $config not complete"
412 export BUILD_TYPE
413 export USERNAME
414
415 rm -f $LOG
416 MODULE_SRC="$INSTALL_DIR/src/vboxguest-$INSTALL_VER"
417 BUILDINTMP="$MODULE_SRC/build_in_tmp"
418 chcon -t bin_t "$BUILDINTMP" > /dev/null 2>&1
419
420 if setup_modules; then
421 mod_succ=0
422 else
423 mod_succ=1
424 show_error "Please check that you have gcc, make, the header files for your Linux kernel and possibly perl installed."
425 fi
426 extra_setup
427 if [ "$mod_succ" -eq "0" ]; then
428 if running_vboxguest || running_vboxadd; then
429 begin "You should restart your guest to make sure the new modules are actually used" console
430 fi
431 fi
432 return "${mod_succ}"
433}
434
435# cleanup_script
436cleanup()
437{
438 if test -r $config; then
439 . $config
440 test -n "$INSTALL_DIR" -a -n "$INSTALL_VER" ||
441 fail "Configuration file $config not complete"
442 else
443 fail "Configuration file $config not found"
444 fi
445
446 # Delete old versions of VBox modules.
447 cleanup_modules
448 depmod
449
450 # Remove old module sources
451 for i in $OLDMODULES; do
452 rm -rf /usr/src/$i-*
453 done
454
455 # Remove other files
456 rm /sbin/mount.vboxsf 2>/dev/null
457 rm /sbin/rcvboxadd 2>/dev/null
458 rm /sbin/rcvboxadd-x11 2>/dev/null
459 rm /etc/udev/rules.d/60-vboxadd.rules 2>/dev/null
460}
461
462dmnstatus()
463{
464 if running_vboxguest; then
465 echo "The VirtualBox Additions are currently running."
466 else
467 echo "The VirtualBox Additions are not currently running."
468 fi
469}
470
471case "$1" in
472start)
473 start
474 ;;
475stop)
476 stop
477 ;;
478restart)
479 restart
480 ;;
481setup)
482 setup && start
483 ;;
484cleanup)
485 cleanup
486 ;;
487status)
488 dmnstatus
489 ;;
490*)
491 echo "Usage: $0 {start|stop|restart|status|setup}"
492 exit 1
493esac
494
495exit
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