VirtualBox

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

Last change on this file since 16793 was 15912, checked in by vboxsync, 16 years ago

Solaris/Installer: Changes for #3381 (combined package).

  • Property svn:eol-style set to LF
  • Property svn:executable set to *
File size: 7.9 KB
Line 
1#!/bin/sh
2# Sun xVM VirtualBox
3# VirtualBox kernel module control script, Solaris hosts.
4#
5# Copyright (C) 2007-2008 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"
27MODDIR32="/platform/i86pc/kernel/drv"
28MODDIR64=$MODDIR32/amd64
29
30abort()
31{
32 echo 1>&2 "## $1"
33 exit 1
34}
35
36info()
37{
38 echo 1>&2 "$1"
39}
40
41warn()
42{
43 echo 1>&2 "WARNING!! $1"
44}
45
46check_if_installed()
47{
48 cputype=`isainfo -k`
49 modulepath="$MODDIR32/$MODNAME"
50 if test "$cputype" = "amd64"; then
51 modulepath="$MODDIR64/$MODNAME"
52 fi
53 if test -f "$modulepath"; then
54 return 0
55 fi
56
57 # Check arch only while installing (because rem_drv works for both arch.)
58 if test ! -z "$CHECKARCH"; then
59 # Let us go a step further and check if user has mixed up x86/amd64
60 # amd64 ISA, x86 kernel module??
61 if test "$cputype" = "amd64"; then
62 modulepath="$MODDIR32/$MODNAME"
63 if test -f "$modulepath"; then
64 abort "Found 32-bit module instead of 64-bit. Please install the amd64 package!"
65 fi
66 else
67 # x86 ISA, amd64 kernel module??
68 modulepath="$MODDIR64/$MODNAME"
69 if test -f "$modulepath"; then
70 abort "Found 64-bit module instead of 32-bit. Please install the x86 package!"
71 fi
72 fi
73
74 abort "VirtualBox Host kernel module NOT installed."
75 else
76 info "## VirtualBox Host kernel module NOT installed."
77 return 0
78 fi
79}
80
81module_added()
82{
83 loadentry=`cat /etc/name_to_major | grep $1`
84 if test -z "$loadentry"; then
85 return 1
86 fi
87 return 0
88}
89
90module_loaded()
91{
92 # modinfo should now work properly since we prevent module autounloading
93 loadentry=`/usr/sbin/modinfo | grep $1`
94 if test -z "$loadentry"; then
95 return 1
96 fi
97 return 0
98}
99
100vboxdrv_loaded()
101{
102 module_loaded $MODNAME
103 return $?
104}
105
106vboxdrv_added()
107{
108 module_added $MODNAME
109 return $?
110}
111
112vboxflt_loaded()
113{
114 module_loaded $FLTMODNAME
115 return $?
116}
117
118vboxflt_added()
119{
120 module_added $FLTMODNAME
121 return $?
122}
123
124check_root()
125{
126 idbin=/usr/xpg4/bin/id
127 if test ! -f "$idbin"; then
128 found=`which id | grep "no id"`
129 if test ! -z "$found"; then
130 abort "Failed to find a suitable user id binary! Aborting"
131 else
132 idbin=$found
133 fi
134 fi
135
136 if test `$idbin -u` -ne 0; then
137 abort "This program must be run with administrator privileges. Aborting"
138 fi
139}
140
141start_module()
142{
143 if vboxdrv_loaded; then
144 info "VirtualBox Host kernel module already loaded."
145 else
146 if test -n "_HARDENED_"; then
147 /usr/sbin/add_drv -m'* 0600 root sys' $MODNAME || abort "Failed to add VirtualBox Host Kernel module."
148 else
149 /usr/sbin/add_drv -m'* 0666 root sys' $MODNAME || abort "Failed to add VirtualBox Host Kernel module."
150 fi
151 /usr/sbin/modload -p drv/$MODNAME
152 if test ! vboxdrv_loaded; then
153 abort "Failed to load VirtualBox Host kernel module."
154 elif test -c "/devices/pseudo/$MODNAME@0:$MODNAME"; then
155 info "VirtualBox Host kernel module loaded."
156 else
157 abort "Aborting due to attach failure."
158 fi
159 fi
160}
161
162stop_module()
163{
164 if vboxdrv_loaded; then
165 vboxdrv_mod_id=`/usr/sbin/modinfo | grep $MODNAME | cut -f 1 -d ' ' `
166 if test -n "$vboxdrv_mod_id"; then
167 /usr/sbin/modunload -i $vboxdrv_mod_id
168
169 # While uninstalling we always remove the driver whether we unloaded successfully or not,
170 # while installing we make SURE if there is an existing driver about, it is cleanly unloaded
171 # and the new one is added hence the "alwaysremdrv" option.
172 if test -n "$ALWAYSREMDRV"; then
173 /usr/sbin/rem_drv $MODNAME
174 else
175 if test "$?" -eq 0; then
176 /usr/sbin/rem_drv $MODNAME || abort "Unloaded VirtualBox Host kernel module, but failed to remove it!"
177 else
178 abort "Failed to unload VirtualBox Host kernel module. Old one still active!!"
179 fi
180 fi
181
182 info "VirtualBox Host kernel module unloaded."
183 fi
184 elif vboxdrv_added; then
185 /usr/sbin/rem_drv $MODNAME || abort "Unloaded VirtualBox Host kernel module, but failed to remove it!"
186 info "VirtualBox Host kernel module unloaded."
187 elif test -z "$SILENTUNLOAD"; then
188 info "VirtualBox Host kernel module not loaded."
189 fi
190
191 # check for vbi and force unload it
192 vbi_mod_id=`/usr/sbin/modinfo | grep $VBIMODNAME | cut -f 1 -d ' ' `
193 if test -n "$vbi_mod_id"; then
194 /usr/sbin/modunload -i $vbi_mod_id
195 fi
196}
197
198start_vboxflt()
199{
200 if vboxflt_loaded; then
201 info "VirtualBox NetFilter kernel module already loaded."
202 else
203 /usr/sbin/add_drv -m'* 0600 root sys' $FLTMODNAME || abort "Failed to add VirtualBox NetFilter Kernel module."
204 /usr/sbin/modload -p drv/$FLTMODNAME
205 if test ! vboxflt_loaded; then
206 abort "Failed to load VirtualBox NetFilter kernel module."
207 else
208 info "VirtualBox NetFilter kernel module loaded."
209 fi
210 fi
211}
212
213stop_vboxflt()
214{
215 if vboxflt_loaded; then
216 vboxflt_mod_id=`/usr/sbin/modinfo | grep $FLTMODNAME | cut -f 1 -d ' '`
217 if test -n "$vboxflt_mod_id"; then
218 /usr/sbin/modunload -i $vboxflt_mod_id
219
220 # see stop_vboxdrv() for why we have "alwaysremdrv".
221 if test -n "$ALWAYSREMDRV"; then
222 /usr/sbin/rem_drv $FLTMODNAME
223 else
224 if test "$?" -eq 0; then
225 /usr/sbin/rem_drv $FLTMODNAME || abort "Unloaded VirtualBox NetFilter kernel module, but failed to remove it!"
226 else
227 abort "Failed to unload VirtualBox NetFilter kernel module. Old one still active!!"
228 fi
229 fi
230
231 info "VirtualBox NetFilter kernel module unloaded."
232 fi
233 elif vboxflt_added; then
234 /usr/sbin/rem_drv $FLTMODNAME || abort "Unloaded VirtualBox NetFilter kernel module, but failed to remove it!"
235 info "VirtualBox NetFilter kernel module unloaded."
236 elif test -z "$SILENTUNLOAD"; then
237 info "VirtualBox NetFilter kernel module not loaded."
238 fi
239}
240
241status_vboxdrv()
242{
243 if vboxdrv_loaded; then
244 info "Running."
245 elif vboxdrv_added; then
246 info "Inactive."
247 else
248 info "Not installed."
249 fi
250}
251
252stop_all_modules()
253{
254 stop_vboxflt
255 stop_module
256}
257
258start_all_modules()
259{
260 start_module
261 start_vboxflt
262}
263
264check_root
265check_if_installed
266
267if test "$2" = "silentunload" || test "$3" = "silentunload"; then
268 SILENTUNLOAD="$2"
269fi
270
271if test "$2" = "alwaysremdrv" || test "$3" = "alwaysremdrv"; then
272 ALWAYSREMDRV="alwaysremdrv"
273fi
274
275if test "$2" = "checkarch" || test "$3" = "checkarch"; then
276 CHECKARCH="checkarch"
277fi
278
279case "$1" in
280stopall)
281 stop_all_modules
282 ;;
283startall)
284 start_all_modules
285 ;;
286start)
287 start_module
288 ;;
289stop)
290 stop_module
291 ;;
292status)
293 status_vboxdrv
294 ;;
295fltstart)
296 start_vboxflt
297 ;;
298fltstop)
299 stop_vboxflt
300 ;;
301*)
302 echo "Usage: $0 {start|stop|status|fltstart|fltstop|stopall|startall}"
303 exit 1
304esac
305
306exit 0
307
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