VirtualBox

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

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

Additions/linux: don't freak out if vboxsf cannot be loaded (this is a valid configuration)

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