1 | #!/bin/sh
|
---|
2 | # Sun VirtualBox
|
---|
3 | # VirtualBox kernel module control script, Solaris hosts.
|
---|
4 | #
|
---|
5 | # Copyright (C) 2007-2009 Sun Microsystems, Inc.
|
---|
6 | #
|
---|
7 | # This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
8 | # available from http://www.virtualbox.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 | CHECKARCH=""
|
---|
21 | SILENTUNLOAD=""
|
---|
22 | ALWAYSREMDRV=""
|
---|
23 |
|
---|
24 | MODNAME="vboxdrv"
|
---|
25 | VBIMODNAME="vbi"
|
---|
26 | FLTMODNAME="vboxflt"
|
---|
27 | NETMODNAME="vboxnet"
|
---|
28 | USBMODNAME="vboxusbmon"
|
---|
29 | MODDIR32="/platform/i86pc/kernel/drv"
|
---|
30 | MODDIR64=$MODDIR32/amd64
|
---|
31 |
|
---|
32 | abort()
|
---|
33 | {
|
---|
34 | echo 1>&2 "## $1"
|
---|
35 | exit 1
|
---|
36 | }
|
---|
37 |
|
---|
38 | info()
|
---|
39 | {
|
---|
40 | echo 1>&2 "$1"
|
---|
41 | }
|
---|
42 |
|
---|
43 | warn()
|
---|
44 | {
|
---|
45 | echo 1>&2 "WARNING!! $1"
|
---|
46 | }
|
---|
47 |
|
---|
48 | check_if_installed()
|
---|
49 | {
|
---|
50 | cputype=`isainfo -k`
|
---|
51 | modulepath="$MODDIR32/$MODNAME"
|
---|
52 | if test "$cputype" = "amd64"; then
|
---|
53 | modulepath="$MODDIR64/$MODNAME"
|
---|
54 | fi
|
---|
55 | if test -f "$modulepath"; then
|
---|
56 | return 0
|
---|
57 | fi
|
---|
58 |
|
---|
59 | # Check arch only while installing (because rem_drv works for both arch.)
|
---|
60 | if test ! -z "$CHECKARCH"; then
|
---|
61 | # Let us go a step further and check if user has mixed up x86/amd64
|
---|
62 | # amd64 ISA, x86 kernel module??
|
---|
63 | if test "$cputype" = "amd64"; then
|
---|
64 | modulepath="$MODDIR32/$MODNAME"
|
---|
65 | if test -f "$modulepath"; then
|
---|
66 | abort "Found 32-bit module instead of 64-bit. Please install the amd64 package!"
|
---|
67 | fi
|
---|
68 | else
|
---|
69 | # x86 ISA, amd64 kernel module??
|
---|
70 | modulepath="$MODDIR64/$MODNAME"
|
---|
71 | if test -f "$modulepath"; then
|
---|
72 | abort "Found 64-bit module instead of 32-bit. Please install the x86 package!"
|
---|
73 | fi
|
---|
74 | fi
|
---|
75 |
|
---|
76 | abort "VirtualBox Host kernel module NOT installed."
|
---|
77 | else
|
---|
78 | info "## VirtualBox Host kernel module NOT installed."
|
---|
79 | return 0
|
---|
80 | fi
|
---|
81 | }
|
---|
82 |
|
---|
83 | module_added()
|
---|
84 | {
|
---|
85 | loadentry=`cat /etc/name_to_major | grep $1`
|
---|
86 | if test -z "$loadentry"; then
|
---|
87 | return 1
|
---|
88 | fi
|
---|
89 | return 0
|
---|
90 | }
|
---|
91 |
|
---|
92 | module_loaded()
|
---|
93 | {
|
---|
94 | # modinfo should now work properly since we prevent module autounloading
|
---|
95 | loadentry=`/usr/sbin/modinfo | grep $1`
|
---|
96 | if test -z "$loadentry"; then
|
---|
97 | return 1
|
---|
98 | fi
|
---|
99 | return 0
|
---|
100 | }
|
---|
101 |
|
---|
102 | vboxdrv_loaded()
|
---|
103 | {
|
---|
104 | module_loaded $MODNAME
|
---|
105 | return $?
|
---|
106 | }
|
---|
107 |
|
---|
108 | vboxdrv_added()
|
---|
109 | {
|
---|
110 | module_added $MODNAME
|
---|
111 | return $?
|
---|
112 | }
|
---|
113 |
|
---|
114 | vboxflt_loaded()
|
---|
115 | {
|
---|
116 | module_loaded $FLTMODNAME
|
---|
117 | return $?
|
---|
118 | }
|
---|
119 |
|
---|
120 | vboxflt_added()
|
---|
121 | {
|
---|
122 | module_added $FLTMODNAME
|
---|
123 | return $?
|
---|
124 | }
|
---|
125 |
|
---|
126 | vboxnet_added()
|
---|
127 | {
|
---|
128 | module_added $NETMODNAME
|
---|
129 | return $?
|
---|
130 | }
|
---|
131 |
|
---|
132 | vboxnet_loaded()
|
---|
133 | {
|
---|
134 | module_loaded $NETMODNAME
|
---|
135 | return $?
|
---|
136 | }
|
---|
137 |
|
---|
138 | vboxusbmon_added()
|
---|
139 | {
|
---|
140 | module_added $USBMODNAME
|
---|
141 | return $?
|
---|
142 | }
|
---|
143 |
|
---|
144 | vboxusbmon_loaded()
|
---|
145 | {
|
---|
146 | module_loaded $USBMODNAME
|
---|
147 | return $?
|
---|
148 | }
|
---|
149 |
|
---|
150 | check_root()
|
---|
151 | {
|
---|
152 | idbin=/usr/xpg4/bin/id
|
---|
153 | if test ! -f "$idbin"; then
|
---|
154 | found=`which id | grep "no id"`
|
---|
155 | if test ! -z "$found"; then
|
---|
156 | abort "Failed to find a suitable user id binary! Aborting"
|
---|
157 | else
|
---|
158 | idbin=$found
|
---|
159 | fi
|
---|
160 | fi
|
---|
161 |
|
---|
162 | if test `$idbin -u` -ne 0; then
|
---|
163 | abort "This program must be run with administrator privileges. Aborting"
|
---|
164 | fi
|
---|
165 | }
|
---|
166 |
|
---|
167 | start_module()
|
---|
168 | {
|
---|
169 | if vboxdrv_loaded; then
|
---|
170 | info "VirtualBox Host kernel module already loaded."
|
---|
171 | else
|
---|
172 | if test -n "_HARDENED_"; then
|
---|
173 | /usr/sbin/add_drv -m'* 0600 root sys' $MODNAME || abort "Failed to add VirtualBox Host Kernel module."
|
---|
174 | else
|
---|
175 | /usr/sbin/add_drv -m'* 0666 root sys' $MODNAME || abort "Failed to add VirtualBox Host Kernel module."
|
---|
176 | fi
|
---|
177 | /usr/sbin/modload -p drv/$MODNAME
|
---|
178 | if test ! vboxdrv_loaded; then
|
---|
179 | abort "Failed to load VirtualBox Host kernel module."
|
---|
180 | elif test -c "/devices/pseudo/$MODNAME@0:$MODNAME"; then
|
---|
181 | info "VirtualBox Host kernel module loaded."
|
---|
182 | else
|
---|
183 | abort "Aborting due to attach failure."
|
---|
184 | fi
|
---|
185 | fi
|
---|
186 | }
|
---|
187 |
|
---|
188 | stop_module()
|
---|
189 | {
|
---|
190 | if vboxdrv_loaded; then
|
---|
191 | vboxdrv_mod_id=`/usr/sbin/modinfo | grep $MODNAME | cut -f 1 -d ' ' `
|
---|
192 | if test -n "$vboxdrv_mod_id"; then
|
---|
193 | /usr/sbin/modunload -i $vboxdrv_mod_id
|
---|
194 |
|
---|
195 | # While uninstalling we always remove the driver whether we unloaded successfully or not,
|
---|
196 | # while installing we make SURE if there is an existing driver about, it is cleanly unloaded
|
---|
197 | # and the new one is added hence the "alwaysremdrv" option.
|
---|
198 | if test -n "$ALWAYSREMDRV"; then
|
---|
199 | /usr/sbin/rem_drv $MODNAME
|
---|
200 | else
|
---|
201 | if test "$?" -eq 0; then
|
---|
202 | /usr/sbin/rem_drv $MODNAME || abort "Unloaded VirtualBox Host kernel module, but failed to remove it!"
|
---|
203 | else
|
---|
204 | abort "Failed to unload VirtualBox Host kernel module. Old one still active!!"
|
---|
205 | fi
|
---|
206 | fi
|
---|
207 |
|
---|
208 | info "VirtualBox Host kernel module unloaded."
|
---|
209 | fi
|
---|
210 | elif vboxdrv_added; then
|
---|
211 | /usr/sbin/rem_drv $MODNAME || abort "Unloaded VirtualBox Host kernel module, but failed to remove it!"
|
---|
212 | info "VirtualBox Host kernel module unloaded."
|
---|
213 | elif test -z "$SILENTUNLOAD"; then
|
---|
214 | info "VirtualBox Host kernel module not loaded."
|
---|
215 | fi
|
---|
216 |
|
---|
217 | # check for vbi and force unload it
|
---|
218 | vbi_mod_id=`/usr/sbin/modinfo | grep $VBIMODNAME | cut -f 1 -d ' ' `
|
---|
219 | if test -n "$vbi_mod_id"; then
|
---|
220 | /usr/sbin/modunload -i $vbi_mod_id
|
---|
221 | fi
|
---|
222 | }
|
---|
223 |
|
---|
224 | start_vboxflt()
|
---|
225 | {
|
---|
226 | if vboxflt_loaded; then
|
---|
227 | info "VirtualBox NetFilter kernel module already loaded."
|
---|
228 | else
|
---|
229 | /usr/sbin/add_drv -m'* 0600 root sys' $FLTMODNAME || abort "Failed to add VirtualBox NetFilter Kernel module."
|
---|
230 | /usr/sbin/modload -p drv/$FLTMODNAME
|
---|
231 | if test ! vboxflt_loaded; then
|
---|
232 | abort "Failed to load VirtualBox NetFilter kernel module."
|
---|
233 | else
|
---|
234 | info "VirtualBox NetFilter kernel module loaded."
|
---|
235 | fi
|
---|
236 | fi
|
---|
237 | }
|
---|
238 |
|
---|
239 | stop_vboxflt()
|
---|
240 | {
|
---|
241 | if vboxflt_loaded; then
|
---|
242 | vboxflt_mod_id=`/usr/sbin/modinfo | grep $FLTMODNAME | cut -f 1 -d ' '`
|
---|
243 | if test -n "$vboxflt_mod_id"; then
|
---|
244 | /usr/sbin/modunload -i $vboxflt_mod_id
|
---|
245 |
|
---|
246 | # see stop_vboxdrv() for why we have "alwaysremdrv".
|
---|
247 | if test -n "$ALWAYSREMDRV"; then
|
---|
248 | /usr/sbin/rem_drv $FLTMODNAME
|
---|
249 | else
|
---|
250 | if test "$?" -eq 0; then
|
---|
251 | /usr/sbin/rem_drv $FLTMODNAME || abort "Unloaded VirtualBox NetFilter kernel module, but failed to remove it!"
|
---|
252 | else
|
---|
253 | abort "Failed to unload VirtualBox NetFilter kernel module. Old one still active!!"
|
---|
254 | fi
|
---|
255 | fi
|
---|
256 |
|
---|
257 | info "VirtualBox NetFilter kernel module unloaded."
|
---|
258 | fi
|
---|
259 | elif vboxflt_added; then
|
---|
260 | /usr/sbin/rem_drv $FLTMODNAME || abort "Unloaded VirtualBox NetFilter kernel module, but failed to remove it!"
|
---|
261 | info "VirtualBox NetFilter kernel module unloaded."
|
---|
262 | elif test -z "$SILENTUNLOAD"; then
|
---|
263 | info "VirtualBox NetFilter kernel module not loaded."
|
---|
264 | fi
|
---|
265 | }
|
---|
266 |
|
---|
267 |
|
---|
268 | start_vboxnet()
|
---|
269 | {
|
---|
270 | if vboxnet_loaded; then
|
---|
271 | info "VirtualBox NetAdapter kernel module already loaded."
|
---|
272 | else
|
---|
273 | /usr/sbin/add_drv -m'* 0666 root sys' $NETMODNAME || abort "Failed to add VirtualBox NetAdapter Kernel module."
|
---|
274 | /usr/sbin/modload -p drv/$NETMODNAME
|
---|
275 | if test ! vboxnet_loaded; then
|
---|
276 | abort "Failed to load VirtualBox NetAdapter kernel module."
|
---|
277 | else
|
---|
278 | # Plumb the interface!
|
---|
279 | /sbin/ifconfig vboxnet0 plumb up
|
---|
280 | info "VirtualBox NetAdapter kernel module loaded."
|
---|
281 | fi
|
---|
282 | fi
|
---|
283 | }
|
---|
284 |
|
---|
285 | stop_vboxnet()
|
---|
286 | {
|
---|
287 | if vboxnet_loaded; then
|
---|
288 | vboxnet_mod_id=`/usr/sbin/modinfo | grep $NETMODNAME | cut -f 1 -d ' '`
|
---|
289 | if test -n "$vboxnet_mod_id"; then
|
---|
290 | /sbin/ifconfig vboxnet0 unplumb
|
---|
291 | /usr/sbin/modunload -i $vboxnet_mod_id
|
---|
292 |
|
---|
293 | # see stop_vboxdrv() for why we have "alwaysremdrv".
|
---|
294 | if test -n "$ALWAYSREMDRV"; then
|
---|
295 | /usr/sbin/rem_drv $NETMODNAME
|
---|
296 | else
|
---|
297 | if test "$?" -eq 0; then
|
---|
298 | /usr/sbin/rem_drv $NETMODNAME || abort "Unloaded VirtualBox NetAdapter kernel module, but failed to remove it!"
|
---|
299 | else
|
---|
300 | abort "Failed to unload VirtualBox NetAdapter kernel module. Old one still active!!"
|
---|
301 | fi
|
---|
302 | fi
|
---|
303 |
|
---|
304 | info "VirtualBox NetAdapter kernel module unloaded."
|
---|
305 | fi
|
---|
306 | elif vboxnet_added; then
|
---|
307 | /usr/sbin/rem_drv $NETMODNAME || abort "Unloaded VirtualBox NetAdapter kernel module, but failed to remove it!"
|
---|
308 | info "VirtualBox NetAdapter kernel module unloaded."
|
---|
309 | elif test -z "$SILENTUNLOAD"; then
|
---|
310 | info "VirtualBox NetAdapter kernel module not loaded."
|
---|
311 | fi
|
---|
312 | }
|
---|
313 |
|
---|
314 |
|
---|
315 | start_vboxusbmon()
|
---|
316 | {
|
---|
317 | if vboxusbmon_loaded; then
|
---|
318 | info "VirtualBox USB Monitor kernel module already loaded."
|
---|
319 | else
|
---|
320 | /usr/sbin/add_drv -m'* 0666 root sys' $USBMODNAME || abort "Failed to add VirtualBox USB Monitor Kernel module."
|
---|
321 | /usr/sbin/modload -p drv/$USBMODNAME
|
---|
322 | if test ! vboxusbmon_loaded; then
|
---|
323 | abort "Failed to load VirtualBox USB kernel module."
|
---|
324 | else
|
---|
325 | info "VirtualBox USB kernel module loaded."
|
---|
326 | fi
|
---|
327 | fi
|
---|
328 | }
|
---|
329 |
|
---|
330 | stop_vboxusbmon()
|
---|
331 | {
|
---|
332 | if vboxusbmon_loaded; then
|
---|
333 | vboxusbmon_mod_id=`/usr/sbin/modinfo | grep $USBMODNAME | cut -f 1 -d ' '`
|
---|
334 | if test -n "$vboxusbmon_mod_id"; then
|
---|
335 | /usr/sbin/modunload -i $vboxusbmon_mod_id
|
---|
336 |
|
---|
337 | # see stop_vboxdrv() for why we have "alwaysremdrv".
|
---|
338 | if test -n "$ALWAYSREMDRV"; then
|
---|
339 | /usr/sbin/rem_drv $USBMODNAME
|
---|
340 | else
|
---|
341 | if test "$?" -eq 0; then
|
---|
342 | /usr/sbin/rem_drv $USBMODNAME || abort "Unloaded VirtualBox USB Monitor kernel module, but failed to remove it!"
|
---|
343 | else
|
---|
344 | abort "Failed to unload VirtualBox USB Monitor kernel module. Old one still active!!"
|
---|
345 | fi
|
---|
346 | fi
|
---|
347 |
|
---|
348 | info "VirtualBox USB kernel module unloaded."
|
---|
349 | fi
|
---|
350 | elif vboxusbmon_added; then
|
---|
351 | /usr/sbin/rem_drv $USBMODNAME || abort "Unloaded VirtualBox USB Monitor kernel module, but failed to remove it!"
|
---|
352 | info "VirtualBox USB kernel module unloaded."
|
---|
353 | elif test -z "$SILENTUNLOAD"; then
|
---|
354 | info "VirtualBox USB kernel module not loaded."
|
---|
355 | fi
|
---|
356 | }
|
---|
357 |
|
---|
358 | status_vboxdrv()
|
---|
359 | {
|
---|
360 | if vboxdrv_loaded; then
|
---|
361 | info "Running."
|
---|
362 | elif vboxdrv_added; then
|
---|
363 | info "Inactive."
|
---|
364 | else
|
---|
365 | info "Not installed."
|
---|
366 | fi
|
---|
367 | }
|
---|
368 |
|
---|
369 | stop_all_modules()
|
---|
370 | {
|
---|
371 | stop_vboxusbmon
|
---|
372 | stop_vboxnet
|
---|
373 | stop_vboxflt
|
---|
374 | stop_module
|
---|
375 | }
|
---|
376 |
|
---|
377 | start_all_modules()
|
---|
378 | {
|
---|
379 | start_module
|
---|
380 | start_vboxflt
|
---|
381 | start_vboxnet
|
---|
382 | start_vboxusbmon
|
---|
383 | }
|
---|
384 |
|
---|
385 | check_root
|
---|
386 | check_if_installed
|
---|
387 |
|
---|
388 | if test "$2" = "silentunload" || test "$3" = "silentunload"; then
|
---|
389 | SILENTUNLOAD="$2"
|
---|
390 | fi
|
---|
391 |
|
---|
392 | if test "$2" = "alwaysremdrv" || test "$3" = "alwaysremdrv"; then
|
---|
393 | ALWAYSREMDRV="alwaysremdrv"
|
---|
394 | fi
|
---|
395 |
|
---|
396 | if test "$2" = "checkarch" || test "$3" = "checkarch"; then
|
---|
397 | CHECKARCH="checkarch"
|
---|
398 | fi
|
---|
399 |
|
---|
400 | case "$1" in
|
---|
401 | stopall)
|
---|
402 | stop_all_modules
|
---|
403 | ;;
|
---|
404 | startall)
|
---|
405 | start_all_modules
|
---|
406 | ;;
|
---|
407 | start)
|
---|
408 | start_module
|
---|
409 | ;;
|
---|
410 | stop)
|
---|
411 | stop_module
|
---|
412 | ;;
|
---|
413 | status)
|
---|
414 | status_vboxdrv
|
---|
415 | ;;
|
---|
416 | fltstart)
|
---|
417 | start_vboxflt
|
---|
418 | ;;
|
---|
419 | fltstop)
|
---|
420 | stop_vboxflt
|
---|
421 | ;;
|
---|
422 | usbstart)
|
---|
423 | start_vboxusbmon
|
---|
424 | ;;
|
---|
425 | usbstop)
|
---|
426 | stop_vboxusbmon
|
---|
427 | ;;
|
---|
428 | netstart)
|
---|
429 | start_vboxnet
|
---|
430 | ;;
|
---|
431 | netstop)
|
---|
432 | stop_vboxnet
|
---|
433 | ;;
|
---|
434 | *)
|
---|
435 | echo "Usage: $0 {start|stop|status|fltstart|fltstop|usbstart|usbstop|netstart|netstop|stopall|startall}"
|
---|
436 | exit 1
|
---|
437 | esac
|
---|
438 |
|
---|
439 | exit 0
|
---|
440 |
|
---|