Installing an I/O Kit KEXT Without Rebooting
Q: Is it possible to install an I/O Kit KEXT without requiring a restart?
A: There is no easy solution to this problem. Currently, even Apple's own installers require restarting after a KEXT installation. Here's why this is more complicated than it may seem.
If another driver is currently matched to your device, that driver has to be unloaded first. This in turn means that the device can't be in use. Plus, the preferred mechanism for updating the system's list of known KEXTs does not exist in early releases of Mac OS X.
Given those considerations, here is the logic you should use:
After installing your KEXT, run the touch command on /System/Library/Extensions. Then,
if the release is 10.5 or newer, there's nothing more to do. All KEXT caches except for the prelinked kernel are updated automatically after a short delay; the prelinked kernel is updated after the next restart.
If the release is either 10.3.x or 10.4.x and
kextdis NOT running, require a restart. A shell script can determine whetherkextdis running using the code in Listing 1. This code will return the PID ofkextdif it is running, or return nothing if it isn't.If the release is either 10.3.x or 10.4.x AND
kextdis running, sendkextdaSIGHUPsignal as shown in Listing 2.If the release is 10.2.x or older (Jaguar or before), require a restart.
Listing 1 Determining whether kextd is running.
/bin/ps -ax | /usr/bin/awk '{print $1" "$4}' | grep kextd | /usr/bin/awk '{print $1}' |
Listing 2 Sending a SIGHUP to kextd.
/bin/kill -1 `/bin/ps -ax | /usr/bin/awk '{print $1" "$4}' | grep kextd | /usr/bin/awk '{print $1}'` |
It is important that your install script cope with the case where kextd is not running.
You might wonder if you can just posix_spawn kextload to load your KEXT. This approach has its own pitfalls. If you run kextload but the user waits longer than about a minute to plug in the device, your driver will be unloaded and another matching driver will be loaded for your device instead. And, even if the user plugs in the device promptly, if they unplug the device later, your driver will still be unloaded after a minute. You're now back to the first situation because kextd isn't aware of your KEXT if you've loaded it by hand using kextload. kextd enumerates available KEXTs only according to the logic presented earlier.
Document Revision History
| Date | Notes |
|---|---|
| 2011-07-22 | Reformatted and made minor editorial changes. Added information about Mac OS X 10.5 and later. |
| 2003-10-28 | New document that describes the state of the art of installing I/O Kit kernel extensions (KEXTs) without requiring a restart. |
Copyright © 2011 Apple Inc. All Rights Reserved. Terms of Use | Privacy Policy | Updated: 2011-07-22