VirtualBox

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

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

bugref:3809: Linux installer maintenance: do not manually delete device nodes in vboxadd.sh on stop unless the kernel modules were actually removed. If the nodes are created by udev then they will not be recreated on next start, as the module will not be reloaded.

  • 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: 65534 $)
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 echo "override vboxguest * misc" > /etc/depmod.d/vboxvideo-upstream.conf
341 echo "override vboxsf * misc" >> /etc/depmod.d/vboxvideo-upstream.conf
342 echo "override vboxvideo * misc" >> /etc/depmod.d/vboxvideo-upstream.conf
343 depmod
344 return 0
345}
346
347# Do non-kernel bits needed for the kernel modules to work properly (user
348# creation, udev, mount helper...)
349extra_setup()
350{
351 log "Creating user for the Guest Additions."
352 # This is the LSB version of useradd and should work on recent
353 # distributions
354 useradd -d /var/run/vboxadd -g 1 -r -s /bin/false vboxadd >/dev/null 2>&1
355 # And for the others, we choose a UID ourselves
356 useradd -d /var/run/vboxadd -g 1 -u 501 -o -s /bin/false vboxadd >/dev/null 2>&1
357
358 # Add a group "vboxsf" for Shared Folders access
359 # All users which want to access the auto-mounted Shared Folders have to
360 # be added to this group.
361 groupadd -r -f vboxsf >/dev/null 2>&1
362
363 # Create udev description file
364 if [ -d /etc/udev/rules.d ]; then
365 log "Creating udev rule for the Guest Additions kernel module."
366 udev_call=""
367 udev_app=`which udevadm 2> /dev/null`
368 if [ $? -eq 0 ]; then
369 udev_call="${udev_app} version 2> /dev/null"
370 else
371 udev_app=`which udevinfo 2> /dev/null`
372 if [ $? -eq 0 ]; then
373 udev_call="${udev_app} -V 2> /dev/null"
374 fi
375 fi
376 udev_fix="="
377 if [ "${udev_call}" != "" ]; then
378 udev_out=`${udev_call}`
379 udev_ver=`expr "$udev_out" : '[^0-9]*\([0-9]*\)'`
380 if [ "$udev_ver" = "" -o "$udev_ver" -lt 55 ]; then
381 udev_fix=""
382 fi
383 fi
384 ## @todo 60-vboxadd.rules -> 60-vboxguest.rules ?
385 echo "KERNEL=${udev_fix}\"vboxguest\", NAME=\"vboxguest\", OWNER=\"vboxadd\", MODE=\"0660\"" > /etc/udev/rules.d/60-vboxadd.rules
386 echo "KERNEL=${udev_fix}\"vboxuser\", NAME=\"vboxuser\", OWNER=\"vboxadd\", MODE=\"0666\"" >> /etc/udev/rules.d/60-vboxadd.rules
387 fi
388
389 # Put mount.vboxsf in the right place
390 ln -sf "${INSTALL_DIR}/other/mount.vboxsf" /sbin
391 # And a post-installation script for rebuilding modules when a new kernel
392 # is installed.
393 mkdir -p /etc/kernel/postinst.d /etc/kernel/prerm.d
394 cat << EOF > /etc/kernel/postinst.d/vboxadd
395#!/bin/sh
396test -d "/lib/modules/\${1}/build" || exit 0
397KERN_DIR="/lib/modules/\${1}/build" MODULE_DIR="/lib/modules/\${1}/misc" \
398/sbin/rcvboxadd quicksetup
399exit 0
400EOF
401 cat << EOF > /etc/kernel/prerm.d/vboxadd
402#!/bin/sh
403for i in ${OLDMODULES}; do rm -f /lib/modules/"\${1}"/misc/"\${i}".ko; done
404rmdir -p /lib/modules/"\$1"/misc 2>/dev/null
405exit 0
406EOF
407 chmod 0755 /etc/kernel/postinst.d/vboxadd /etc/kernel/prerm.d/vboxadd
408 # SELinux security context for the mount helper.
409 if test -e /etc/selinux/config; then
410 # This is correct. semanage maps this to the real path, and it aborts
411 # with an error, telling you what you should have typed, if you specify
412 # the real path. The "chcon" is there as a back-up for old guests.
413 command -v semanage > /dev/null &&
414 semanage fcontext -a -t mount_exec_t "${INSTALL_DIR}/other/mount.vboxsf"
415 chcon -t mount_exec_t "${INSTALL_DIR}/other/mount.vboxsf"
416 fi
417}
418
419# setup_script
420setup()
421{
422 if test -r $config; then
423 . $config
424 else
425 fail "Configuration file $config not found"
426 fi
427 test -n "$INSTALL_DIR" -a -n "$INSTALL_VER" ||
428 fail "Configuration file $config not complete"
429 export BUILD_TYPE
430 export USERNAME
431
432 MODULE_SRC="$INSTALL_DIR/src/vboxguest-$INSTALL_VER"
433 BUILDINTMP="$MODULE_SRC/build_in_tmp"
434 chcon -t bin_t "$BUILDINTMP" > /dev/null 2>&1
435
436 if setup_modules; then
437 mod_succ=0
438 else
439 mod_succ=1
440 fi
441 test -n "${QUICKSETUP}" && return "${mod_succ}"
442 extra_setup
443 if [ "$mod_succ" -eq "0" ]; then
444 if running_vboxguest || running_vboxadd; then
445 info "You should restart your guest to make sure the new modules are actually used"
446 fi
447 fi
448 return "${mod_succ}"
449}
450
451# cleanup_script
452cleanup()
453{
454 if test -r $config; then
455 . $config
456 test -n "$INSTALL_DIR" -a -n "$INSTALL_VER" ||
457 fail "Configuration file $config not complete"
458 else
459 fail "Configuration file $config not found"
460 fi
461
462 # Delete old versions of VBox modules.
463 cleanup_modules
464 depmod
465
466 # Remove old module sources
467 for i in $OLDMODULES; do
468 rm -rf /usr/src/$i-*
469 done
470
471 # Clean-up X11-related bits
472 "${INSTALL_DIR}/init/vboxadd-x11" cleanup 2>> "${LOG}"
473
474 # Remove other files
475 rm /sbin/mount.vboxsf 2>/dev/null
476 rm -f /etc/kernel/postinst.d/vboxadd /etc/kernel/prerm.d/vboxadd
477 rmdir -p /etc/kernel/postinst.d /etc/kernel/prerm.d 2>/dev/null
478 rm /etc/udev/rules.d/60-vboxadd.rules 2>/dev/null
479}
480
481dmnstatus()
482{
483 if running_vboxguest; then
484 echo "The VirtualBox Additions are currently running."
485 else
486 echo "The VirtualBox Additions are not currently running."
487 fi
488}
489
490case "$2" in quiet)
491 QUIET=yes;;
492esac
493case "$1" in
494start)
495 start
496 ;;
497stop)
498 stop
499 ;;
500restart)
501 restart
502 ;;
503setup)
504 setup && start
505 ;;
506quicksetup)
507 QUICKSETUP=yes
508 setup
509 ;;
510cleanup)
511 cleanup
512 ;;
513status)
514 dmnstatus
515 ;;
516*)
517 echo "Usage: $0 {start|stop|restart|status|setup|quicksetup|cleanup} [quiet]"
518 exit 1
519esac
520
521exit
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