VirtualBox

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

Last change on this file since 30295 was 30295, checked in by vboxsync, 15 years ago

Additions/linux/installer: make sure the rest of the installation succeeds even if the modules cannot be built

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 14.3 KB
Line 
1#! /bin/sh
2# Sun VirtualBox
3# Linux Additions kernel module init script ($Revision: 30295 $)
4#
5
6#
7# Copyright (C) 2006-2009 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: 357 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
33BUILDVBOXGUEST=`/bin/ls /usr/src/vboxguest*/build_in_tmp 2>/dev/null|cut -d' ' -f1`
34BUILDVBOXSF=`/bin/ls /usr/src/vboxsf*/build_in_tmp 2>/dev/null|cut -d' ' -f1`
35BUILDVBOXVIDEO=`/bin/ls /usr/src/vboxvideo*/build_in_tmp 2>/dev/null|cut -d' ' -f1`
36LOG="/var/log/vboxadd-install.log"
37MODPROBE=/sbin/modprobe
38
39if $MODPROBE -c | grep -q '^allow_unsupported_modules *0'; then
40 MODPROBE="$MODPROBE --allow-unsupported-modules"
41fi
42
43# Check architecture
44cpu=`uname -m`;
45case "$cpu" in
46 i[3456789]86|x86)
47 cpu="x86"
48 lib_path="/usr/lib"
49 ;;
50 x86_64|amd64)
51 cpu="amd64"
52 if test -d "/usr/lib64"; then
53 lib_path="/usr/lib64"
54 else
55 lib_path="/usr/lib"
56 fi
57 ;;
58esac
59
60if [ -f /etc/arch-release ]; then
61 system=arch
62elif [ -f /etc/redhat-release ]; then
63 system=redhat
64elif [ -f /etc/SuSE-release ]; then
65 system=suse
66elif [ -f /etc/gentoo-release ]; then
67 system=gentoo
68elif [ -f /etc/lfs-release -a -d /etc/rc.d/init.d ]; then
69 system=lfs
70else
71 system=other
72fi
73
74if [ "$system" = "arch" ]; then
75 USECOLOR=yes
76 . /etc/rc.d/functions
77 fail_msg() {
78 stat_fail
79 }
80
81 succ_msg() {
82 stat_done
83 }
84
85 begin() {
86 stat_busy "$1"
87 }
88fi
89
90if [ "$system" = "redhat" ]; then
91 . /etc/init.d/functions
92 fail_msg() {
93 echo_failure
94 echo
95 }
96 succ_msg() {
97 echo_success
98 echo
99 }
100 begin() {
101 echo -n "$1"
102 }
103fi
104
105if [ "$system" = "suse" ]; then
106 . /etc/rc.status
107 fail_msg() {
108 rc_failed 1
109 rc_status -v
110 }
111 succ_msg() {
112 rc_reset
113 rc_status -v
114 }
115 begin() {
116 echo -n "$1"
117 }
118fi
119
120if [ "$system" = "gentoo" ]; then
121 if [ -f /sbin/functions.sh ]; then
122 . /sbin/functions.sh
123 elif [ -f /etc/init.d/functions.sh ]; then
124 . /etc/init.d/functions.sh
125 fi
126 fail_msg() {
127 eend 1
128 }
129 succ_msg() {
130 eend $?
131 }
132 begin() {
133 ebegin $1
134 }
135 if [ "`which $0`" = "/sbin/rc" ]; then
136 shift
137 fi
138fi
139
140if [ "$system" = "lfs" ]; then
141 . /etc/rc.d/init.d/functions
142 fail_msg() {
143 echo_failure
144 }
145 succ_msg() {
146 echo_ok
147 }
148 begin() {
149 echo $1
150 }
151fi
152
153if [ "$system" = "other" ]; then
154 fail_msg() {
155 echo " ...fail!"
156 }
157 succ_msg() {
158 echo " ...done."
159 }
160 begin() {
161 echo -n $1
162 }
163fi
164
165dev=/dev/vboxguest
166userdev=/dev/vboxuser
167owner=vboxadd
168group=1
169
170test_sane_kernel_dir()
171{
172 KERN_VER=`uname -r`
173 KERN_DIR="/lib/modules/$KERN_VER/build"
174 if [ -d "$KERN_DIR" ]; then
175 KERN_REL=`make -sC $KERN_DIR --no-print-directory kernelrelease || true`
176 if [ "x$KERN_REL" == "x$KERN_VER" ]; then
177 return 0
178 fi
179 fi
180 printf "\nThe headers for the current running kernel were not found. If the following\nmodule compilation fails then this could be the reason.\n"
181 if [ "$system" = "redhat" ]; then
182 printf "The missing package can be probably installed with\nyum install kernel-devel-$KERN_VER\n"
183 elif [ "$system" = "suse" ]; then
184 printf "The missing package can be probably installed with\nzypper install kernel-$KERN_VER\n"
185 elif [ "$system" = "debian" ]; then
186 printf "The missing package can be probably installed with\napt-get install linux-headers-$KERN_VER\n"
187 fi
188}
189
190fail()
191{
192 if [ "$system" = "gentoo" ]; then
193 eerror $1
194 exit 1
195 fi
196 fail_msg
197 echo "($1)"
198 exit 1
199}
200
201running_vboxguest()
202{
203 lsmod | grep -q "vboxguest[^_-]"
204}
205
206running_vboxadd()
207{
208 lsmod | grep -q "vboxadd[^_-]"
209}
210
211running_vboxsf()
212{
213 lsmod | grep -q "vboxsf[^_-]"
214}
215
216start()
217{
218 begin "Starting the VirtualBox Guest Additions ";
219 running_vboxguest || {
220 rm -f $dev || {
221 fail "Cannot remove $dev"
222 }
223
224 rm -f $userdev || {
225 fail "Cannot remove $userdev"
226 }
227
228 $MODPROBE vboxguest >/dev/null 2>&1 || {
229 fail "modprobe vboxguest failed"
230 }
231 sleep .5
232 }
233 if [ ! -c $dev ]; then
234 maj=`sed -n 's;\([0-9]\+\) vboxguest;\1;p' /proc/devices`
235 if [ ! -z "$maj" ]; then
236 min=0
237 else
238 min=`sed -n 's;\([0-9]\+\) vboxguest;\1;p' /proc/misc`
239 if [ ! -z "$min" ]; then
240 maj=10
241 fi
242 fi
243 test -z "$maj" && {
244 rmmod vboxguest 2>/dev/null
245 fail "Cannot locate the VirtualBox device"
246 }
247
248 mknod -m 0664 $dev c $maj $min || {
249 rmmod vboxguest 2>/dev/null
250 fail "Cannot create device $dev with major $maj and minor $min"
251 }
252 fi
253 chown $owner:$group $dev 2>/dev/null || {
254 rm -f $dev 2>/dev/null
255 rm -f $userdev 2>/dev/null
256 rmmod vboxguest 2>/dev/null
257 fail "Cannot change owner $owner:$group for device $dev"
258 }
259
260 if [ ! -c $userdev ]; then
261 maj=10
262 min=`sed -n 's;\([0-9]\+\) vboxuser;\1;p' /proc/misc`
263 if [ ! -z "$min" ]; then
264 mknod -m 0666 $userdev c $maj $min || {
265 rm -f $dev 2>/dev/null
266 rmmod vboxguest 2>/dev/null
267 fail "Cannot create device $userdev with major $maj and minor $min"
268 }
269 chown $owner:$group $userdev 2>/dev/null || {
270 rm -f $dev 2>/dev/null
271 rm -f $userdev 2>/dev/null
272 rmmod vboxguest 2>/dev/null
273 fail "Cannot change owner $owner:$group for device $userdev"
274 }
275 fi
276 fi
277
278 if [ -n "$BUILDVBOXSF" ]; then
279 running_vboxsf || {
280 $MODPROBE vboxsf > /dev/null 2>&1 || {
281 if dmesg | grep "vboxConnect failed" > /dev/null 2>&1; then
282 fail_msg
283 echo "Unable to start shared folders support. Make sure that your VirtualBox build"
284 echo "supports this feature."
285 exit 1
286 fi
287 fail "modprobe vboxsf failed"
288 }
289 }
290 fi
291
292 # Mount all shared folders from /etc/fstab. Normally this is done by some
293 # other startup script but this requires the vboxdrv kernel module loaded.
294 # This isn't necessary anymore as the vboxsf module is autoloaded.
295 # mount -a -t vboxsf
296
297 succ_msg
298 return 0
299}
300
301stop()
302{
303 begin "Stopping VirtualBox Additions ";
304 if ! umount -a -t vboxsf 2>/dev/null; then
305 fail "Cannot unmount vboxsf folders"
306 fi
307 if [ -n "$BUILDVBOXSF" ]; then
308 if running_vboxsf; then
309 rmmod vboxsf 2>/dev/null || fail "Cannot unload module vboxsf"
310 fi
311 fi
312 if running_vboxguest; then
313 rmmod vboxguest 2>/dev/null || fail "Cannot unload module vboxguest"
314 rm -f $userdev || fail "Cannot unlink $userdev"
315 rm -f $dev || fail "Cannot unlink $dev"
316 fi
317 succ_msg
318 return 0
319}
320
321restart()
322{
323 stop && start
324 return 0
325}
326
327# setup_script
328setup()
329{
330 # don't stop the old modules here -- they might be in use
331 if find /lib/modules/`uname -r` -name "vboxvideo\.*" 2>/dev/null|grep -q vboxvideo; then
332 begin "Removing old VirtualBox vboxvideo kernel module"
333 find /lib/modules/`uname -r` -name "vboxvideo\.*" 2>/dev/null|xargs rm -f 2>/dev/null
334 succ_msg
335 fi
336 if find /lib/modules/`uname -r` -name "vboxsf\.*" 2>/dev/null|grep -q vboxsf; then
337 begin "Removing old VirtualBox vboxsf kernel module"
338 find /lib/modules/`uname -r` -name "vboxsf\.*" 2>/dev/null|xargs rm -f 2>/dev/null
339 succ_msg
340 fi
341 if find /lib/modules/`uname -r` -name "vboxguest\.*" 2>/dev/null|grep -q vboxguest; then
342 begin "Removing old VirtualBox vboxguest kernel module"
343 find /lib/modules/`uname -r` -name "vboxguest\.*" 2>/dev/null|xargs rm -f 2>/dev/null
344 succ_msg
345 fi
346 begin "Building the VirtualBox Guest Additions kernel modules"
347 test_sane_kernel_dir
348 if ! sh /usr/share/$PACKAGE/test/build_in_tmp \
349 --no-dkms --no-print-directory > $LOG 2>&1; then
350 fail_msg
351 printf "Your system does not seem to be set up to build kernel modules.\nLook at $LOG to find out what went wrong. Once you have corrected it, you can\nrun\n\n /etc/init.d/vboxadd setup\n\nto build them."
352 BUILDVBOXGUEST=""
353 BUILDVBOXSF=""
354 BUILDVBOXVIDEO=""
355 else
356 if ! sh /usr/share/$PACKAGE/test_drm/build_in_tmp \
357 --no-dkms --no-print-directory >> $LOG 2>&1; then
358 printf "\nYour guest system does not seem to have sufficient OpenGL support to enable\naccelerated 3D effects (this requires Linux 2.6.27 or later in the guest\nsystem). This Guest Additions feature will be disabled.\n\n"
359 BUILDVBOXVIDEO=""
360 fi
361 fi
362 echo
363 if [ -n "$BUILDVBOXGUEST" ]; then
364 begin "Building the main Guest Additions module"
365 if ! $BUILDVBOXGUEST \
366 --save-module-symvers /tmp/vboxguest-Module.symvers \
367 --no-print-directory install >> $LOG 2>&1; then
368 fail "Look at $LOG to find out what went wrong"
369 fi
370 succ_msg
371 fi
372 if [ -n "$BUILDVBOXSF" ]; then
373 begin "Building the shared folder support module"
374 if ! $BUILDVBOXSF \
375 --use-module-symvers /tmp/vboxguest-Module.symvers \
376 --no-print-directory install >> $LOG 2>&1; then
377 fail "Look at $LOG to find out what went wrong"
378 fi
379 succ_msg
380 fi
381 if [ -n "$BUILDVBOXVIDEO" ]; then
382 begin "Building the OpenGL support module"
383 if ! $BUILDVBOXVIDEO \
384 --use-module-symvers /tmp/vboxguest-Module.symvers \
385 --no-print-directory install >> $LOG 2>&1; then
386 fail "Look at $LOG to find out what went wrong"
387 fi
388 succ_msg
389 fi
390 depmod
391
392 begin "Doing non-kernel setup of the Guest Additions"
393 echo "Creating user for the Guest Additions." >> $LOG
394 # This is the LSB version of useradd and should work on recent
395 # distributions
396 useradd -d /var/run/vboxadd -g 1 -r -s /bin/false vboxadd >/dev/null 2>&1
397 # And for the others, we choose a UID ourselves
398 useradd -d /var/run/vboxadd -g 1 -u 501 -o -s /bin/false vboxadd >/dev/null 2>&1
399
400 # Create udev description file
401 if [ -d /etc/udev/rules.d ]; then
402 echo "Creating udev rule for the Guest Additions kernel module." >> $LOG
403 udev_call=""
404 udev_app=`which udevadm 2> /dev/null`
405 if [ $? -eq 0 ]; then
406 udev_call="${udev_app} version 2> /dev/null"
407 else
408 udev_app=`which udevinfo 2> /dev/null`
409 if [ $? -eq 0 ]; then
410 udev_call="${udev_app} -V 2> /dev/null"
411 fi
412 fi
413 udev_fix="="
414 if [ "${udev_call}" != "" ]; then
415 udev_out=`${udev_call}`
416 udev_ver=`expr "$udev_out" : '[^0-9]*\([0-9]*\)'`
417 if [ "$udev_ver" = "" -o "$udev_ver" -lt 55 ]; then
418 udev_fix=""
419 fi
420 fi
421 ## @todo 60-vboxadd.rules -> 60-vboxguest.rules ?
422 echo "KERNEL=${udev_fix}\"vboxguest\", NAME=\"vboxguest\", OWNER=\"vboxadd\", MODE=\"0660\"" > /etc/udev/rules.d/60-vboxadd.rules
423 echo "KERNEL=${udev_fix}\"vboxuser\", NAME=\"vboxuser\", OWNER=\"vboxadd\", MODE=\"0666\"" >> /etc/udev/rules.d/60-vboxadd.rules
424 fi
425
426 # Put mount.vboxsf in the right place
427 ln -sf "$lib_path/$PACKAGE/mount.vboxsf" /sbin
428 # At least Fedora 11 and Fedora 12 demand on the correct security context when
429 # executing this command from service scripts. Shouldn't hurt for other distributions.
430 chcon -u system_u -t mount_exec_t "$lib_path/$PACKAGE/mount.vboxsf" > /dev/null 2>&1
431
432 succ_msg
433 if [ -n "$BUILDVBOXGUEST" ]; then
434 if running_vboxguest || running_vboxadd; then
435 printf "You should restart your guest to make sure the new modules are actually used\n\n"
436 else
437 start
438 fi
439 fi
440}
441
442# cleanup_script
443cleanup()
444{
445 # Delete old versions of VBox modules.
446 DKMS=`which dkms 2>/dev/null`
447 if [ -n "$DKMS" ]; then
448 echo "Attempt to remove old DKMS modules..."
449 for mod in vboxadd vboxguest vboxvfs vboxsf vboxvideo; do
450 $DKMS status -m $mod | while read line; do
451 if echo "$line" | grep -q added > /dev/null ||
452 echo "$line" | grep -q built > /dev/null ||
453 echo "$line" | grep -q installed > /dev/null; then
454 version=`echo "$line" | sed "s/$mod,\([^,]*\)[,:].*/\1/;t;d"`
455 echo " removing module $mod version $version"
456 $DKMS remove -m $mod -v $version --all 1>&2
457 fi
458 done
459 done
460 echo "Done."
461 fi
462
463 # Remove old installed modules
464 find /lib/modules -name vboxadd\* | xargs rm 2>/dev/null
465 find /lib/modules -name vboxguest\* | xargs rm 2>/dev/null
466 find /lib/modules -name vboxvfs\* | xargs rm 2>/dev/null
467 find /lib/modules -name vboxsf\* | xargs rm 2>/dev/null
468 find /lib/modules -name vboxvideo\* | xargs rm 2>/dev/null
469 depmod
470
471 # Remove old module sources
472 rm -rf /usr/src/vboxadd-* /usr/src/vboxguest-* /usr/src/vboxvfs-* /usr/src/vboxsf-* /usr/src/vboxvideo-*
473
474 # Remove other files
475 rm /sbin/mount.vboxsf 2>/dev/null
476 rm /etc/udev/rules.d/60-vboxadd.rules 2>/dev/null
477}
478
479dmnstatus()
480{
481 if running_vboxguest; then
482 echo "The VirtualBox Additions are currently running."
483 else
484 echo "The VirtualBox Additions are not currently running."
485 fi
486}
487
488case "$1" in
489start)
490 start
491 ;;
492stop)
493 stop
494 ;;
495restart)
496 restart
497 ;;
498setup)
499 setup
500 ;;
501cleanup)
502 cleanup
503 ;;
504status)
505 dmnstatus
506 ;;
507*)
508 echo "Usage: $0 {start|stop|restart|status}"
509 exit 1
510esac
511
512exit
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