VirtualBox

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

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

bugref:8087: Additions/x11: support non-root X server: remove init script code to install the now removed DRI driver.

  • Property svn:eol-style set to LF
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 13.6 KB
Line 
1#! /bin/sh
2#
3# Linux Additions kernel module init script ($Revision: 59197 $)
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 fail "modprobe vboxguest failed"
191 }
192 case "$no_udev" in 1)
193 sleep .5;;
194 esac
195 }
196 case "$no_udev" in 1)
197 do_vboxguest_non_udev;;
198 esac
199
200 running_vboxsf || {
201 $MODPROBE vboxsf > /dev/null 2>&1 || {
202 if dmesg | grep "vboxConnect failed" > /dev/null 2>&1; then
203 show_error "Unable to start shared folders support. Make sure that your VirtualBox build"
204 show_error "supports this feature."
205 exit 1
206 fi
207 fail "modprobe vboxsf failed"
208 }
209 }
210
211 # This is needed as X.Org Server 1.13 does not auto-load the module.
212 running_vboxvideo || $MODPROBE vboxvideo > /dev/null 2>&1
213 # Install the guest OpenGL drivers. For now we don't support
214 # multi-architecture installations
215 rm -rf /etc/ld.so.conf.d/00vboxvideo.conf
216 ldconfig
217 if /usr/bin/VBoxClient --check3d; then
218 rm -r /tmp/VBoxOGL
219 mkdir -m 0755 /tmp/VBoxOGL
220 mkdir -m 0755 /tmp/VBoxOGL/system
221 ldconfig -p | while read -r line; do
222 case "${line}" in "libGL.so.1 ${ldconfig_arch} => "*)
223 ln -s "${line#libGL.so.1 ${ldconfig_arch} => }" /tmp/VBoxOGL/system/libGL.so.1
224 break
225 esac
226 done
227 echo "/tmp/VBoxOGL" > /etc/ld.so.conf.d/00vboxvideo.conf
228 ln -s "${INSTALL_DIR}/lib/VBoxOGL.so" /tmp/VBoxOGL/libGL.so.1
229 ln -s "${INSTALL_DIR}/lib/VBoxEGL.so" /tmp/VBoxOGL/libEGL.so.1
230 ldconfig
231 fi
232
233 # Mount all shared folders from /etc/fstab. Normally this is done by some
234 # other startup script but this requires the vboxdrv kernel module loaded.
235 # This isn't necessary anymore as the vboxsf module is autoloaded.
236 # mount -a -t vboxsf
237
238 succ_msg
239 return 0
240}
241
242stop()
243{
244 begin "Stopping VirtualBox Additions" console;
245 if test -r /etc/ld.so.conf.d/00vboxvideo.conf; then
246 rm /etc/ld.so.conf.d/00vboxvideo.conf
247 ldconfig
248 fi
249 if ! umount -a -t vboxsf 2>/dev/null; then
250 fail "Cannot unmount vboxsf folders"
251 fi
252 if running_vboxsf; then
253 rmmod vboxsf 2>/dev/null || fail "Cannot unload module vboxsf"
254 fi
255 if running_vboxguest; then
256 rmmod vboxguest 2>/dev/null || fail "Cannot unload module vboxguest"
257 rm -f $userdev || fail "Cannot unlink $userdev"
258 rm -f $dev || fail "Cannot unlink $dev"
259 fi
260 succ_msg
261 return 0
262}
263
264restart()
265{
266 stop && start
267 return 0
268}
269
270# Remove any existing VirtualBox guest kernel modules from the disk, but not
271# from the kernel as they may still be in use
272cleanup_modules()
273{
274 begin "Removing existing VirtualBox kernel modules"
275 # We no longer support DKMS, remove any leftovers.
276 for i in vboxguest vboxadd vboxsf vboxvfs vboxvideo; do
277 rm -rf "/var/lib/dkms/${i}"*
278 done
279 for i in $OLDMODULES; do
280 find /lib/modules -name $i\* | xargs rm 2>/dev/null
281 done
282 succ_msg
283}
284
285# Build and install the VirtualBox guest kernel modules
286setup_modules()
287{
288 # don't stop the old modules here -- they might be in use
289 cleanup_modules
290 begin "Building the VirtualBox Guest Additions kernel modules"
291
292 begin "Building the main Guest Additions module"
293 if ! $BUILDINTMP \
294 --save-module-symvers /tmp/vboxguest-Module.symvers \
295 --module-source $MODULE_SRC/vboxguest \
296 --no-print-directory install >> $LOG 2>&1; then
297 show_error "Look at $LOG to find out what went wrong"
298 return 1
299 fi
300 succ_msg
301 begin "Building the shared folder support module"
302 if ! $BUILDINTMP \
303 --use-module-symvers /tmp/vboxguest-Module.symvers \
304 --module-source $MODULE_SRC/vboxsf \
305 --no-print-directory install >> $LOG 2>&1; then
306 show_error "Look at $LOG to find out what went wrong"
307 return 1
308 fi
309 succ_msg
310 if expr `uname -r` '<' '2.6.27' > /dev/null; then
311 echo "Not building the VirtualBox advanced graphics driver as this Linux version is"
312 echo "too old to use it."
313 else
314 begin "Building the OpenGL support module"
315 if ! $BUILDINTMP \
316 --use-module-symvers /tmp/vboxguest-Module.symvers \
317 --module-source $MODULE_SRC/vboxvideo \
318 --no-print-directory install >> $LOG 2>&1; then
319 show_error "Look at $LOG to find out what went wrong. All other modules were built successfully."
320 else
321 succ_msg
322 fi
323 fi
324 depmod
325 return 0
326}
327
328# Do non-kernel bits needed for the kernel modules to work properly (user
329# creation, udev, mount helper...)
330extra_setup()
331{
332 begin "Doing non-kernel setup of the Guest Additions"
333 echo "Creating user for the Guest Additions." >> $LOG
334 # This is the LSB version of useradd and should work on recent
335 # distributions
336 useradd -d /var/run/vboxadd -g 1 -r -s /bin/false vboxadd >/dev/null 2>&1
337 # And for the others, we choose a UID ourselves
338 useradd -d /var/run/vboxadd -g 1 -u 501 -o -s /bin/false vboxadd >/dev/null 2>&1
339
340 # Add a group "vboxsf" for Shared Folders access
341 # All users which want to access the auto-mounted Shared Folders have to
342 # be added to this group.
343 groupadd -r -f vboxsf >/dev/null 2>&1
344
345 # Create udev description file
346 if [ -d /etc/udev/rules.d ]; then
347 echo "Creating udev rule for the Guest Additions kernel module." >> $LOG
348 udev_call=""
349 udev_app=`which udevadm 2> /dev/null`
350 if [ $? -eq 0 ]; then
351 udev_call="${udev_app} version 2> /dev/null"
352 else
353 udev_app=`which udevinfo 2> /dev/null`
354 if [ $? -eq 0 ]; then
355 udev_call="${udev_app} -V 2> /dev/null"
356 fi
357 fi
358 udev_fix="="
359 if [ "${udev_call}" != "" ]; then
360 udev_out=`${udev_call}`
361 udev_ver=`expr "$udev_out" : '[^0-9]*\([0-9]*\)'`
362 if [ "$udev_ver" = "" -o "$udev_ver" -lt 55 ]; then
363 udev_fix=""
364 fi
365 fi
366 ## @todo 60-vboxadd.rules -> 60-vboxguest.rules ?
367 echo "KERNEL=${udev_fix}\"vboxguest\", NAME=\"vboxguest\", OWNER=\"vboxadd\", MODE=\"0660\"" > /etc/udev/rules.d/60-vboxadd.rules
368 echo "KERNEL=${udev_fix}\"vboxuser\", NAME=\"vboxuser\", OWNER=\"vboxadd\", MODE=\"0666\"" >> /etc/udev/rules.d/60-vboxadd.rules
369 fi
370
371 # Put mount.vboxsf in the right place
372 ln -sf "$lib_path/$PACKAGE/mount.vboxsf" /sbin
373 # And an rc file to re-build the kernel modules and re-set-up the X server.
374 ln -sf "$lib_path/$PACKAGE/vboxadd" /sbin/rcvboxadd
375 ln -sf "$lib_path/$PACKAGE/vboxadd-x11" /sbin/rcvboxadd-x11
376 # At least Fedora 11 and Fedora 12 require the correct security context when
377 # executing this command from service scripts. Shouldn't hurt for other
378 # distributions.
379 chcon -u system_u -t mount_exec_t "$lib_path/$PACKAGE/mount.vboxsf" > /dev/null 2>&1
380 # And at least Fedora 15 needs this for the acceleration support check to
381 # work
382 redhat_release=`cat /etc/redhat-release 2> /dev/null`
383 case "$redhat_release" in Fedora\ release\ 15* )
384 for i in "$lib_path"/*.so
385 do
386 restorecon "$i" >/dev/null
387 done
388 ;;
389 esac
390
391 succ_msg
392}
393
394# setup_script
395setup()
396{
397 begin "Building Guest Additions kernel modules" console
398 if test -r $config; then
399 . $config
400 else
401 fail "Configuration file $config not found"
402 fi
403 test -n "$INSTALL_DIR" -a -n "$INSTALL_VER" ||
404 fail "Configuration file $config not complete"
405 export BUILD_TYPE
406 export USERNAME
407
408 rm -f $LOG
409 MODULE_SRC="$INSTALL_DIR/src/vboxguest-$INSTALL_VER"
410 BUILDINTMP="$MODULE_SRC/build_in_tmp"
411 chcon -t bin_t "$BUILDINTMP" > /dev/null 2>&1
412
413 if setup_modules; then
414 mod_succ=0
415 else
416 mod_succ=1
417 show_error "Please check that you have gcc, make, the header files for your Linux kernel and possibly perl installed."
418 fi
419 extra_setup
420 if [ "$mod_succ" -eq "0" ]; then
421 if running_vboxguest || running_vboxadd; then
422 begin "You should restart your guest to make sure the new modules are actually used" console
423 fi
424 fi
425 return "${mod_succ}"
426}
427
428# cleanup_script
429cleanup()
430{
431 if test -r $config; then
432 . $config
433 test -n "$INSTALL_DIR" -a -n "$INSTALL_VER" ||
434 fail "Configuration file $config not complete"
435 else
436 fail "Configuration file $config not found"
437 fi
438
439 # Delete old versions of VBox modules.
440 cleanup_modules
441 depmod
442
443 # Remove old module sources
444 for i in $OLDMODULES; do
445 rm -rf /usr/src/$i-*
446 done
447
448 # Remove other files
449 rm /sbin/mount.vboxsf 2>/dev/null
450 rm /sbin/rcvboxadd 2>/dev/null
451 rm /sbin/rcvboxadd-x11 2>/dev/null
452 rm /etc/udev/rules.d/60-vboxadd.rules 2>/dev/null
453}
454
455dmnstatus()
456{
457 if running_vboxguest; then
458 echo "The VirtualBox Additions are currently running."
459 else
460 echo "The VirtualBox Additions are not currently running."
461 fi
462}
463
464case "$1" in
465start)
466 start
467 ;;
468stop)
469 stop
470 ;;
471restart)
472 restart
473 ;;
474setup)
475 setup && start
476 ;;
477cleanup)
478 cleanup
479 ;;
480status)
481 dmnstatus
482 ;;
483*)
484 echo "Usage: $0 {start|stop|restart|status|setup}"
485 exit 1
486esac
487
488exit
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette