kextunload - macOS


Overview

kextunload is a command-line utility used on macOS to unload kernel extensions (kexts). Kernel extensions extend the functionality of the macOS kernel, providing additional capabilities directly at the system level. The primary purpose of kextunload is to allow system administrators and users to manually remove a kernel extension from the kernel, which is useful for troubleshooting, system maintenance, or reversing a previous extension load operation.

Syntax

The basic syntax of the kextunload command is as follows:

kextunload [options] <kext>
  • <kext>: Specifies the path to the kernel extension bundle or the bundle identifier that you want to unload.

Variations

  • Unload using a direct path:

    kextunload /System/Library/Extensions/MyDriver.kext
    
  • Unload using a bundle identifier:

    kextunload -b com.example.driver.mydriver
    

Options/Flags

  • -b <bundle_id>: Unload the kernel extension with the specified bundle identifier. Use this when you do not know the exact path or when the path may vary.

  • -q: Quiet mode. This option suppresses non-critical output, useful in scripts or automated tasks to reduce noise.

  • -h: Help. Displays help information about the command usage.

Examples

  1. Unload a Kext by Path:
    To unload a kernel extension located at a specific path:

    kextunload /System/Library/Extensions/MyDriver.kext
    
  2. Unload Multiple Kexts:
    To unload several kernel extensions at once, list them all:

    kextunload /path/to/first.kext /path/to/second.kext
    
  3. Use of Bundle Identifier:
    If you prefer not to use the full path, or the path is subject to change, use the bundle identifier:

    kextunload -b com.example.driver.mydriver
    

Common Issues

  • Permission Errors: Attempting to unload a kernel extension without sufficient privileges. Ensure you run the command with sudo:

    sudo kextunload /System/Library/Extensions/MyDriver.kext
    
  • Kext Not Found: Ensure the path or bundle identifier is correctly specified. Typos or incorrect bundle IDs will prevent the unload operation.

Integration

Combine kextunload with kextload for testing kernel extension behavior changes without rebooting. Example script to reload a kernel extension:

sudo kextunload /System/Library/Extensions/MyDriver.kext
sudo kextload /System/Library/Extensions/MyDriver.kext

This can be useful for development or troubleshooting of kernel extensions.

  • kextload: Load kernel extensions.
  • kextstat: Show loaded kernel extensions.

For more detailed information, consult the macOS developer documentation available on the Apple Developer website or use the man pages (e.g., man kextunload).