VirtualBox

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

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

Additions/linux: re-write r106090: call vboxadd-x11 during uninstall, otherwise a few files in /etc survive.

  • 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: 60103 $)
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 begin "Building the graphics driver module"
318 if ! $BUILDINTMP \
319 --use-module-symvers /tmp/vboxguest-Module.symvers \
320 --module-source $MODULE_SRC/vboxvideo \
321 --no-print-directory install >> $LOG 2>&1; then
322 show_error "Look at $LOG to find out what went wrong"
323 fi
324 succ_msg
325 depmod
326 return 0
327}
328
329# Do non-kernel bits needed for the kernel modules to work properly (user
330# creation, udev, mount helper...)
331extra_setup()
332{
333 begin "Doing non-kernel setup of the Guest Additions"
334 echo "Creating user for the Guest Additions." >> $LOG
335 # This is the LSB version of useradd and should work on recent
336 # distributions
337 useradd -d /var/run/vboxadd -g 1 -r -s /bin/false vboxadd >/dev/null 2>&1
338 # And for the others, we choose a UID ourselves
339 useradd -d /var/run/vboxadd -g 1 -u 501 -o -s /bin/false vboxadd >/dev/null 2>&1
340
341 # Add a group "vboxsf" for Shared Folders access
342 # All users which want to access the auto-mounted Shared Folders have to
343 # be added to this group.
344 groupadd -r -f vboxsf >/dev/null 2>&1
345
346 # Create udev description file
347 if [ -d /etc/udev/rules.d ]; then
348 echo "Creating udev rule for the Guest Additions kernel module." >> $LOG
349 udev_call=""
350 udev_app=`which udevadm 2> /dev/null`
351 if [ $? -eq 0 ]; then
352 udev_call="${udev_app} version 2> /dev/null"
353 else
354 udev_app=`which udevinfo 2> /dev/null`
355 if [ $? -eq 0 ]; then
356 udev_call="${udev_app} -V 2> /dev/null"
357 fi
358 fi
359 udev_fix="="
360 if [ "${udev_call}" != "" ]; then
361 udev_out=`${udev_call}`
362 udev_ver=`expr "$udev_out" : '[^0-9]*\([0-9]*\)'`
363 if [ "$udev_ver" = "" -o "$udev_ver" -lt 55 ]; then
364 udev_fix=""
365 fi
366 fi
367 ## @todo 60-vboxadd.rules -> 60-vboxguest.rules ?
368 echo "KERNEL=${udev_fix}\"vboxguest\", NAME=\"vboxguest\", OWNER=\"vboxadd\", MODE=\"0660\"" > /etc/udev/rules.d/60-vboxadd.rules
369 echo "KERNEL=${udev_fix}\"vboxuser\", NAME=\"vboxuser\", OWNER=\"vboxadd\", MODE=\"0666\"" >> /etc/udev/rules.d/60-vboxadd.rules
370 fi
371
372 # Put mount.vboxsf in the right place
373 ln -sf "$lib_path/$PACKAGE/mount.vboxsf" /sbin
374 # And an rc file to re-build the kernel modules and re-set-up the X server.
375 ln -sf "$lib_path/$PACKAGE/vboxadd" /sbin/rcvboxadd
376 ln -sf "$lib_path/$PACKAGE/vboxadd-x11" /sbin/rcvboxadd-x11
377 # At least Fedora 11 and Fedora 12 require the correct security context when
378 # executing this command from service scripts. Shouldn't hurt for other
379 # distributions.
380 chcon -u system_u -t mount_exec_t "$lib_path/$PACKAGE/mount.vboxsf" > /dev/null 2>&1
381 # And at least Fedora 15 needs this for the acceleration support check to
382 # work
383 redhat_release=`cat /etc/redhat-release 2> /dev/null`
384 case "$redhat_release" in Fedora\ release\ 15* )
385 for i in "$lib_path"/*.so
386 do
387 restorecon "$i" >/dev/null
388 done
389 ;;
390 esac
391
392 succ_msg
393}
394
395# setup_script
396setup()
397{
398 begin "Building Guest Additions kernel modules" console
399 if test -r $config; then
400 . $config
401 else
402 fail "Configuration file $config not found"
403 fi
404 test -n "$INSTALL_DIR" -a -n "$INSTALL_VER" ||
405 fail "Configuration file $config not complete"
406 export BUILD_TYPE
407 export USERNAME
408
409 rm -f $LOG
410 MODULE_SRC="$INSTALL_DIR/src/vboxguest-$INSTALL_VER"
411 BUILDINTMP="$MODULE_SRC/build_in_tmp"
412 chcon -t bin_t "$BUILDINTMP" > /dev/null 2>&1
413
414 if setup_modules; then
415 mod_succ=0
416 else
417 mod_succ=1
418 show_error "Please check that you have gcc, make, the header files for your Linux kernel and possibly perl installed."
419 fi
420 extra_setup
421 if [ "$mod_succ" -eq "0" ]; then
422 if running_vboxguest || running_vboxadd; then
423 begin "You should restart your guest to make sure the new modules are actually used" console
424 fi
425 fi
426 return "${mod_succ}"
427}
428
429# cleanup_script
430cleanup()
431{
432 if test -r $config; then
433 . $config
434 test -n "$INSTALL_DIR" -a -n "$INSTALL_VER" ||
435 fail "Configuration file $config not complete"
436 else
437 fail "Configuration file $config not found"
438 fi
439
440 # Delete old versions of VBox modules.
441 cleanup_modules
442 depmod
443
444 # Remove old module sources
445 for i in $OLDMODULES; do
446 rm -rf /usr/src/$i-*
447 done
448
449 # Clean-up X11-related bits
450 /sbin/rcvboxadd-x11 cleanup
451
452 # Remove other files
453 rm /sbin/mount.vboxsf 2>/dev/null
454 rm /sbin/rcvboxadd 2>/dev/null
455 rm /sbin/rcvboxadd-x11 2>/dev/null
456 rm /etc/udev/rules.d/60-vboxadd.rules 2>/dev/null
457}
458
459dmnstatus()
460{
461 if running_vboxguest; then
462 echo "The VirtualBox Additions are currently running."
463 else
464 echo "The VirtualBox Additions are not currently running."
465 fi
466}
467
468case "$1" in
469start)
470 start
471 ;;
472stop)
473 stop
474 ;;
475restart)
476 restart
477 ;;
478setup)
479 setup && start
480 ;;
481cleanup)
482 cleanup
483 ;;
484status)
485 dmnstatus
486 ;;
487*)
488 echo "Usage: $0 {start|stop|restart|status|setup}"
489 exit 1
490esac
491
492exit
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