VirtualBox

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

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

Solaris/Installer: vboxnet0 default netmask fix.

  • Property svn:eol-style set to LF
  • Property svn:executable set to *
File size: 12.1 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 if test "$?" -eq 0; then
283 /sbin/ifconfig vboxnet0 192.168.56.1 netmask 255.255.255.0 up
284 info "VirtualBox NetAdapter kernel module loaded."
285 else
286 warn "VirtualBox NetAdapter kernel module loaded BUT failed to plumb interface."
287 fi
288 fi
289 fi
290}
291
292stop_vboxnet()
293{
294 if vboxnet_loaded; then
295 vboxnet_mod_id=`/usr/sbin/modinfo | grep $NETMODNAME | cut -f 1 -d ' '`
296 if test -n "$vboxnet_mod_id"; then
297 /sbin/ifconfig vboxnet0 unplumb
298 /usr/sbin/modunload -i $vboxnet_mod_id
299
300 # see stop_vboxdrv() for why we have "alwaysremdrv".
301 if test -n "$ALWAYSREMDRV"; then
302 /usr/sbin/rem_drv $NETMODNAME
303 else
304 if test "$?" -eq 0; then
305 /usr/sbin/rem_drv $NETMODNAME || abort "Unloaded VirtualBox NetAdapter kernel module, but failed to remove it!"
306 else
307 abort "Failed to unload VirtualBox NetAdapter kernel module. Old one still active!!"
308 fi
309 fi
310
311 info "VirtualBox NetAdapter kernel module unloaded."
312 fi
313 elif vboxnet_added; then
314 /usr/sbin/rem_drv $NETMODNAME || abort "Unloaded VirtualBox NetAdapter kernel module, but failed to remove it!"
315 info "VirtualBox NetAdapter kernel module unloaded."
316 elif test -z "$SILENTUNLOAD"; then
317 info "VirtualBox NetAdapter kernel module not loaded."
318 fi
319}
320
321
322start_vboxusbmon()
323{
324 if vboxusbmon_loaded; then
325 info "VirtualBox USB Monitor kernel module already loaded."
326 else
327 /usr/sbin/add_drv -m'* 0666 root sys' $USBMODNAME || abort "Failed to add VirtualBox USB Monitor Kernel module."
328 /usr/sbin/modload -p drv/$USBMODNAME
329 if test ! vboxusbmon_loaded; then
330 abort "Failed to load VirtualBox USB kernel module."
331 else
332 info "VirtualBox USB kernel module loaded."
333 fi
334 fi
335}
336
337stop_vboxusbmon()
338{
339 if vboxusbmon_loaded; then
340 vboxusbmon_mod_id=`/usr/sbin/modinfo | grep $USBMODNAME | cut -f 1 -d ' '`
341 if test -n "$vboxusbmon_mod_id"; then
342 /usr/sbin/modunload -i $vboxusbmon_mod_id
343
344 # see stop_vboxdrv() for why we have "alwaysremdrv".
345 if test -n "$ALWAYSREMDRV"; then
346 /usr/sbin/rem_drv $USBMODNAME
347 else
348 if test "$?" -eq 0; then
349 /usr/sbin/rem_drv $USBMODNAME || abort "Unloaded VirtualBox USB Monitor kernel module, but failed to remove it!"
350 else
351 abort "Failed to unload VirtualBox USB Monitor kernel module. Old one still active!!"
352 fi
353 fi
354
355 info "VirtualBox USB kernel module unloaded."
356 fi
357 elif vboxusbmon_added; then
358 /usr/sbin/rem_drv $USBMODNAME || abort "Unloaded VirtualBox USB Monitor kernel module, but failed to remove it!"
359 info "VirtualBox USB kernel module unloaded."
360 elif test -z "$SILENTUNLOAD"; then
361 info "VirtualBox USB kernel module not loaded."
362 fi
363}
364
365status_vboxdrv()
366{
367 if vboxdrv_loaded; then
368 info "Running."
369 elif vboxdrv_added; then
370 info "Inactive."
371 else
372 info "Not installed."
373 fi
374}
375
376stop_all_modules()
377{
378 stop_vboxusbmon
379 stop_vboxnet
380 stop_vboxflt
381 stop_module
382}
383
384start_all_modules()
385{
386 start_module
387 start_vboxflt
388 start_vboxnet
389 start_vboxusbmon
390}
391
392check_root
393check_if_installed
394
395if test "$2" = "silentunload" || test "$3" = "silentunload"; then
396 SILENTUNLOAD="$2"
397fi
398
399if test "$2" = "alwaysremdrv" || test "$3" = "alwaysremdrv"; then
400 ALWAYSREMDRV="alwaysremdrv"
401fi
402
403if test "$2" = "checkarch" || test "$3" = "checkarch"; then
404 CHECKARCH="checkarch"
405fi
406
407case "$1" in
408stopall)
409 stop_all_modules
410 ;;
411startall)
412 start_all_modules
413 ;;
414start)
415 start_module
416 ;;
417stop)
418 stop_module
419 ;;
420status)
421 status_vboxdrv
422 ;;
423fltstart)
424 start_vboxflt
425 ;;
426fltstop)
427 stop_vboxflt
428 ;;
429usbstart)
430 start_vboxusbmon
431 ;;
432usbstop)
433 stop_vboxusbmon
434 ;;
435netstart)
436 start_vboxnet
437 ;;
438netstop)
439 stop_vboxnet
440 ;;
441*)
442 echo "Usage: $0 {start|stop|status|fltstart|fltstop|usbstart|usbstop|netstart|netstop|stopall|startall}"
443 exit 1
444esac
445
446exit 0
447
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