VirtualBox

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

Last change on this file since 65512 was 64718, checked in by vboxsync, 8 years ago

bugref:8530: Documentation: improve automated instructions for building kernel modules: make the Additions use check_module_dependencies.sh too. This should also greatly increase testing.

  • Property svn:eol-style set to LF
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 15.2 KB
Line 
1#! /bin/sh
2#
3# Linux Additions kernel module init script ($Revision: 64718 $)
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
31## @todo This file duplicates a lot of script with vboxdrv.sh. When making
32# changes please try to reduce differences between the two wherever possible.
33
34PATH=$PATH:/bin:/sbin:/usr/sbin
35PACKAGE=VBoxGuestAdditions
36LOG="/var/log/vboxadd-setup.log"
37MODPROBE=/sbin/modprobe
38OLDMODULES="vboxguest vboxadd vboxsf vboxvfs vboxvideo"
39SERVICE="VirtualBox Guest Additions"
40QUICKSETUP=
41## systemd logs information about service status, otherwise do that ourselves.
42QUIET=
43
44# Rotate log files
45mv "${LOG}.3" "${LOG}.4" 2>/dev/null
46mv "${LOG}.2" "${LOG}.3" 2>/dev/null
47mv "${LOG}.1" "${LOG}.2" 2>/dev/null
48mv "${LOG}" "${LOG}.1" 2>/dev/null
49
50if $MODPROBE -c 2>/dev/null | grep -q '^allow_unsupported_modules *0'; then
51 MODPROBE="$MODPROBE --allow-unsupported-modules"
52fi
53
54# Check architecture
55cpu=`uname -m`;
56case "$cpu" in
57 i[3456789]86|x86)
58 cpu="x86"
59 ldconfig_arch="(libc6)"
60 lib_candidates="/usr/lib/i386-linux-gnu /usr/lib /lib"
61 ;;
62 x86_64|amd64)
63 cpu="amd64"
64 ldconfig_arch="(libc6,x86-64)"
65 lib_candidates="/usr/lib/x86_64-linux-gnu /usr/lib64 /usr/lib /lib64 /lib"
66 ;;
67esac
68for i in $lib_candidates; do
69 if test -d "$i/VBoxGuestAdditions"; then
70 lib_path=$i
71 break
72 fi
73done
74
75# Preamble for Gentoo
76if [ "`which $0`" = "/sbin/rc" ]; then
77 shift
78fi
79
80begin()
81{
82 test -z "${QUIET}" && echo "${SERVICE}: ${1}"
83}
84
85info()
86{
87 if test -z "${QUIET}"; then
88 echo "${SERVICE}: $1"
89 else
90 echo "$1"
91 fi
92}
93
94fail()
95{
96 log "${1}"
97 echo "$1" >&2
98 echo "The log file $LOG may contain further information." >&2
99 exit 1
100}
101
102log()
103{
104 echo "${1}" >> "${LOG}"
105}
106
107dev=/dev/vboxguest
108userdev=/dev/vboxuser
109config=/var/lib/VBoxGuestAdditions/config
110owner=vboxadd
111group=1
112
113running_vboxguest()
114{
115 lsmod | grep -q "vboxguest[^_-]"
116}
117
118running_vboxadd()
119{
120 lsmod | grep -q "vboxadd[^_-]"
121}
122
123running_vboxsf()
124{
125 lsmod | grep -q "vboxsf[^_-]"
126}
127
128running_vboxvideo()
129{
130 lsmod | grep -q "vboxvideo[^_-]"
131}
132
133do_vboxguest_non_udev()
134{
135 if [ ! -c $dev ]; then
136 maj=`sed -n 's;\([0-9]\+\) vboxguest;\1;p' /proc/devices`
137 if [ ! -z "$maj" ]; then
138 min=0
139 else
140 min=`sed -n 's;\([0-9]\+\) vboxguest;\1;p' /proc/misc`
141 if [ ! -z "$min" ]; then
142 maj=10
143 fi
144 fi
145 test -z "$maj" && {
146 rmmod vboxguest 2>/dev/null
147 fail "Cannot locate the VirtualBox device"
148 }
149
150 mknod -m 0664 $dev c $maj $min || {
151 rmmod vboxguest 2>/dev/null
152 fail "Cannot create device $dev with major $maj and minor $min"
153 }
154 fi
155 chown $owner:$group $dev 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 $dev"
160 }
161
162 if [ ! -c $userdev ]; then
163 maj=10
164 min=`sed -n 's;\([0-9]\+\) vboxuser;\1;p' /proc/misc`
165 if [ ! -z "$min" ]; then
166 mknod -m 0666 $userdev c $maj $min || {
167 rm -f $dev 2>/dev/null
168 rmmod vboxguest 2>/dev/null
169 fail "Cannot create device $userdev with major $maj and minor $min"
170 }
171 chown $owner:$group $userdev 2>/dev/null || {
172 rm -f $dev 2>/dev/null
173 rm -f $userdev 2>/dev/null
174 rmmod vboxguest 2>/dev/null
175 fail "Cannot change owner $owner:$group for device $userdev"
176 }
177 fi
178 fi
179}
180
181start()
182{
183 begin "Starting."
184 # If we got this far assume that the slow set-up has been done.
185 QUICKSETUP=yes
186 if test -r $config; then
187 . $config
188 else
189 fail "Configuration file $config not found"
190 fi
191 test -n "$INSTALL_DIR" -a -n "$INSTALL_VER" ||
192 fail "Configuration file $config not complete"
193 uname -r | grep -q -E '^2\.6|^3|^4' 2>/dev/null &&
194 ps -A -o comm | grep -q '/*udevd$' 2>/dev/null ||
195 no_udev=1
196 running_vboxguest || {
197 rm -f $dev || {
198 fail "Cannot remove $dev"
199 }
200
201 rm -f $userdev || {
202 fail "Cannot remove $userdev"
203 }
204
205 $MODPROBE vboxguest >/dev/null 2>&1 || {
206 setup
207 $MODPROBE vboxguest >/dev/null 2>&1 || {
208 "${INSTALL_DIR}/init/vboxadd-x11" cleanup 2>> "${LOG}"
209 fail "modprobe vboxguest failed"
210 }
211 }
212 case "$no_udev" in 1)
213 sleep .5;;
214 esac
215 }
216 case "$no_udev" in 1)
217 do_vboxguest_non_udev;;
218 esac
219
220 running_vboxsf || {
221 $MODPROBE vboxsf > /dev/null 2>&1 || {
222 if dmesg | grep "VbglR0SfConnect failed" > /dev/null 2>&1; then
223 info "Unable to start shared folders support. Make sure that your VirtualBox build supports this feature."
224 else
225 info "modprobe vboxsf failed"
226 fi
227 }
228 }
229
230 # Put the X.Org driver in place. This is harmless if it is not needed.
231 "${INSTALL_DIR}/init/vboxadd-x11" setup 2>> "${LOG}"
232 # Install the guest OpenGL drivers. For now we don't support
233 # multi-architecture installations
234 rm -f /etc/ld.so.conf.d/00vboxvideo.conf
235 if /usr/bin/VBoxClient --check3d 2>/dev/null; then
236 mkdir -p /var/lib/VBoxGuestAdditions/lib
237 ln -sf "${INSTALL_DIR}/lib/VBoxOGL.so" /var/lib/VBoxGuestAdditions/lib/libGL.so.1
238 ln -sf "${INSTALL_DIR}/lib/VBoxEGL.so" /var/lib/VBoxGuestAdditions/lib/libEGL.so.1
239 # SELinux for the OpenGL libraries, so that gdm can load them during the
240 # acceleration support check. This prevents an "Oh no, something has gone
241 # wrong!" error when starting EL7 guests.
242 if test -e /etc/selinux/config; then
243 if command -v semanage > /dev/null; then
244 semanage fcontext -a -t lib_t "/var/lib/VBoxGuestAdditions/lib/libGL.so.1"
245 semanage fcontext -a -t lib_t "/var/lib/VBoxGuestAdditions/lib/libEGL.so.1"
246 fi
247 chcon -h -t lib_t "/var/lib/VBoxGuestAdditions/lib/libGL.so.1"
248 chcon -h -t lib_t "/var/lib/VBoxGuestAdditions/lib/libEGL.so.1"
249 fi
250 echo "/var/lib/VBoxGuestAdditions/lib" > /etc/ld.so.conf.d/00vboxvideo.conf
251 fi
252 ldconfig
253
254 # Mount all shared folders from /etc/fstab. Normally this is done by some
255 # other startup script but this requires the vboxdrv kernel module loaded.
256 # This isn't necessary anymore as the vboxsf module is autoloaded.
257 # mount -a -t vboxsf
258
259 return 0
260}
261
262stop()
263{
264 begin "Stopping."
265 if test -r /etc/ld.so.conf.d/00vboxvideo.conf; then
266 rm /etc/ld.so.conf.d/00vboxvideo.conf
267 ldconfig
268 fi
269 if ! umount -a -t vboxsf 2>/dev/null; then
270 fail "Cannot unmount vboxsf folders"
271 fi
272 modprobe -q -r -a vboxvideo vboxsf vboxguest
273 egrep -q 'vboxguest|vboxsf|vboxvideo' /proc/modules &&
274 info "You may need to restart your guest system to finish removing the guest drivers."
275 rm -f $userdev || fail "Cannot unlink $userdev"
276 rm -f $dev || fail "Cannot unlink $dev"
277 return 0
278}
279
280restart()
281{
282 stop && start
283 return 0
284}
285
286# Remove any existing VirtualBox guest kernel modules from the disk, but not
287# from the kernel as they may still be in use
288cleanup_modules()
289{
290 log "Removing existing VirtualBox kernel modules."
291 for i in ${OLDMODULES}; do
292 # We no longer support DKMS, remove any leftovers.
293 rm -rf "/var/lib/dkms/${i}"*
294 # And remove old modules.
295 rm -f /lib/modules/*/misc/"${i}"*
296 done
297 # Remove leftover module folders.
298 for i in /lib/modules/*/misc; do
299 test -d "${i}" && rmdir -p "${i}" 2>/dev/null
300 done
301 rm -f /etc/depmod.d/vboxvideo-upstream.conf
302}
303
304# Build and install the VirtualBox guest kernel modules
305setup_modules()
306{
307 # don't stop the old modules here -- they might be in use
308 test -z "${QUICKSETUP}" && cleanup_modules
309 # This does not work for 2.4 series kernels. How sad.
310 test -n "${QUICKSETUP}" && test -f "${MODULE_DIR}/vboxguest.ko" && return 0
311 info "Building the VirtualBox Guest Additions kernel modules."
312
313 log "Building the main Guest Additions module."
314 if ! $BUILDINTMP \
315 --save-module-symvers /tmp/vboxguest-Module.symvers \
316 --module-source $MODULE_SRC/vboxguest \
317 --no-print-directory install >> $LOG 2>&1; then
318 # If check_module_dependencies.sh fails it prints a message itself.
319 "${INSTALL_DIR}"/other/check_module_dependencies.sh 2>&1 &&
320 info "Look at $LOG to find out what went wrong"
321 return 1
322 fi
323 log "Building the shared folder support module"
324 if ! $BUILDINTMP \
325 --use-module-symvers /tmp/vboxguest-Module.symvers \
326 --module-source $MODULE_SRC/vboxsf \
327 --no-print-directory install >> $LOG 2>&1; then
328 info "Look at $LOG to find out what went wrong"
329 return 1
330 fi
331 log "Building the graphics driver module"
332 if ! $BUILDINTMP \
333 --use-module-symvers /tmp/vboxguest-Module.symvers \
334 --module-source $MODULE_SRC/vboxvideo \
335 --no-print-directory install >> $LOG 2>&1; then
336 info "Look at $LOG to find out what went wrong"
337 fi
338 echo "override vboxguest * misc" > /etc/depmod.d/vboxvideo-upstream.conf
339 echo "override vboxsf * misc" >> /etc/depmod.d/vboxvideo-upstream.conf
340 echo "override vboxvideo * misc" >> /etc/depmod.d/vboxvideo-upstream.conf
341 depmod
342 return 0
343}
344
345# Do non-kernel bits needed for the kernel modules to work properly (user
346# creation, udev, mount helper...)
347extra_setup()
348{
349 log "Creating user for the Guest Additions."
350 # This is the LSB version of useradd and should work on recent
351 # distributions
352 useradd -d /var/run/vboxadd -g 1 -r -s /bin/false vboxadd >/dev/null 2>&1
353 # And for the others, we choose a UID ourselves
354 useradd -d /var/run/vboxadd -g 1 -u 501 -o -s /bin/false vboxadd >/dev/null 2>&1
355
356 # Add a group "vboxsf" for Shared Folders access
357 # All users which want to access the auto-mounted Shared Folders have to
358 # be added to this group.
359 groupadd -r -f vboxsf >/dev/null 2>&1
360
361 # Create udev description file
362 if [ -d /etc/udev/rules.d ]; then
363 log "Creating udev rule for the Guest Additions kernel module."
364 udev_call=""
365 udev_app=`which udevadm 2> /dev/null`
366 if [ $? -eq 0 ]; then
367 udev_call="${udev_app} version 2> /dev/null"
368 else
369 udev_app=`which udevinfo 2> /dev/null`
370 if [ $? -eq 0 ]; then
371 udev_call="${udev_app} -V 2> /dev/null"
372 fi
373 fi
374 udev_fix="="
375 if [ "${udev_call}" != "" ]; then
376 udev_out=`${udev_call}`
377 udev_ver=`expr "$udev_out" : '[^0-9]*\([0-9]*\)'`
378 if [ "$udev_ver" = "" -o "$udev_ver" -lt 55 ]; then
379 udev_fix=""
380 fi
381 fi
382 ## @todo 60-vboxadd.rules -> 60-vboxguest.rules ?
383 echo "KERNEL=${udev_fix}\"vboxguest\", NAME=\"vboxguest\", OWNER=\"vboxadd\", MODE=\"0660\"" > /etc/udev/rules.d/60-vboxadd.rules
384 echo "KERNEL=${udev_fix}\"vboxuser\", NAME=\"vboxuser\", OWNER=\"vboxadd\", MODE=\"0666\"" >> /etc/udev/rules.d/60-vboxadd.rules
385 fi
386
387 # Put mount.vboxsf in the right place
388 ln -sf "${INSTALL_DIR}/other/mount.vboxsf" /sbin
389 # And a post-installation script for rebuilding modules when a new kernel
390 # is installed.
391 mkdir -p /etc/kernel/postinst.d /etc/kernel/prerm.d
392 cat << EOF > /etc/kernel/postinst.d/vboxadd
393#!/bin/sh
394test -d "/lib/modules/\${1}/build" || exit 0
395KERN_DIR="/lib/modules/\${1}/build" MODULE_DIR="/lib/modules/\${1}/misc" \
396/sbin/rcvboxadd quicksetup
397exit 0
398EOF
399 cat << EOF > /etc/kernel/prerm.d/vboxadd
400#!/bin/sh
401for i in ${OLDMODULES}; do rm -f /lib/modules/"\${1}"/misc/"\${i}".ko; done
402rmdir -p /lib/modules/"\$1"/misc 2>/dev/null
403exit 0
404EOF
405 chmod 0755 /etc/kernel/postinst.d/vboxadd /etc/kernel/prerm.d/vboxadd
406 # SELinux security context for the mount helper.
407 if test -e /etc/selinux/config; then
408 # This is correct. semanage maps this to the real path, and it aborts
409 # with an error, telling you what you should have typed, if you specify
410 # the real path. The "chcon" is there as a back-up for old guests.
411 command -v semanage > /dev/null &&
412 semanage fcontext -a -t mount_exec_t "${INSTALL_DIR}/other/mount.vboxsf"
413 chcon -t mount_exec_t "${INSTALL_DIR}/other/mount.vboxsf"
414 fi
415}
416
417# setup_script
418setup()
419{
420 if test -r $config; then
421 . $config
422 else
423 fail "Configuration file $config not found"
424 fi
425 test -n "$INSTALL_DIR" -a -n "$INSTALL_VER" ||
426 fail "Configuration file $config not complete"
427 export BUILD_TYPE
428 export USERNAME
429
430 MODULE_SRC="$INSTALL_DIR/src/vboxguest-$INSTALL_VER"
431 BUILDINTMP="$MODULE_SRC/build_in_tmp"
432 chcon -t bin_t "$BUILDINTMP" > /dev/null 2>&1
433
434 if setup_modules; then
435 mod_succ=0
436 else
437 mod_succ=1
438 fi
439 test -n "${QUICKSETUP}" && return "${mod_succ}"
440 extra_setup
441 if [ "$mod_succ" -eq "0" ]; then
442 if running_vboxguest || running_vboxadd; then
443 info "You should restart your guest to make sure the new modules are actually used"
444 fi
445 fi
446 return "${mod_succ}"
447}
448
449# cleanup_script
450cleanup()
451{
452 if test -r $config; then
453 . $config
454 test -n "$INSTALL_DIR" -a -n "$INSTALL_VER" ||
455 fail "Configuration file $config not complete"
456 else
457 fail "Configuration file $config not found"
458 fi
459
460 # Delete old versions of VBox modules.
461 cleanup_modules
462 depmod
463
464 # Remove old module sources
465 for i in $OLDMODULES; do
466 rm -rf /usr/src/$i-*
467 done
468
469 # Clean-up X11-related bits
470 "${INSTALL_DIR}/init/vboxadd-x11" cleanup 2>> "${LOG}"
471
472 # Remove other files
473 rm /sbin/mount.vboxsf 2>/dev/null
474 rm -f /etc/kernel/postinst.d/vboxadd /etc/kernel/prerm.d/vboxadd
475 rmdir -p /etc/kernel/postinst.d /etc/kernel/prerm.d 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 "$2" in quiet)
489 QUIET=yes;;
490esac
491case "$1" in
492start)
493 start
494 ;;
495stop)
496 stop
497 ;;
498restart)
499 restart
500 ;;
501setup)
502 setup && start
503 ;;
504quicksetup)
505 QUICKSETUP=yes
506 setup
507 ;;
508cleanup)
509 cleanup
510 ;;
511status)
512 dmnstatus
513 ;;
514*)
515 echo "Usage: $0 {start|stop|restart|status|setup|quicksetup|cleanup} [quiet]"
516 exit 1
517esac
518
519exit
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