VirtualBox

source: vbox/trunk/src/VBox/Installer/solaris/vboxdrv.sh@ 20915

Last change on this file since 20915 was 20915, checked in by vboxsync, 15 years ago

Solaris/Installer: only i386/amd64 please.

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