VirtualBox

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

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

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