VirtualBox

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

最後變更 在這個檔案從15585是 15585,由 vboxsync 提交於 16 年 前

Linux additions: merged vboxvfs with vboxadd since vboxvfs has module dependencies to vboxadd

  • 屬性 svn:eol-style 設為 LF
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 6.4 KB
 
1#! /bin/sh
2# Sun xVM VirtualBox
3# Linux Additions kernel module init script
4#
5# Copyright (C) 2006-2007 Sun Microsystems, Inc.
6#
7# This file is part of VirtualBox Open Source Edition (OSE), as
8# available from http://www.alldomusa.eu.org. This file is free software;
9# you can redistribute it and/or modify it under the terms of the GNU
10# General Public License (GPL) as published by the Free Software
11# Foundation, in version 2 as it comes in the "COPYING" file of the
12# VirtualBox OSE distribution. VirtualBox OSE is distributed in the
13# hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
14#
15# Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
16# Clara, CA 95054 USA or visit http://www.sun.com if you need
17# additional information or have any questions.
18#
19
20
21# chkconfig: 35 30 60
22# description: VirtualBox Linux Additions kernel modules
23#
24### BEGIN INIT INFO
25# Provides: vboxadd
26# Required-Start:
27# Required-Stop:
28# Default-Start: 2 3 4 5
29# Default-Stop: 0 1 6
30# Description: VirtualBox Linux Additions kernel modules
31### END INIT INFO
32
33PATH=$PATH:/bin:/sbin:/usr/sbin
34BUILDVBOXADD=`/bin/ls /usr/src/vboxadd*/build_in_tmp 2>/dev/null|cut -d' ' -f1`
35BUILDVBOXVFS=`/bin/ls /usr/src/vboxvfs*/build_in_tmp 2>/dev/null|cut -d' ' -f1`
36LOG="/var/log/vboxadd-install.log"
37
38if [ -f /etc/redhat-release ]; then
39 system=redhat
40elif [ -f /etc/SuSE-release ]; then
41 system=suse
42elif [ -f /etc/gentoo-release ]; then
43 system=gentoo
44else
45 system=other
46fi
47
48if [ "$system" = "redhat" ]; then
49 . /etc/init.d/functions
50 fail_msg() {
51 echo_failure
52 echo
53 }
54
55 succ_msg() {
56 echo_success
57 echo
58 }
59
60 begin() {
61 echo -n "$1"
62 }
63fi
64
65if [ "$system" = "suse" ]; then
66 . /etc/rc.status
67 fail_msg() {
68 rc_failed 1
69 rc_status -v
70 }
71
72 succ_msg() {
73 rc_reset
74 rc_status -v
75 }
76
77 begin() {
78 echo -n "$1"
79 }
80fi
81
82if [ "$system" = "gentoo" ]; then
83 . /sbin/functions.sh
84 fail_msg() {
85 eend 1
86 }
87
88 succ_msg() {
89 eend $?
90 }
91
92 begin() {
93 ebegin $1
94 }
95
96 if [ "`which $0`" = "/sbin/rc" ]; then
97 shift
98 fi
99fi
100
101if [ "$system" = "other" ]; then
102 fail_msg() {
103 echo " ...fail!"
104 }
105
106 succ_msg() {
107 echo " ...done."
108 }
109
110 begin() {
111 echo -n $1
112 }
113fi
114
115dev=/dev/vboxadd
116owner=vboxadd
117group=1
118
119fail()
120{
121 if [ "$system" = "gentoo" ]; then
122 eerror $1
123 exit 1
124 fi
125 fail_msg
126 echo "($1)"
127 exit 1
128}
129
130running_vboxadd()
131{
132 lsmod | grep -q "vboxadd[^_-]"
133}
134
135running_vboxvfs()
136{
137 lsmod | grep -q "vboxvfs[^_-]"
138}
139
140start()
141{
142 begin "Starting VirtualBox Additions ";
143 running_vboxadd || {
144 rm -f $dev || {
145 fail "Cannot remove $dev"
146 }
147
148 modprobe vboxadd >/dev/null 2>&1 || {
149 fail "modprobe vboxadd failed"
150 }
151 sleep .5
152 }
153 if [ ! -c $dev ]; then
154 maj=`sed -n 's;\([0-9]\+\) vboxadd;\1;p' /proc/devices`
155 if [ ! -z "$maj" ]; then
156 min=0
157 else
158 min=`sed -n 's;\([0-9]\+\) vboxadd;\1;p' /proc/misc`
159 if [ ! -z "$min" ]; then
160 maj=10
161 fi
162 fi
163 test -z "$maj" && {
164 rmmod vboxadd 2>/dev/null
165 fail "Cannot locate the VirtualBox device"
166 }
167
168 mknod -m 0664 $dev c $maj $min || {
169 rmmod vboxadd 2>/dev/null
170 fail "Cannot create device $dev with major $maj and minor $min"
171 }
172 fi
173 chown $owner:$group $dev 2>/dev/null || {
174 rmmod vboxadd 2>/dev/null
175 fail "Cannot change owner $owner:$group for device $dev"
176 }
177
178 if [ -n "$BUILDVBOXVFS" ]; then
179 running_vboxvfs || {
180 modprobe vboxvfs > /dev/null 2>&1 || {
181 if dmesg | grep "vboxConnect failed" > /dev/null 2>&1; then
182 fail_msg
183 echo "You may be trying to run Guest Additions from binary release of VirtualBox"
184 echo "in the Open Source Edition."
185 exit 1
186 fi
187 fail "modprobe vboxvfs failed"
188 }
189 }
190 fi
191
192 # Mount all shared folders from /etc/fstab. Normally this is done by some
193 # other startup script but this requires the vboxdrv kernel module loaded.
194 mount -a -t vboxsf
195
196 succ_msg
197 return 0
198}
199
200stop()
201{
202 begin "Stopping VirtualBox Additions ";
203 if !umount -a -t vboxsf 2>/dev/null; then
204 fail "Cannot unmount vboxsf folders"
205 fi
206 if [ -n "$BUILDVBOXVFS" ]; then
207 if running_vboxvfs; then
208 rmmod vboxvfs 2>/dev/null || fail "Cannot unload module vboxvfs"
209 fi
210 fi
211 if running_vboxadd; then
212 rmmod vboxadd 2>/dev/null || fail "Cannot unload module vboxadd"
213 rm -f $dev || fail "Cannot unlink $dev"
214 fi
215 succ_msg
216 return 0
217}
218
219restart()
220{
221 stop && start
222 return 0
223}
224
225setup()
226{
227 # don't stop the old modules here -- they might be in use
228 if find /lib/modules/`uname -r` -name "vboxvfs\.*" 2>/dev/null|grep -q vboxvfs; then
229 begin "Removing old VirtualBox vboxvfs kernel module"
230 find /lib/modules/`uname -r` -name "vboxvfs\.*" 2>/dev/null|xargs rm -f 2>/dev/null
231 succ_msg
232 fi
233 if find /lib/modules/`uname -r` -name "vboxadd\.*" 2>/dev/null|grep -q vboxadd; then
234 begin "Removing old VirtualBox vboxadd kernel module"
235 find /lib/modules/`uname -r` -name "vboxadd\.*" 2>/dev/null|xargs rm -f 2>/dev/null
236 succ_msg
237 fi
238 begin "Recompiling VirtualBox kernel modules"
239 if ! $BUILDVBOXADD \
240 --save-module-symvers /tmp/vboxadd-Module.symvers \
241 --no-print-directory install > $LOG 2>&1; then
242 fail "Look at $LOG to find out what went wrong"
243 fi
244 if [ -n "$BUILDVBOXVFS" ]; then
245 if ! $BUILDVBOXVFS \
246 --use-module-symvers /tmp/vboxadd-Module.symvers \
247 --no-print-directory install >> $LOG 2>&1; then
248 fail "Look at $LOG to find out what went wrong"
249 fi
250 fi
251 start
252 succ_msg
253 echo
254 echo "You should reboot your guest to make sure the new modules are actually used"
255}
256
257dmnstatus()
258{
259 if running_vboxadd; then
260 echo "The VirtualBox Additions are currently running."
261 else
262 echo "The VirtualBox Additions are not currently running."
263 fi
264}
265
266case "$1" in
267start)
268 start
269 ;;
270stop)
271 stop
272 ;;
273restart)
274 restart
275 ;;
276setup)
277 setup
278 ;;
279status)
280 dmnstatus
281 ;;
282*)
283 echo "Usage: $0 {start|stop|restart|status}"
284 exit 1
285esac
286
287exit
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette