VirtualBox

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

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

Linux Additions: don't automount the vboxsf folders twice

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 13.1 KB
Line 
1#! /bin/sh
2# Sun VirtualBox
3# Linux Additions kernel module init script ($Revision: 29016 $)
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
170fail()
171{
172 if [ "$system" = "gentoo" ]; then
173 eerror $1
174 exit 1
175 fi
176 fail_msg
177 echo "($1)"
178 exit 1
179}
180
181running_vboxguest()
182{
183 lsmod | grep -q "vboxguest[^_-]"
184}
185
186running_vboxadd()
187{
188 lsmod | grep -q "vboxadd[^_-]"
189}
190
191running_vboxsf()
192{
193 lsmod | grep -q "vboxsf[^_-]"
194}
195
196start()
197{
198 begin "Starting the VirtualBox Guest Additions ";
199 running_vboxguest || {
200 rm -f $dev || {
201 fail "Cannot remove $dev"
202 }
203
204 rm -f $userdev || {
205 fail "Cannot remove $userdev"
206 }
207
208 $MODPROBE vboxguest >/dev/null 2>&1 || {
209 fail "modprobe vboxguest failed"
210 }
211 sleep .5
212 }
213 if [ ! -c $dev ]; then
214 maj=`sed -n 's;\([0-9]\+\) vboxguest;\1;p' /proc/devices`
215 if [ ! -z "$maj" ]; then
216 min=0
217 else
218 min=`sed -n 's;\([0-9]\+\) vboxguest;\1;p' /proc/misc`
219 if [ ! -z "$min" ]; then
220 maj=10
221 fi
222 fi
223 test -z "$maj" && {
224 rmmod vboxguest 2>/dev/null
225 fail "Cannot locate the VirtualBox device"
226 }
227
228 mknod -m 0664 $dev c $maj $min || {
229 rmmod vboxguest 2>/dev/null
230 fail "Cannot create device $dev with major $maj and minor $min"
231 }
232 fi
233 chown $owner:$group $dev 2>/dev/null || {
234 rm -f $dev 2>/dev/null
235 rm -f $userdev 2>/dev/null
236 rmmod vboxguest 2>/dev/null
237 fail "Cannot change owner $owner:$group for device $dev"
238 }
239
240 if [ ! -c $userdev ]; then
241 maj=10
242 min=`sed -n 's;\([0-9]\+\) vboxuser;\1;p' /proc/misc`
243 if [ ! -z "$min" ]; then
244 mknod -m 0666 $userdev c $maj $min || {
245 rm -f $dev 2>/dev/null
246 rmmod vboxguest 2>/dev/null
247 fail "Cannot create device $userdev with major $maj and minor $min"
248 }
249 chown $owner:$group $userdev 2>/dev/null || {
250 rm -f $dev 2>/dev/null
251 rm -f $userdev 2>/dev/null
252 rmmod vboxguest 2>/dev/null
253 fail "Cannot change owner $owner:$group for device $userdev"
254 }
255 fi
256 fi
257
258 if [ -n "$BUILDVBOXSF" ]; then
259 running_vboxsf || {
260 $MODPROBE vboxsf > /dev/null 2>&1 || {
261 if dmesg | grep "vboxConnect failed" > /dev/null 2>&1; then
262 fail_msg
263 echo "Unable to start shared folders support. Make sure that your VirtualBox build"
264 echo "supports this feature."
265 exit 1
266 fi
267 fail "modprobe vboxsf failed"
268 }
269 }
270 fi
271
272 # Mount all shared folders from /etc/fstab. Normally this is done by some
273 # other startup script but this requires the vboxdrv kernel module loaded.
274 # This isn't necessary anymore as the vboxsf module is autoloaded.
275 # mount -a -t vboxsf
276
277 succ_msg
278 return 0
279}
280
281stop()
282{
283 begin "Stopping VirtualBox Additions ";
284 if ! umount -a -t vboxsf 2>/dev/null; then
285 fail "Cannot unmount vboxsf folders"
286 fi
287 if [ -n "$BUILDVBOXSF" ]; then
288 if running_vboxsf; then
289 rmmod vboxsf 2>/dev/null || fail "Cannot unload module vboxsf"
290 fi
291 fi
292 if running_vboxguest; then
293 rmmod vboxguest 2>/dev/null || fail "Cannot unload module vboxguest"
294 rm -f $userdev || fail "Cannot unlink $userdev"
295 rm -f $dev || fail "Cannot unlink $dev"
296 fi
297 succ_msg
298 return 0
299}
300
301restart()
302{
303 stop && start
304 return 0
305}
306
307# setup_script
308setup()
309{
310 # don't stop the old modules here -- they might be in use
311 if find /lib/modules/`uname -r` -name "vboxvideo\.*" 2>/dev/null|grep -q vboxvideo; then
312 begin "Removing old VirtualBox vboxvideo kernel module"
313 find /lib/modules/`uname -r` -name "vboxvideo\.*" 2>/dev/null|xargs rm -f 2>/dev/null
314 succ_msg
315 fi
316 if find /lib/modules/`uname -r` -name "vboxsf\.*" 2>/dev/null|grep -q vboxsf; then
317 begin "Removing old VirtualBox vboxsf kernel module"
318 find /lib/modules/`uname -r` -name "vboxsf\.*" 2>/dev/null|xargs rm -f 2>/dev/null
319 succ_msg
320 fi
321 if find /lib/modules/`uname -r` -name "vboxguest\.*" 2>/dev/null|grep -q vboxguest; then
322 begin "Removing old VirtualBox vboxguest kernel module"
323 find /lib/modules/`uname -r` -name "vboxguest\.*" 2>/dev/null|xargs rm -f 2>/dev/null
324 succ_msg
325 fi
326 begin "Building the VirtualBox Guest Additions kernel modules"
327 if ! sh /usr/share/$PACKAGE/test/build_in_tmp \
328 --no-dkms --no-print-directory > $LOG 2>&1; then
329 fail "`printf "Your system does not seem to be set up to build kernel modules.\nLook at $LOG to find out what went wrong"`"
330 fi
331 echo
332 if ! sh /usr/share/$PACKAGE/test_drm/build_in_tmp \
333 --no-dkms --no-print-directory >> $LOG 2>&1; then
334 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"
335 BUILDVBOXVIDEO=""
336 fi
337 begin "Building the main Guest Additions module"
338 if ! $BUILDVBOXGUEST \
339 --save-module-symvers /tmp/vboxguest-Module.symvers \
340 --no-print-directory install >> $LOG 2>&1; then
341 fail "Look at $LOG to find out what went wrong"
342 fi
343 succ_msg
344 if [ -n "$BUILDVBOXSF" ]; then
345 begin "Building the shared folder support module"
346 if ! $BUILDVBOXSF \
347 --use-module-symvers /tmp/vboxguest-Module.symvers \
348 --no-print-directory install >> $LOG 2>&1; then
349 fail "Look at $LOG to find out what went wrong"
350 fi
351 succ_msg
352 fi
353 if [ -n "$BUILDVBOXVIDEO" ]; then
354 begin "Building the OpenGL support module"
355 if ! $BUILDVBOXVIDEO \
356 --use-module-symvers /tmp/vboxguest-Module.symvers \
357 --no-print-directory install >> $LOG 2>&1; then
358 fail "Look at $LOG to find out what went wrong"
359 fi
360 succ_msg
361 fi
362 depmod
363
364 begin "Doing non-kernel setup of the Guest Additions"
365 echo "Creating user for the Guest Additions." >> $LOG
366 # This is the LSB version of useradd and should work on recent
367 # distributions
368 useradd -d /var/run/vboxadd -g 1 -r -s /bin/false vboxadd >/dev/null 2>&1
369 # And for the others, we choose a UID ourselves
370 useradd -d /var/run/vboxadd -g 1 -u 501 -o -s /bin/false vboxadd >/dev/null 2>&1
371
372 # Create udev description file
373 if [ -d /etc/udev/rules.d ]; then
374 echo "Creating udev rule for the Guest Additions kernel module." >> $LOG
375 udev_call=""
376 udev_app=`which udevadm 2> /dev/null`
377 if [ $? -eq 0 ]; then
378 udev_call="${udev_app} version 2> /dev/null"
379 else
380 udev_app=`which udevinfo 2> /dev/null`
381 if [ $? -eq 0 ]; then
382 udev_call="${udev_app} -V 2> /dev/null"
383 fi
384 fi
385 udev_fix="="
386 if [ "${udev_call}" != "" ]; then
387 udev_out=`${udev_call}`
388 udev_ver=`expr "$udev_out" : '[^0-9]*\([0-9]*\)'`
389 if [ "$udev_ver" = "" -o "$udev_ver" -lt 55 ]; then
390 udev_fix=""
391 fi
392 fi
393 ## @todo 60-vboxadd.rules -> 60-vboxguest.rules ?
394 echo "KERNEL=${udev_fix}\"vboxguest\", NAME=\"vboxguest\", OWNER=\"vboxadd\", MODE=\"0660\"" > /etc/udev/rules.d/60-vboxadd.rules
395 echo "KERNEL=${udev_fix}\"vboxuser\", NAME=\"vboxuser\", OWNER=\"vboxadd\", MODE=\"0666\"" >> /etc/udev/rules.d/60-vboxadd.rules
396 fi
397
398 # Put mount.vboxsf in the right place
399 ln -sf "$lib_path/$PACKAGE/mount.vboxsf" /sbin
400 # At least Fedora 11 and Fedora 12 demand on the correct security context when
401 # executing this command from service scripts. Shouldn't hurt for other distributions.
402 chcon -u system_u -t mount_exec_t "$lib_path/$PACKAGE/mount.vboxsf" > /dev/null 2>&1
403
404 succ_msg
405 if running_vboxguest || running_vboxadd; then
406 printf "You should restart your guest to make sure the new modules are actually used\n\n"
407 else
408 start
409 fi
410}
411
412# cleanup_script
413cleanup()
414{
415 # Delete old versions of VBox modules.
416 DKMS=`which dkms 2>/dev/null`
417 if [ -n "$DKMS" ]; then
418 echo "Attempt to remove old DKMS modules..."
419 for mod in vboxadd vboxguest vboxvfs vboxsf vboxvideo; do
420 $DKMS status -m $mod | while read line; do
421 if echo "$line" | grep -q added > /dev/null ||
422 echo "$line" | grep -q built > /dev/null ||
423 echo "$line" | grep -q installed > /dev/null; then
424 version=`echo "$line" | sed "s/$mod,\([^,]*\)[,:].*/\1/;t;d"`
425 echo " removing module $mod version $version"
426 $DKMS remove -m $mod -v $version --all 1>&2
427 fi
428 done
429 done
430 echo "Done."
431 fi
432
433 # Remove old installed modules
434 find /lib/modules -name vboxadd\* | xargs rm 2>/dev/null
435 find /lib/modules -name vboxguest\* | xargs rm 2>/dev/null
436 find /lib/modules -name vboxvfs\* | xargs rm 2>/dev/null
437 find /lib/modules -name vboxsf\* | xargs rm 2>/dev/null
438 find /lib/modules -name vboxvideo\* | xargs rm 2>/dev/null
439 depmod
440
441 # Remove old module sources
442 rm -rf /usr/src/vboxadd-* /usr/src/vboxguest-* /usr/src/vboxvfs-* /usr/src/vboxsf-* /usr/src/vboxvideo-*
443
444 # Remove other files
445 rm /sbin/mount.vboxsf 2>/dev/null
446 rm /etc/udev/rules.d/60-vboxadd.rules 2>/dev/null
447}
448
449dmnstatus()
450{
451 if running_vboxguest; then
452 echo "The VirtualBox Additions are currently running."
453 else
454 echo "The VirtualBox Additions are not currently running."
455 fi
456}
457
458case "$1" in
459start)
460 start
461 ;;
462stop)
463 stop
464 ;;
465restart)
466 restart
467 ;;
468setup)
469 setup
470 ;;
471cleanup)
472 cleanup
473 ;;
474status)
475 dmnstatus
476 ;;
477*)
478 echo "Usage: $0 {start|stop|restart|status}"
479 exit 1
480esac
481
482exit
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