VirtualBox

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

Last change on this file since 36668 was 36668, checked in by vboxsync, 14 years ago

Additions/linux/installer: fix an error message on SUSE guests

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