1 | #!/bin/sh
|
---|
2 | # Sun xVM VirtualBox
|
---|
3 | # VirtualBox kernel module control script for Solaris.
|
---|
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 |
|
---|
20 | SILENTUNLOAD=""
|
---|
21 | MODNAME="vboxdrv"
|
---|
22 | FLTMODNAME="vboxflt"
|
---|
23 | MODDIR32="/platform/i86pc/kernel/drv"
|
---|
24 | MODDIR64=$MODDIR32/amd64
|
---|
25 |
|
---|
26 | abort()
|
---|
27 | {
|
---|
28 | echo 1>&2 "## $1"
|
---|
29 | exit 1
|
---|
30 | }
|
---|
31 |
|
---|
32 | info()
|
---|
33 | {
|
---|
34 | echo 1>&2 "$1"
|
---|
35 | }
|
---|
36 |
|
---|
37 | check_if_installed()
|
---|
38 | {
|
---|
39 | cputype=`isainfo -k`
|
---|
40 | modulepath="$MODDIR32/$MODNAME"
|
---|
41 | if test "$cputype" = "amd64"; then
|
---|
42 | modulepath="$MODDIR64/$MODNAME"
|
---|
43 | fi
|
---|
44 | if test -f "$modulepath"; then
|
---|
45 | return 0
|
---|
46 | fi
|
---|
47 |
|
---|
48 | # Let us go a step further and check if user has mixed up x86/amd64
|
---|
49 | # amd64 ISA, x86 kernel module??
|
---|
50 | if test "$cputype" = "amd64"; then
|
---|
51 | modulepath="$MODDIR32/$MODNAME"
|
---|
52 | if test -f "$modulepath"; then
|
---|
53 | abort "Found 32-bit module instead of 64-bit. Please install the amd64 package!"
|
---|
54 | fi
|
---|
55 | else
|
---|
56 | # x86 ISA, amd64 kernel module??
|
---|
57 | modulepath="$MODDIR64/$MODNAME"
|
---|
58 | if test -f "$modulepath"; then
|
---|
59 | abort "Found 64-bit module instead of 32-bit. Please install the x86 package!"
|
---|
60 | fi
|
---|
61 | fi
|
---|
62 |
|
---|
63 | abort "VirtualBox Host kernel module NOT installed."
|
---|
64 | }
|
---|
65 |
|
---|
66 | module_loaded()
|
---|
67 | {
|
---|
68 | if test -f "/etc/name_to_major"; then
|
---|
69 | loadentry=`cat /etc/name_to_major | grep $MODNAME`
|
---|
70 | else
|
---|
71 | loadentry=`/usr/sbin/modinfo | grep $MODNAME`
|
---|
72 | fi
|
---|
73 | if test -z "$loadentry"; then
|
---|
74 | return 1
|
---|
75 | fi
|
---|
76 | return 0
|
---|
77 | }
|
---|
78 |
|
---|
79 | vboxflt_module_loaded()
|
---|
80 | {
|
---|
81 | if test -f "/etc/name_to_major"; then
|
---|
82 | loadentry=`cat /etc/name_to_major | grep $FLTMODNAME`
|
---|
83 | else
|
---|
84 | loadentry=`/usr/sbin/modinfo | grep $FLTMODNAME`
|
---|
85 | fi
|
---|
86 | if test -z "$loadentry"; then
|
---|
87 | return 1
|
---|
88 | fi
|
---|
89 | return 0
|
---|
90 | }
|
---|
91 |
|
---|
92 | check_root()
|
---|
93 | {
|
---|
94 | idbin=/usr/xpg4/bin/id
|
---|
95 | if test ! -f "$idbin"; then
|
---|
96 | found=`which id | grep "no id"`
|
---|
97 | if test ! -z "$found"; then
|
---|
98 | abort "Failed to find a suitable user id binary! Aborting"
|
---|
99 | else
|
---|
100 | idbin=$found
|
---|
101 | fi
|
---|
102 | fi
|
---|
103 |
|
---|
104 | if test `$idbin -u` -ne 0; then
|
---|
105 | abort "This program must be run with administrator privileges. Aborting"
|
---|
106 | fi
|
---|
107 | }
|
---|
108 |
|
---|
109 | start_module()
|
---|
110 | {
|
---|
111 | if module_loaded; then
|
---|
112 | info "VirtualBox Host kernel module already loaded."
|
---|
113 | else
|
---|
114 | if test -n "_HARDENED_"; then
|
---|
115 | /usr/sbin/add_drv -m'* 0600 root sys' $MODNAME
|
---|
116 | else
|
---|
117 | /usr/sbin/add_drv -m'* 0666 root sys' $MODNAME
|
---|
118 | fi
|
---|
119 | if test ! module_loaded; then
|
---|
120 | abort "Failed to load VirtualBox Host kernel module."
|
---|
121 | elif test -c "/devices/pseudo/$MODNAME@0:$MODNAME"; then
|
---|
122 | info "VirtualBox Host kernel module loaded."
|
---|
123 | else
|
---|
124 | abort "Aborting due to attach failure."
|
---|
125 | fi
|
---|
126 | fi
|
---|
127 | }
|
---|
128 |
|
---|
129 | stop_module()
|
---|
130 | {
|
---|
131 | if module_loaded; then
|
---|
132 | /usr/sbin/rem_drv $MODNAME || info "## WARNING!! Failed to unload VirtualBox Host kernel module. Old one still active!"
|
---|
133 | info "VirtualBox Host kernel module unloaded."
|
---|
134 | elif test -z "$SILENTUNLOAD"; then
|
---|
135 | info "VirtualBox Host kernel module not loaded."
|
---|
136 | fi
|
---|
137 |
|
---|
138 | # check for vbi and force unload it
|
---|
139 | vbi_mod_id=`/usr/sbin/modinfo | grep vbi | cut -f 1 -d ' ' `
|
---|
140 | if test -n "$vbi_mod_id"; then
|
---|
141 | /usr/sbin/modunload -i $vbi_mod_id > /dev/null 2>&1
|
---|
142 | fi
|
---|
143 | }
|
---|
144 |
|
---|
145 | start_vboxflt()
|
---|
146 | {
|
---|
147 | if vboxflt_module_loaded; then
|
---|
148 | info "VirtualBox NetFilter kernel module already loaded."
|
---|
149 | else
|
---|
150 | /usr/sbin/add_drv -m'* 0600 root sys' $FLTMODNAME
|
---|
151 | /usr/sbin/modload -p drv/$FLTMODNAME
|
---|
152 | if test ! vboxflt_module_loaded; then
|
---|
153 | abort "Failed to load VirtualBox NetFilter kernel module."
|
---|
154 | else
|
---|
155 | info "VirtualBox NetFilter kernel module loaded."
|
---|
156 | fi
|
---|
157 | fi
|
---|
158 | }
|
---|
159 |
|
---|
160 | stop_vboxflt()
|
---|
161 | {
|
---|
162 | if vboxflt_module_loaded; then
|
---|
163 | /usr/sbin/rem_drv $FLTMODNAME || info "## WARNING!! Failed to unload VirtualBox NetFilter module. Old one still active!"
|
---|
164 | info "VirtualBox NetFilter kernel module unloaded."
|
---|
165 | elif test -z "$SILENTUNLOAD"; then
|
---|
166 | info "VirtualBox NetFilter kernel module not loaded."
|
---|
167 | fi
|
---|
168 | }
|
---|
169 |
|
---|
170 | status_module()
|
---|
171 | {
|
---|
172 | if module_loaded; then
|
---|
173 | info "Running."
|
---|
174 | else
|
---|
175 | info "Stopped."
|
---|
176 | fi
|
---|
177 | }
|
---|
178 |
|
---|
179 | stop_all_modules()
|
---|
180 | {
|
---|
181 | stop_vboxflt
|
---|
182 | stop_module
|
---|
183 | }
|
---|
184 |
|
---|
185 | start_all_modules()
|
---|
186 | {
|
---|
187 | start_module
|
---|
188 | start_vboxflt
|
---|
189 | }
|
---|
190 |
|
---|
191 | check_root
|
---|
192 | check_if_installed
|
---|
193 |
|
---|
194 | if test "$2" = "silentunload"; then
|
---|
195 | SILENTUNLOAD="$2"
|
---|
196 | fi
|
---|
197 |
|
---|
198 | case "$1" in
|
---|
199 | stopall)
|
---|
200 | stop_all_modules
|
---|
201 | ;;
|
---|
202 | startall)
|
---|
203 | start_all_modules
|
---|
204 | ;;
|
---|
205 | start)
|
---|
206 | start_module
|
---|
207 | ;;
|
---|
208 | stop)
|
---|
209 | stop_module
|
---|
210 | ;;
|
---|
211 | status)
|
---|
212 | status_module
|
---|
213 | ;;
|
---|
214 | fltstart)
|
---|
215 | start_vboxflt
|
---|
216 | ;;
|
---|
217 | fltstop)
|
---|
218 | stop_vboxflt
|
---|
219 | ;;
|
---|
220 | *)
|
---|
221 | echo "Usage: $0 {start|stop|status|fltstart|fltstop|stopall|startall}"
|
---|
222 | exit 1
|
---|
223 | esac
|
---|
224 |
|
---|
225 | exit 0
|
---|
226 |
|
---|