VirtualBox

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

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

Additions/Linux: If /etc/depmod.d does not exist (e.g. on Debian 8), create it.

  • Property svn:eol-style set to LF
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 15.3 KB
Line 
1#! /bin/sh
2#
3# Linux Additions kernel module init script ($Revision: 65872 $)
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 if egrep -q 'vboxguest|vboxsf|vboxvideo' /proc/modules; then
274 info "You may need to restart your guest system to finish removing the guest drivers."
275 else
276 rm -f $userdev || fail "Cannot unlink $userdev"
277 rm -f $dev || fail "Cannot unlink $dev"
278 fi
279 return 0
280}
281
282restart()
283{
284 stop && start
285 return 0
286}
287
288# Remove any existing VirtualBox guest kernel modules from the disk, but not
289# from the kernel as they may still be in use
290cleanup_modules()
291{
292 log "Removing existing VirtualBox kernel modules."
293 for i in ${OLDMODULES}; do
294 # We no longer support DKMS, remove any leftovers.
295 rm -rf "/var/lib/dkms/${i}"*
296 # And remove old modules.
297 rm -f /lib/modules/*/misc/"${i}"*
298 done
299 # Remove leftover module folders.
300 for i in /lib/modules/*/misc; do
301 test -d "${i}" && rmdir -p "${i}" 2>/dev/null
302 done
303 rm -f /etc/depmod.d/vboxvideo-upstream.conf
304}
305
306# Build and install the VirtualBox guest kernel modules
307setup_modules()
308{
309 # don't stop the old modules here -- they might be in use
310 test -z "${QUICKSETUP}" && cleanup_modules
311 # This does not work for 2.4 series kernels. How sad.
312 test -n "${QUICKSETUP}" && test -f "${MODULE_DIR}/vboxguest.ko" && return 0
313 info "Building the VirtualBox Guest Additions kernel modules."
314
315 log "Building the main Guest Additions module."
316 if ! $BUILDINTMP \
317 --save-module-symvers /tmp/vboxguest-Module.symvers \
318 --module-source $MODULE_SRC/vboxguest \
319 --no-print-directory install >> $LOG 2>&1; then
320 # If check_module_dependencies.sh fails it prints a message itself.
321 "${INSTALL_DIR}"/other/check_module_dependencies.sh 2>&1 &&
322 info "Look at $LOG to find out what went wrong"
323 return 1
324 fi
325 log "Building the shared folder support module"
326 if ! $BUILDINTMP \
327 --use-module-symvers /tmp/vboxguest-Module.symvers \
328 --module-source $MODULE_SRC/vboxsf \
329 --no-print-directory install >> $LOG 2>&1; then
330 info "Look at $LOG to find out what went wrong"
331 return 1
332 fi
333 log "Building the graphics driver module"
334 if ! $BUILDINTMP \
335 --use-module-symvers /tmp/vboxguest-Module.symvers \
336 --module-source $MODULE_SRC/vboxvideo \
337 --no-print-directory install >> $LOG 2>&1; then
338 info "Look at $LOG to find out what went wrong"
339 fi
340 [ -d /etc/depmod.d ] || mkdir /etc/depmod.d
341 echo "override vboxguest * misc" > /etc/depmod.d/vboxvideo-upstream.conf
342 echo "override vboxsf * misc" >> /etc/depmod.d/vboxvideo-upstream.conf
343 echo "override vboxvideo * misc" >> /etc/depmod.d/vboxvideo-upstream.conf
344 depmod
345 return 0
346}
347
348# Do non-kernel bits needed for the kernel modules to work properly (user
349# creation, udev, mount helper...)
350extra_setup()
351{
352 log "Creating user for the Guest Additions."
353 # This is the LSB version of useradd and should work on recent
354 # distributions
355 useradd -d /var/run/vboxadd -g 1 -r -s /bin/false vboxadd >/dev/null 2>&1
356 # And for the others, we choose a UID ourselves
357 useradd -d /var/run/vboxadd -g 1 -u 501 -o -s /bin/false vboxadd >/dev/null 2>&1
358
359 # Add a group "vboxsf" for Shared Folders access
360 # All users which want to access the auto-mounted Shared Folders have to
361 # be added to this group.
362 groupadd -r -f vboxsf >/dev/null 2>&1
363
364 # Create udev description file
365 if [ -d /etc/udev/rules.d ]; then
366 log "Creating udev rule for the Guest Additions kernel module."
367 udev_call=""
368 udev_app=`which udevadm 2> /dev/null`
369 if [ $? -eq 0 ]; then
370 udev_call="${udev_app} version 2> /dev/null"
371 else
372 udev_app=`which udevinfo 2> /dev/null`
373 if [ $? -eq 0 ]; then
374 udev_call="${udev_app} -V 2> /dev/null"
375 fi
376 fi
377 udev_fix="="
378 if [ "${udev_call}" != "" ]; then
379 udev_out=`${udev_call}`
380 udev_ver=`expr "$udev_out" : '[^0-9]*\([0-9]*\)'`
381 if [ "$udev_ver" = "" -o "$udev_ver" -lt 55 ]; then
382 udev_fix=""
383 fi
384 fi
385 ## @todo 60-vboxadd.rules -> 60-vboxguest.rules ?
386 echo "KERNEL=${udev_fix}\"vboxguest\", NAME=\"vboxguest\", OWNER=\"vboxadd\", MODE=\"0660\"" > /etc/udev/rules.d/60-vboxadd.rules
387 echo "KERNEL=${udev_fix}\"vboxuser\", NAME=\"vboxuser\", OWNER=\"vboxadd\", MODE=\"0666\"" >> /etc/udev/rules.d/60-vboxadd.rules
388 fi
389
390 # Put mount.vboxsf in the right place
391 ln -sf "${INSTALL_DIR}/other/mount.vboxsf" /sbin
392 # And a post-installation script for rebuilding modules when a new kernel
393 # is installed.
394 mkdir -p /etc/kernel/postinst.d /etc/kernel/prerm.d
395 cat << EOF > /etc/kernel/postinst.d/vboxadd
396#!/bin/sh
397test -d "/lib/modules/\${1}/build" || exit 0
398KERN_DIR="/lib/modules/\${1}/build" MODULE_DIR="/lib/modules/\${1}/misc" \
399/sbin/rcvboxadd quicksetup
400exit 0
401EOF
402 cat << EOF > /etc/kernel/prerm.d/vboxadd
403#!/bin/sh
404for i in ${OLDMODULES}; do rm -f /lib/modules/"\${1}"/misc/"\${i}".ko; done
405rmdir -p /lib/modules/"\$1"/misc 2>/dev/null
406exit 0
407EOF
408 chmod 0755 /etc/kernel/postinst.d/vboxadd /etc/kernel/prerm.d/vboxadd
409 # SELinux security context for the mount helper.
410 if test -e /etc/selinux/config; then
411 # This is correct. semanage maps this to the real path, and it aborts
412 # with an error, telling you what you should have typed, if you specify
413 # the real path. The "chcon" is there as a back-up for old guests.
414 command -v semanage > /dev/null &&
415 semanage fcontext -a -t mount_exec_t "${INSTALL_DIR}/other/mount.vboxsf"
416 chcon -t mount_exec_t "${INSTALL_DIR}/other/mount.vboxsf"
417 fi
418}
419
420# setup_script
421setup()
422{
423 if test -r $config; then
424 . $config
425 else
426 fail "Configuration file $config not found"
427 fi
428 test -n "$INSTALL_DIR" -a -n "$INSTALL_VER" ||
429 fail "Configuration file $config not complete"
430 export BUILD_TYPE
431 export USERNAME
432
433 MODULE_SRC="$INSTALL_DIR/src/vboxguest-$INSTALL_VER"
434 BUILDINTMP="$MODULE_SRC/build_in_tmp"
435 chcon -t bin_t "$BUILDINTMP" > /dev/null 2>&1
436
437 if setup_modules; then
438 mod_succ=0
439 else
440 mod_succ=1
441 fi
442 test -n "${QUICKSETUP}" && return "${mod_succ}"
443 extra_setup
444 if [ "$mod_succ" -eq "0" ]; then
445 if running_vboxguest || running_vboxadd; then
446 info "You should restart your guest to make sure the new modules are actually used"
447 fi
448 fi
449 return "${mod_succ}"
450}
451
452# cleanup_script
453cleanup()
454{
455 if test -r $config; then
456 . $config
457 test -n "$INSTALL_DIR" -a -n "$INSTALL_VER" ||
458 fail "Configuration file $config not complete"
459 else
460 fail "Configuration file $config not found"
461 fi
462
463 # Delete old versions of VBox modules.
464 cleanup_modules
465 depmod
466
467 # Remove old module sources
468 for i in $OLDMODULES; do
469 rm -rf /usr/src/$i-*
470 done
471
472 # Clean-up X11-related bits
473 "${INSTALL_DIR}/init/vboxadd-x11" cleanup 2>> "${LOG}"
474
475 # Remove other files
476 rm /sbin/mount.vboxsf 2>/dev/null
477 rm -f /etc/kernel/postinst.d/vboxadd /etc/kernel/prerm.d/vboxadd
478 rmdir -p /etc/kernel/postinst.d /etc/kernel/prerm.d 2>/dev/null
479 rm /etc/udev/rules.d/60-vboxadd.rules 2>/dev/null
480}
481
482dmnstatus()
483{
484 if running_vboxguest; then
485 echo "The VirtualBox Additions are currently running."
486 else
487 echo "The VirtualBox Additions are not currently running."
488 fi
489}
490
491case "$2" in quiet)
492 QUIET=yes;;
493esac
494case "$1" in
495start)
496 start
497 ;;
498stop)
499 stop
500 ;;
501restart)
502 restart
503 ;;
504setup)
505 setup && start
506 ;;
507quicksetup)
508 QUICKSETUP=yes
509 setup
510 ;;
511cleanup)
512 cleanup
513 ;;
514status)
515 dmnstatus
516 ;;
517*)
518 echo "Usage: $0 {start|stop|restart|status|setup|quicksetup|cleanup} [quiet]"
519 exit 1
520esac
521
522exit
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