VirtualBox

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

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

bugref:8087: Additions/x11: support non-root X server: fix creating initrd files on CentOS 7 guests. Missing path separator in a wildcard.

  • Property svn:eol-style set to LF
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 16.7 KB
Line 
1#! /bin/sh
2#
3# Linux Additions kernel module init script ($Revision: 62195 $)
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 if /usr/bin/VBoxClient --check3d 2>/dev/null; then
230 rm -f /var/lib/VBoxGuestAdditions/lib/system/tmp.so
231 mkdir -m 0755 -p /var/lib/VBoxGuestAdditions/lib/system
232 ldconfig -p | while read -r line; do
233 case "${line}" in "libGL.so.1 ${ldconfig_arch} => "*)
234 ln -s "${line#libGL.so.1 ${ldconfig_arch} => }" /var/lib/VBoxGuestAdditions/lib/system/tmp.so
235 mv /var/lib/VBoxGuestAdditions/lib/system/tmp.so /var/lib/VBoxGuestAdditions/lib/system/libGL.so.1
236 break
237 esac
238 done
239 ldconfig -p | while read -r line; do
240 case "${line}" in "libEGL.so.1 ${ldconfig_arch} => "*)
241 ln -s "${line#libEGL.so.1 ${ldconfig_arch} => }" /var/lib/VBoxGuestAdditions/lib/system/tmp.so
242 mv /var/lib/VBoxGuestAdditions/lib/system/tmp.so /var/lib/VBoxGuestAdditions/lib/system/libEGL.so.1
243 break
244 esac
245 done
246 ln -sf "${INSTALL_DIR}/lib/VBoxOGL.so" /var/lib/VBoxGuestAdditions/lib/libGL.so.1
247 ln -sf "${INSTALL_DIR}/lib/VBoxEGL.so" /var/lib/VBoxGuestAdditions/lib/libEGL.so.1
248 echo "/var/lib/VBoxGuestAdditions/lib" > /etc/ld.so.conf.d/00vboxvideo.conf
249 else
250 rm -f /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 succ_msg
260 return 0
261}
262
263stop()
264{
265 begin "Stopping VirtualBox Additions" console;
266 if test -r /etc/ld.so.conf.d/00vboxvideo.conf; then
267 rm /etc/ld.so.conf.d/00vboxvideo.conf
268 ldconfig
269 fi
270 if ! umount -a -t vboxsf 2>/dev/null; then
271 fail "Cannot unmount vboxsf folders"
272 fi
273 if running_vboxsf; then
274 rmmod vboxsf 2>/dev/null || fail "Cannot unload module vboxsf"
275 fi
276 if running_vboxguest; then
277 rmmod vboxguest 2>/dev/null || fail "Cannot unload module vboxguest"
278 rm -f $userdev || fail "Cannot unlink $userdev"
279 rm -f $dev || fail "Cannot unlink $dev"
280 fi
281 succ_msg
282 return 0
283}
284
285restart()
286{
287 stop && start
288 return 0
289}
290
291## Update the initramfs. Debian and Ubuntu put the graphics driver in, and
292# need the touch(1) command below. Everyone else that I checked just need
293# the right module alias file from depmod(1) and only use the initramfs to
294# load the root filesystem, not the boot splash. update-initramfs works
295# for the first two and dracut for every one else I checked. We are only
296# interested in distributions recent enough to use the KMS vboxvideo driver.
297## @param $1 kernel version to update for.
298update_module_dependencies()
299{
300 depmod "${1}"
301 test -d "/lib/modules/${1}/initrd" &&
302 touch "/lib/modules/${1}/initrd/vboxvideo"
303 test -n "${QUICKSETUP}" && return
304 if type dracut >/dev/null 2>&1; then
305 dracut -f "/boot/initramfs-${1}.img"
306 elif type update-initramfs >/dev/null 2>&1; then
307 update-initramfs -u -k "${1}"
308 fi
309}
310
311# Remove any existing VirtualBox guest kernel modules from the disk, but not
312# from the kernel as they may still be in use
313cleanup_modules()
314{
315 begin "Removing existing VirtualBox kernel modules"
316 # We no longer support DKMS, remove any leftovers.
317 for i in vboxguest vboxadd vboxsf vboxvfs vboxvideo; do
318 rm -rf "/var/lib/dkms/${i}"*
319 done
320 for i in $OLDMODULES; do
321 find /lib/modules -name $i\* | xargs rm 2>/dev/null
322 done
323 # Remove leftover module folders.
324 for i in /lib/modules/*/misc; do
325 test -d "${i}" && rmdir -p "${i}" 2>/dev/null
326 done
327 succ_msg
328}
329
330# Build and install the VirtualBox guest kernel modules
331setup_modules()
332{
333 # don't stop the old modules here -- they might be in use
334 test -z "${QUICKSETUP}" && cleanup_modules
335 # This does not work for 2.4 series kernels. How sad.
336 test -n "${QUICKSETUP}" && test -f "${MODULE_DIR}/vboxguest.ko" && return 0
337 begin "Building the VirtualBox Guest Additions kernel modules"
338
339 begin "Building the main Guest Additions module"
340 if ! $BUILDINTMP \
341 --save-module-symvers /tmp/vboxguest-Module.symvers \
342 --module-source $MODULE_SRC/vboxguest \
343 --no-print-directory install >> $LOG 2>&1; then
344 show_error "Look at $LOG to find out what went wrong"
345 return 1
346 fi
347 succ_msg
348 begin "Building the shared folder support module"
349 if ! $BUILDINTMP \
350 --use-module-symvers /tmp/vboxguest-Module.symvers \
351 --module-source $MODULE_SRC/vboxsf \
352 --no-print-directory install >> $LOG 2>&1; then
353 show_error "Look at $LOG to find out what went wrong"
354 return 1
355 fi
356 succ_msg
357 begin "Building the graphics driver module"
358 if ! $BUILDINTMP \
359 --use-module-symvers /tmp/vboxguest-Module.symvers \
360 --module-source $MODULE_SRC/vboxvideo \
361 --no-print-directory install >> $LOG 2>&1; then
362 show_error "Look at $LOG to find out what went wrong"
363 fi
364 succ_msg
365 update_module_dependencies "${KERN_VER}"
366 return 0
367}
368
369# Do non-kernel bits needed for the kernel modules to work properly (user
370# creation, udev, mount helper...)
371extra_setup()
372{
373 begin "Doing non-kernel setup of the Guest Additions"
374 echo "Creating user for the Guest Additions." >> $LOG
375 # This is the LSB version of useradd and should work on recent
376 # distributions
377 useradd -d /var/run/vboxadd -g 1 -r -s /bin/false vboxadd >/dev/null 2>&1
378 # And for the others, we choose a UID ourselves
379 useradd -d /var/run/vboxadd -g 1 -u 501 -o -s /bin/false vboxadd >/dev/null 2>&1
380
381 # Add a group "vboxsf" for Shared Folders access
382 # All users which want to access the auto-mounted Shared Folders have to
383 # be added to this group.
384 groupadd -r -f vboxsf >/dev/null 2>&1
385
386 # Create udev description file
387 if [ -d /etc/udev/rules.d ]; then
388 echo "Creating udev rule for the Guest Additions kernel module." >> $LOG
389 udev_call=""
390 udev_app=`which udevadm 2> /dev/null`
391 if [ $? -eq 0 ]; then
392 udev_call="${udev_app} version 2> /dev/null"
393 else
394 udev_app=`which udevinfo 2> /dev/null`
395 if [ $? -eq 0 ]; then
396 udev_call="${udev_app} -V 2> /dev/null"
397 fi
398 fi
399 udev_fix="="
400 if [ "${udev_call}" != "" ]; then
401 udev_out=`${udev_call}`
402 udev_ver=`expr "$udev_out" : '[^0-9]*\([0-9]*\)'`
403 if [ "$udev_ver" = "" -o "$udev_ver" -lt 55 ]; then
404 udev_fix=""
405 fi
406 fi
407 ## @todo 60-vboxadd.rules -> 60-vboxguest.rules ?
408 echo "KERNEL=${udev_fix}\"vboxguest\", NAME=\"vboxguest\", OWNER=\"vboxadd\", MODE=\"0660\"" > /etc/udev/rules.d/60-vboxadd.rules
409 echo "KERNEL=${udev_fix}\"vboxuser\", NAME=\"vboxuser\", OWNER=\"vboxadd\", MODE=\"0666\"" >> /etc/udev/rules.d/60-vboxadd.rules
410 fi
411
412 # Put mount.vboxsf in the right place
413 ln -sf "$lib_path/$PACKAGE/mount.vboxsf" /sbin
414 # And an rc file to re-build the kernel modules and re-set-up the X server.
415 ln -sf "$lib_path/$PACKAGE/vboxadd" /sbin/rcvboxadd
416 ln -sf "$lib_path/$PACKAGE/vboxadd-x11" /sbin/rcvboxadd-x11
417 # And a post-installation script for rebuilding modules when a new kernel
418 # is installed.
419 mkdir -p /etc/kernel/postinst.d /etc/kernel/prerm.d
420 cat << EOF > /etc/kernel/postinst.d/vboxadd
421#!/bin/sh
422test -d "/lib/modules/\${1}/build" || exit 0
423KERN_DIR="/lib/modules/\${1}/build" MODULE_DIR="/lib/modules/\${1}/misc" \
424/sbin/rcvboxadd quicksetup
425exit 0
426EOF
427 cat << EOF > /etc/kernel/prerm.d/vboxadd
428#!/bin/sh
429for i in ${OLDMODULES}; do rm -f /lib/modules/"\${1}"/misc/"\${i}".ko; done
430rmdir -p /lib/modules/"\$1"/misc 2>/dev/null
431exit 0
432EOF
433 chmod 0755 /etc/kernel/postinst.d/vboxadd /etc/kernel/prerm.d/vboxadd
434 # At least Fedora 11 and Fedora 12 require the correct security context when
435 # executing this command from service scripts. Shouldn't hurt for other
436 # distributions.
437 chcon -u system_u -t mount_exec_t "$lib_path/$PACKAGE/mount.vboxsf" > /dev/null 2>&1
438 # And at least Fedora 15 needs this for the acceleration support check to
439 # work
440 redhat_release=`cat /etc/redhat-release 2> /dev/null`
441 case "$redhat_release" in Fedora\ release\ 15* )
442 for i in "$lib_path"/*.so
443 do
444 restorecon "$i" >/dev/null
445 done
446 ;;
447 esac
448
449 succ_msg
450}
451
452# setup_script
453setup()
454{
455 begin "Building Guest Additions kernel modules" console
456 if test -r $config; then
457 . $config
458 else
459 fail "Configuration file $config not found"
460 fi
461 test -n "$INSTALL_DIR" -a -n "$INSTALL_VER" ||
462 fail "Configuration file $config not complete"
463 export BUILD_TYPE
464 export USERNAME
465
466 rm -f $LOG
467 MODULE_SRC="$INSTALL_DIR/src/vboxguest-$INSTALL_VER"
468 BUILDINTMP="$MODULE_SRC/build_in_tmp"
469 chcon -t bin_t "$BUILDINTMP" > /dev/null 2>&1
470
471 if setup_modules; then
472 mod_succ=0
473 else
474 mod_succ=1
475 show_error "Please check that you have gcc, make, the header files for your Linux kernel and possibly perl installed."
476 fi
477 test -n "${QUICKSETUP}" && return "${mod_succ}"
478 extra_setup
479 if [ "$mod_succ" -eq "0" ]; then
480 if running_vboxguest || running_vboxadd; then
481 begin "You should restart your guest to make sure the new modules are actually used" console
482 fi
483 fi
484 return "${mod_succ}"
485}
486
487# cleanup_script
488cleanup()
489{
490 if test -r $config; then
491 . $config
492 test -n "$INSTALL_DIR" -a -n "$INSTALL_VER" ||
493 fail "Configuration file $config not complete"
494 else
495 fail "Configuration file $config not found"
496 fi
497
498 # Delete old versions of VBox modules.
499 cleanup_modules
500 for i in /lib/modules/*; do
501 update_module_dependencies "${i#/lib/modules/}"
502 done
503
504 # Remove old module sources
505 for i in $OLDMODULES; do
506 rm -rf /usr/src/$i-*
507 done
508
509 # Clean-up X11-related bits
510 /sbin/rcvboxadd-x11 cleanup
511
512 # Remove other files
513 rm /sbin/mount.vboxsf 2>/dev/null
514 rm /sbin/rcvboxadd 2>/dev/null
515 rm /sbin/rcvboxadd-x11 2>/dev/null
516 rm -f /etc/kernel/postinst.d/vboxadd /etc/kernel/prerm.d/vboxadd
517 rmdir -p /etc/kernel/postinst.d /etc/kernel/prerm.d 2>/dev/null
518 rm /etc/udev/rules.d/60-vboxadd.rules 2>/dev/null
519 rm -f /lib/modules/*/initrd/vboxvideo
520}
521
522dmnstatus()
523{
524 if running_vboxguest; then
525 echo "The VirtualBox Additions are currently running."
526 else
527 echo "The VirtualBox Additions are not currently running."
528 fi
529}
530
531case "$1" in
532start)
533 start
534 ;;
535stop)
536 stop
537 ;;
538restart)
539 restart
540 ;;
541setup)
542 setup && start
543 ;;
544quicksetup)
545 QUICKSETUP=yes
546 setup
547 ;;
548cleanup)
549 cleanup
550 ;;
551status)
552 dmnstatus
553 ;;
554*)
555 echo "Usage: $0 {start|stop|restart|status|setup|quicksetup|cleanup}"
556 exit 1
557esac
558
559exit
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