VirtualBox

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

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

bugref:8511: RHEL7 -- Oh no! Something has gone wrong -- GA problem: only call semange if it is actually found on the system.

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