VirtualBox

source: vbox/trunk/src/VBox/Installer/darwin/VBoxKEXTs/VirtualBoxStartup.sh@ 91852

Last change on this file since 91852 was 86306, checked in by vboxsync, 4 years ago

Installer/darwin/VBoxKEXTs/VirtualBoxStartup.sh: Make it work with BigSur where we can only load by bundle ID, bugref:9836

  • Property svn:eol-style set to LF
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 11.2 KB
Line 
1#!/bin/sh
2# $Id: VirtualBoxStartup.sh 86306 2020-09-26 14:36:12Z vboxsync $
3## @file
4# Startup service for loading the kernel extensions and select the set of VBox
5# binaries that matches the kernel architecture.
6#
7
8#
9# Copyright (C) 2007-2020 Oracle Corporation
10#
11# This file is part of VirtualBox Open Source Edition (OSE), as
12# available from http://www.virtualbox.org. This file is free software;
13# you can redistribute it and/or modify it under the terms of the GNU
14# General Public License (GPL) as published by the Free Software
15# Foundation, in version 2 as it comes in the "COPYING" file of the
16# VirtualBox OSE distribution. VirtualBox OSE is distributed in the
17# hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
18#
19
20if false; then
21 . /etc/rc.common
22else
23 # Fake the startup item functions we're using.
24
25 ConsoleMessage()
26 {
27 if [ "$1" != "-f" ]; then
28 echo "$@"
29 else
30 shift
31 echo "Fatal error: $@"
32 exit 1;
33 fi
34 }
35
36 RunService()
37 {
38 case "$1" in
39 "start")
40 StartService
41 exit $?;
42 ;;
43 "stop")
44 StopService
45 exit $?;
46 ;;
47 "restart")
48 RestartService
49 exit $?;
50 ;;
51 "launchd")
52 if RestartService; then
53 while true;
54 do
55 sleep 3600
56 done
57 fi
58 exit $?;
59 ;;
60 **)
61 echo "Error: Unknown action '$1'"
62 exit 1;
63 esac
64 }
65fi
66
67
68StartService()
69{
70 VBOX_RC=0
71 VBOXDRV="VBoxDrv"
72 VBOXUSB="VBoxUSB"
73 MACOS_VERS=$(sw_vers -productVersion)
74
75 #
76 # Check that all the directories exist first.
77 #
78 if [ ! -d "/Library/Application Support/VirtualBox/${VBOXDRV}.kext" ]; then
79 ConsoleMessage "Error: /Library/Application Support/VirtualBox/${VBOXDRV}.kext is missing"
80 VBOX_RC=1
81 fi
82 if [ ! -d "/Library/Application Support/VirtualBox/${VBOXUSB}.kext" ]; then
83 ConsoleMessage "Error: /Library/Application Support/VirtualBox/${VBOXUSB}.kext is missing"
84 VBOX_RC=1
85 fi
86 if [ ! -d "/Library/Application Support/VirtualBox/VBoxNetFlt.kext" ]; then
87 ConsoleMessage "Error: /Library/Application Support/VirtualBox/VBoxNetFlt.kext is missing"
88 VBOX_RC=1
89 fi
90 if [ ! -d "/Library/Application Support/VirtualBox/VBoxNetAdp.kext" ]; then
91 ConsoleMessage "Error: /Library/Application Support/VirtualBox/VBoxNetAdp.kext is missing"
92 VBOX_RC=1
93 fi
94
95 #
96 # Check that no drivers are currently running.
97 # (Try stop the service if this is the case.)
98 #
99 if [ $VBOX_RC -eq 0 ]; then
100 if [[ ${MACOS_VERS} != 11.* ]]; then
101 if kextstat -lb org.virtualbox.kext.VBoxDrv 2>&1 | grep -q org.virtualbox.kext.VBoxDrv; then
102 ConsoleMessage "Error: ${VBOXDRV}.kext is already loaded"
103 VBOX_RC=1
104 fi
105 if kextstat -lb org.virtualbox.kext.VBoxUSB 2>&1 | grep -q org.virtualbox.kext.VBoxUSB; then
106 ConsoleMessage "Error: ${VBOXUSB}.kext is already loaded"
107 VBOX_RC=1
108 fi
109 if kextstat -lb org.virtualbox.kext.VBoxNetFlt 2>&1 | grep -q org.virtualbox.kext.VBoxNetFlt; then
110 ConsoleMessage "Error: VBoxNetFlt.kext is already loaded"
111 VBOX_RC=1
112 fi
113 if kextstat -lb org.virtualbox.kext.VBoxNetAdp 2>&1 | grep -q org.virtualbox.kext.VBoxNetAdp; then
114 ConsoleMessage "Error: VBoxNetAdp.kext is already loaded"
115 VBOX_RC=1
116 fi
117 else
118 #
119 # Use kmutil directly on BigSur or grep will erroneously trigger because kextstat dumps the kmutil
120 # invocation to stdout...
121 #
122 if kmutil showloaded --list-only -b org.virtualbox.kext.VBoxDrv 2>&1 | grep -q org.virtualbox.kext.VBoxDrv; then
123 ConsoleMessage "Error: ${VBOXDRV}.kext is already loaded"
124 VBOX_RC=1
125 fi
126 if kmutil showloaded --list-only -b org.virtualbox.kext.VBoxUSB 2>&1 | grep -q org.virtualbox.kext.VBoxUSB; then
127 ConsoleMessage "Error: ${VBOXUSB}.kext is already loaded"
128 VBOX_RC=1
129 fi
130 if kmutil showloaded --list-only -b org.virtualbox.kext.VBoxNetFlt 2>&1 | grep -q org.virtualbox.kext.VBoxNetFlt; then
131 ConsoleMessage "Error: VBoxNetFlt.kext is already loaded"
132 VBOX_RC=1
133 fi
134 if kmutil showloaded --list-only -b org.virtualbox.kext.VBoxNetAdp 2>&1 | grep -q org.virtualbox.kext.VBoxNetAdp; then
135 ConsoleMessage "Error: VBoxNetAdp.kext is already loaded"
136 VBOX_RC=1
137 fi
138 fi
139 fi
140
141 #
142 # Load the drivers.
143 #
144 if [ $VBOX_RC -eq 0 ]; then
145 if [[ ${MACOS_VERS} != 11.* ]]; then
146 ConsoleMessage "Loading ${VBOXDRV}.kext"
147 if ! kextload "/Library/Application Support/VirtualBox/${VBOXDRV}.kext"; then
148 ConsoleMessage "Error: Failed to load /Library/Application Support/VirtualBox/${VBOXDRV}.kext"
149 VBOX_RC=1
150 fi
151
152 ConsoleMessage "Loading ${VBOXUSB}.kext"
153 if ! kextload -d "/Library/Application Support/VirtualBox/${VBOXDRV}.kext" "/Library/Application Support/VirtualBox/${VBOXUSB}.kext"; then
154 ConsoleMessage "Error: Failed to load /Library/Application Support/VirtualBox/${VBOXUSB}.kext"
155 VBOX_RC=1
156 fi
157
158 ConsoleMessage "Loading VBoxNetFlt.kext"
159 if ! kextload -d "/Library/Application Support/VirtualBox/${VBOXDRV}.kext" "/Library/Application Support/VirtualBox/VBoxNetFlt.kext"; then
160 ConsoleMessage "Error: Failed to load /Library/Application Support/VirtualBox/VBoxNetFlt.kext"
161 VBOX_RC=1
162 fi
163
164 ConsoleMessage "Loading VBoxNetAdp.kext"
165 if ! kextload -d "/Library/Application Support/VirtualBox/${VBOXDRV}.kext" "/Library/Application Support/VirtualBox/VBoxNetAdp.kext"; then
166 ConsoleMessage "Error: Failed to load /Library/Application Support/VirtualBox/VBoxNetAdp.kext"
167 VBOX_RC=1
168 fi
169 else
170 #
171 # On BigSur we can only load by bundle ID because the drivers are baked into a kext collection image
172 # and the real path is never loaded actually.
173 #
174 ConsoleMessage "Loading ${VBOXDRV}.kext"
175 if ! kmutil load -b org.virtualbox.kext.VBoxDrv; then
176 ConsoleMessage "Error: Failed to load org.virtualbox.kext.VBoxDrv"
177 VBOX_RC=1
178 fi
179
180 ConsoleMessage "Loading ${VBOXUSB}.kext"
181 if ! kmutil load -b org.virtualbox.kext.VBoxUSB; then
182 ConsoleMessage "Error: Failed to load org.virtualbox.kext.VBoxUSB"
183 VBOX_RC=1
184 fi
185
186 ConsoleMessage "Loading VBoxNetFlt.kext"
187 if ! kmutil load -b org.virtualbox.kext.VBoxNetFlt; then
188 ConsoleMessage "Error: Failed to load org.virtualbox.kext.VBoxNetFlt"
189 VBOX_RC=1
190 fi
191
192 ConsoleMessage "Loading VBoxNetAdp.kext"
193 if ! kmutil load -b org.virtualbox.kext.VBoxNetAdp; then
194 ConsoleMessage "Error: Failed to load org.virtualbox.kext.VBoxNetAdp"
195 VBOX_RC=1
196 fi
197 fi
198
199 if [ $VBOX_RC -ne 0 ]; then
200 # unload the drivers (ignoring failures)
201 kextunload -b org.virtualbox.kext.VBoxNetAdp
202 kextunload -b org.virtualbox.kext.VBoxNetFlt
203 kextunload -b org.virtualbox.kext.VBoxUSB
204 kextunload -b org.virtualbox.kext.VBoxDrv
205 fi
206 fi
207
208 #
209 # Set the error on failure.
210 #
211 if [ "$VBOX_RC" -ne "0" ]; then
212 ConsoleMessage -f VirtualBox
213 exit $VBOX_RC
214 fi
215}
216
217
218StopService()
219{
220 VBOX_RC=0
221 VBOXDRV="VBoxDrv"
222 VBOXUSB="VBoxUSB"
223 MACOS_VERS=$(sw_vers -productVersion)
224
225 if [[ ${MACOS_VERS} != 11.* ]]; then
226 if kextstat -lb org.virtualbox.kext.VBoxUSB 2>&1 | grep -q org.virtualbox.kext.VBoxUSB; then
227 ConsoleMessage "Unloading ${VBOXUSB}.kext"
228 if ! kextunload -m org.virtualbox.kext.VBoxUSB; then
229 ConsoleMessage "Error: Failed to unload VBoxUSB.kext"
230 VBOX_RC=1
231 fi
232 fi
233
234 if kextstat -lb org.virtualbox.kext.VBoxNetFlt 2>&1 | grep -q org.virtualbox.kext.VBoxNetFlt; then
235 ConsoleMessage "Unloading VBoxNetFlt.kext"
236 if ! kextunload -m org.virtualbox.kext.VBoxNetFlt; then
237 ConsoleMessage "Error: Failed to unload VBoxNetFlt.kext"
238 VBOX_RC=1
239 fi
240 fi
241
242 if kextstat -lb org.virtualbox.kext.VBoxNetAdp 2>&1 | grep -q org.virtualbox.kext.VBoxNetAdp; then
243 ConsoleMessage "Unloading VBoxNetAdp.kext"
244 if ! kextunload -m org.virtualbox.kext.VBoxNetAdp; then
245 ConsoleMessage "Error: Failed to unload VBoxNetAdp.kext"
246 VBOX_RC=1
247 fi
248 fi
249
250 # This must come last because of dependencies.
251 if kextstat -lb org.virtualbox.kext.VBoxDrv 2>&1 | grep -q org.virtualbox.kext.VBoxDrv; then
252 ConsoleMessage "Unloading ${VBOXDRV}.kext"
253 if ! kextunload -m org.virtualbox.kext.VBoxDrv; then
254 ConsoleMessage "Error: Failed to unload VBoxDrv.kext"
255 VBOX_RC=1
256 fi
257 fi
258 else
259 if kmutil showloaded --list-only -b org.virtualbox.kext.VBoxUSB 2>&1 | grep -q org.virtualbox.kext.VBoxUSB; then
260 ConsoleMessage "Unloading ${VBOXUSB}.kext"
261 if ! kmutil unload -b org.virtualbox.kext.VBoxUSB; then
262 ConsoleMessage "Error: Failed to unload VBoxUSB.kext"
263 VBOX_RC=1
264 fi
265 fi
266
267 if kmutil showloaded --list-only -b org.virtualbox.kext.VBoxNetFlt 2>&1 | grep -q org.virtualbox.kext.VBoxNetFlt; then
268 ConsoleMessage "Unloading VBoxNetFlt.kext"
269 if ! kmutil unload -b org.virtualbox.kext.VBoxNetFlt; then
270 ConsoleMessage "Error: Failed to unload VBoxNetFlt.kext"
271 VBOX_RC=1
272 fi
273 fi
274
275 if kmutil showloaded --list-only -b org.virtualbox.kext.VBoxNetAdp 2>&1 | grep -q org.virtualbox.kext.VBoxNetAdp; then
276 ConsoleMessage "Unloading VBoxNetAdp.kext"
277 if ! kmutil unload -b org.virtualbox.kext.VBoxNetAdp; then
278 ConsoleMessage "Error: Failed to unload VBoxNetAdp.kext"
279 VBOX_RC=1
280 fi
281 fi
282
283 # This must come last because of dependencies.
284 if kmutil showloaded --list-only -b org.virtualbox.kext.VBoxDrv 2>&1 | grep -q org.virtualbox.kext.VBoxDrv; then
285 ConsoleMessage "Unloading ${VBOXDRV}.kext"
286 if ! kmutil unload -b org.virtualbox.kext.VBoxDrv; then
287 ConsoleMessage "Error: Failed to unload VBoxDrv.kext"
288 VBOX_RC=1
289 fi
290 fi
291 fi
292
293 # Set the error on failure.
294 if [ "$VBOX_RC" -ne "0" ]; then
295 ConsoleMessage -f VirtualBox
296 exit $VBOX_RC
297 fi
298}
299
300
301RestartService()
302{
303 StopService
304 StartService
305}
306
307
308RunService "$1"
309
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