VirtualBox

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

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

Installer/linux (guest): remove confusing sanity checks.

  • Property svn:eol-style set to LF
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 12.4 KB
Line 
1#! /bin/sh
2#
3# Linux Additions kernel module init script ($Revision: 58359 $)
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 lib_candidates="/usr/lib/i386-linux-gnu /usr/lib /lib"
48 ;;
49 x86_64|amd64)
50 cpu="amd64"
51 lib_candidates="/usr/lib/x86_64-linux-gnu /usr/lib64 /usr/lib /lib64 /lib"
52 ;;
53esac
54for i in $lib_candidates; do
55 if test -d "$i/VBoxGuestAdditions"; then
56 lib_path=$i
57 break
58 fi
59done
60
61# Preamble for Gentoo
62if [ "`which $0`" = "/sbin/rc" ]; then
63 shift
64fi
65
66begin()
67{
68 test -n "${2}" && echo "${SCRIPTNAME}: ${1}."
69 logger -t "${SCRIPTNAME}" "${1}."
70}
71
72succ_msg()
73{
74 logger -t "${SCRIPTNAME}" "${1}."
75}
76
77show_error()
78{
79 echo "${SCRIPTNAME}: failed: ${1}." >&2
80 logger -t "${SCRIPTNAME}" "${1}."
81}
82
83fail()
84{
85 show_error "$1"
86 exit 1
87}
88
89dev=/dev/vboxguest
90userdev=/dev/vboxuser
91config=/var/lib/VBoxGuestAdditions/config
92owner=vboxadd
93group=1
94
95running_vboxguest()
96{
97 lsmod | grep -q "vboxguest[^_-]"
98}
99
100running_vboxadd()
101{
102 lsmod | grep -q "vboxadd[^_-]"
103}
104
105running_vboxsf()
106{
107 lsmod | grep -q "vboxsf[^_-]"
108}
109
110running_vboxvideo()
111{
112 lsmod | grep -q "vboxvideo[^_-]"
113}
114
115do_vboxguest_non_udev()
116{
117 if [ ! -c $dev ]; then
118 maj=`sed -n 's;\([0-9]\+\) vboxguest;\1;p' /proc/devices`
119 if [ ! -z "$maj" ]; then
120 min=0
121 else
122 min=`sed -n 's;\([0-9]\+\) vboxguest;\1;p' /proc/misc`
123 if [ ! -z "$min" ]; then
124 maj=10
125 fi
126 fi
127 test -z "$maj" && {
128 rmmod vboxguest 2>/dev/null
129 fail "Cannot locate the VirtualBox device"
130 }
131
132 mknod -m 0664 $dev c $maj $min || {
133 rmmod vboxguest 2>/dev/null
134 fail "Cannot create device $dev with major $maj and minor $min"
135 }
136 fi
137 chown $owner:$group $dev 2>/dev/null || {
138 rm -f $dev 2>/dev/null
139 rm -f $userdev 2>/dev/null
140 rmmod vboxguest 2>/dev/null
141 fail "Cannot change owner $owner:$group for device $dev"
142 }
143
144 if [ ! -c $userdev ]; then
145 maj=10
146 min=`sed -n 's;\([0-9]\+\) vboxuser;\1;p' /proc/misc`
147 if [ ! -z "$min" ]; then
148 mknod -m 0666 $userdev c $maj $min || {
149 rm -f $dev 2>/dev/null
150 rmmod vboxguest 2>/dev/null
151 fail "Cannot create device $userdev with major $maj and minor $min"
152 }
153 chown $owner:$group $userdev 2>/dev/null || {
154 rm -f $dev 2>/dev/null
155 rm -f $userdev 2>/dev/null
156 rmmod vboxguest 2>/dev/null
157 fail "Cannot change owner $owner:$group for device $userdev"
158 }
159 fi
160 fi
161}
162
163start()
164{
165 begin "Starting the VirtualBox Guest Additions" console;
166 uname -r | grep -q -E '^2\.6|^3|^4' 2>/dev/null &&
167 ps -A -o comm | grep -q '/*udevd$' 2>/dev/null ||
168 no_udev=1
169 running_vboxguest || {
170 rm -f $dev || {
171 fail "Cannot remove $dev"
172 }
173
174 rm -f $userdev || {
175 fail "Cannot remove $userdev"
176 }
177
178 $MODPROBE vboxguest >/dev/null 2>&1 || {
179 setup
180 $MODPROBE vboxguest >/dev/null 2>&1 ||
181 fail "modprobe vboxguest failed"
182 }
183 case "$no_udev" in 1)
184 sleep .5;;
185 esac
186 }
187 case "$no_udev" in 1)
188 do_vboxguest_non_udev;;
189 esac
190
191 running_vboxsf || {
192 $MODPROBE vboxsf > /dev/null 2>&1 || {
193 if dmesg | grep "vboxConnect failed" > /dev/null 2>&1; then
194 show_error "Unable to start shared folders support. Make sure that your VirtualBox build"
195 show_error "supports this feature."
196 exit 1
197 fi
198 fail "modprobe vboxsf failed"
199 }
200 }
201
202 # This is needed as X.Org Server 1.13 does not auto-load the module.
203 running_vboxvideo || $MODPROBE vboxvideo > /dev/null 2>&1
204
205 # Mount all shared folders from /etc/fstab. Normally this is done by some
206 # other startup script but this requires the vboxdrv kernel module loaded.
207 # This isn't necessary anymore as the vboxsf module is autoloaded.
208 # mount -a -t vboxsf
209
210 succ_msg
211 return 0
212}
213
214stop()
215{
216 begin "Stopping VirtualBox Additions" console;
217 if ! umount -a -t vboxsf 2>/dev/null; then
218 fail "Cannot unmount vboxsf folders"
219 fi
220 if running_vboxsf; then
221 rmmod vboxsf 2>/dev/null || fail "Cannot unload module vboxsf"
222 fi
223 if running_vboxguest; then
224 rmmod vboxguest 2>/dev/null || fail "Cannot unload module vboxguest"
225 rm -f $userdev || fail "Cannot unlink $userdev"
226 rm -f $dev || fail "Cannot unlink $dev"
227 fi
228 succ_msg
229 return 0
230}
231
232restart()
233{
234 stop && start
235 return 0
236}
237
238# Remove any existing VirtualBox guest kernel modules from the disk, but not
239# from the kernel as they may still be in use
240cleanup_modules()
241{
242 begin "Removing existing VirtualBox kernel modules"
243 # We no longer support DKMS, remove any leftovers.
244 for i in vboxguest vboxadd vboxsf vboxvfs vboxvideo; do
245 rm -rf "/var/lib/dkms/${i}"*
246 done
247 for i in $OLDMODULES; do
248 find /lib/modules -name $i\* | xargs rm 2>/dev/null
249 done
250 succ_msg
251}
252
253# Build and install the VirtualBox guest kernel modules
254setup_modules()
255{
256 # don't stop the old modules here -- they might be in use
257 cleanup_modules
258 begin "Building the VirtualBox Guest Additions kernel modules"
259
260 begin "Building the main Guest Additions module"
261 if ! $BUILDINTMP \
262 --save-module-symvers /tmp/vboxguest-Module.symvers \
263 --module-source $MODULE_SRC/vboxguest \
264 --no-print-directory install >> $LOG 2>&1; then
265 show_error "Look at $LOG to find out what went wrong"
266 return 1
267 fi
268 succ_msg
269 begin "Building the shared folder support module"
270 if ! $BUILDINTMP \
271 --use-module-symvers /tmp/vboxguest-Module.symvers \
272 --module-source $MODULE_SRC/vboxsf \
273 --no-print-directory install >> $LOG 2>&1; then
274 show_error "Look at $LOG to find out what went wrong"
275 return 1
276 fi
277 succ_msg
278 if expr `uname -r` '<' '2.6.27' > /dev/null; then
279 echo "Not building the VirtualBox advanced graphics driver as this Linux version is"
280 echo "too old to use it."
281 else
282 begin "Building the OpenGL support module"
283 if ! $BUILDINTMP \
284 --use-module-symvers /tmp/vboxguest-Module.symvers \
285 --module-source $MODULE_SRC/vboxvideo \
286 --no-print-directory install >> $LOG 2>&1; then
287 show_error "Look at $LOG to find out what went wrong. All other modules were built successfully."
288 else
289 succ_msg
290 fi
291 fi
292 depmod
293 return 0
294}
295
296# Do non-kernel bits needed for the kernel modules to work properly (user
297# creation, udev, mount helper...)
298extra_setup()
299{
300 begin "Doing non-kernel setup of the Guest Additions"
301 echo "Creating user for the Guest Additions." >> $LOG
302 # This is the LSB version of useradd and should work on recent
303 # distributions
304 useradd -d /var/run/vboxadd -g 1 -r -s /bin/false vboxadd >/dev/null 2>&1
305 # And for the others, we choose a UID ourselves
306 useradd -d /var/run/vboxadd -g 1 -u 501 -o -s /bin/false vboxadd >/dev/null 2>&1
307
308 # Add a group "vboxsf" for Shared Folders access
309 # All users which want to access the auto-mounted Shared Folders have to
310 # be added to this group.
311 groupadd -r -f vboxsf >/dev/null 2>&1
312
313 # Create udev description file
314 if [ -d /etc/udev/rules.d ]; then
315 echo "Creating udev rule for the Guest Additions kernel module." >> $LOG
316 udev_call=""
317 udev_app=`which udevadm 2> /dev/null`
318 if [ $? -eq 0 ]; then
319 udev_call="${udev_app} version 2> /dev/null"
320 else
321 udev_app=`which udevinfo 2> /dev/null`
322 if [ $? -eq 0 ]; then
323 udev_call="${udev_app} -V 2> /dev/null"
324 fi
325 fi
326 udev_fix="="
327 if [ "${udev_call}" != "" ]; then
328 udev_out=`${udev_call}`
329 udev_ver=`expr "$udev_out" : '[^0-9]*\([0-9]*\)'`
330 if [ "$udev_ver" = "" -o "$udev_ver" -lt 55 ]; then
331 udev_fix=""
332 fi
333 fi
334 ## @todo 60-vboxadd.rules -> 60-vboxguest.rules ?
335 echo "KERNEL=${udev_fix}\"vboxguest\", NAME=\"vboxguest\", OWNER=\"vboxadd\", MODE=\"0660\"" > /etc/udev/rules.d/60-vboxadd.rules
336 echo "KERNEL=${udev_fix}\"vboxuser\", NAME=\"vboxuser\", OWNER=\"vboxadd\", MODE=\"0666\"" >> /etc/udev/rules.d/60-vboxadd.rules
337 fi
338
339 # Put mount.vboxsf in the right place
340 ln -sf "$lib_path/$PACKAGE/mount.vboxsf" /sbin
341 # And an rc file to re-build the kernel modules and re-set-up the X server.
342 ln -sf "$lib_path/$PACKAGE/vboxadd" /sbin/rcvboxadd
343 ln -sf "$lib_path/$PACKAGE/vboxadd-x11" /sbin/rcvboxadd-x11
344 # At least Fedora 11 and Fedora 12 require the correct security context when
345 # executing this command from service scripts. Shouldn't hurt for other
346 # distributions.
347 chcon -u system_u -t mount_exec_t "$lib_path/$PACKAGE/mount.vboxsf" > /dev/null 2>&1
348 # And at least Fedora 15 needs this for the acceleration support check to
349 # work
350 redhat_release=`cat /etc/redhat-release 2> /dev/null`
351 case "$redhat_release" in Fedora\ release\ 15* )
352 for i in "$lib_path"/*.so
353 do
354 restorecon "$i" >/dev/null
355 done
356 ;;
357 esac
358
359 succ_msg
360}
361
362# setup_script
363setup()
364{
365 begin "Building Guest Additions kernel modules" console
366 if test -r $config; then
367 . $config
368 else
369 fail "Configuration file $config not found"
370 fi
371 test -n "$INSTALL_DIR" -a -n "$INSTALL_VER" ||
372 fail "Configuration file $config not complete"
373 export BUILD_TYPE
374 export USERNAME
375
376 MODULE_SRC="$INSTALL_DIR/src/vboxguest-$INSTALL_VER"
377 BUILDINTMP="$MODULE_SRC/build_in_tmp"
378 chcon -t bin_t "$BUILDINTMP" > /dev/null 2>&1
379
380 setup_modules || \
381 show_error "Please check that you have gcc, make, the header files for your Linux kernel and possibly perl installed."
382 mod_succ="$?"
383 extra_setup
384 if [ "$mod_succ" -eq "0" ]; then
385 if running_vboxguest || running_vboxadd; then
386 begin "You should restart your guest to make sure the new modules are actually used" console
387 fi
388 fi
389 return "${mod_succ}"
390}
391
392# cleanup_script
393cleanup()
394{
395 if test -r $config; then
396 . $config
397 test -n "$INSTALL_DIR" -a -n "$INSTALL_VER" ||
398 fail "Configuration file $config not complete"
399 else
400 fail "Configuration file $config not found"
401 fi
402
403 # Delete old versions of VBox modules.
404 cleanup_modules
405 depmod
406
407 # Remove old module sources
408 for i in $OLDMODULES; do
409 rm -rf /usr/src/$i-*
410 done
411
412 # Remove other files
413 rm /sbin/mount.vboxsf 2>/dev/null
414 rm /sbin/rcvboxadd 2>/dev/null
415 rm /sbin/rcvboxadd-x11 2>/dev/null
416 rm /etc/udev/rules.d/60-vboxadd.rules 2>/dev/null
417}
418
419dmnstatus()
420{
421 if running_vboxguest; then
422 echo "The VirtualBox Additions are currently running."
423 else
424 echo "The VirtualBox Additions are not currently running."
425 fi
426}
427
428case "$1" in
429start)
430 start
431 ;;
432stop)
433 stop
434 ;;
435restart)
436 restart
437 ;;
438setup)
439 setup && start
440 ;;
441cleanup)
442 cleanup
443 ;;
444status)
445 dmnstatus
446 ;;
447*)
448 echo "Usage: $0 {start|stop|restart|status|setup}"
449 exit 1
450esac
451
452exit
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