Sunday, April 27, 2008

All About Kext


What is KEXT?
KEXT stands for Kernel Extension, this means that whatever needs to run in the kernel (OS core) environment can be written as extension and then loaded, even after the OSX has finished loading, this mostly answer the needs for hardware drivers.

Where are kext located?
kext are not files rather a folder (disguised as a file),

Leopard holds kext files/folders in the /System/Library/Extensions folder,
at boot time the relevant kext are uploaded from Extensions.mkext this is a cache folder that contains kext related to the installed hardware,

you can delete it, if Leopard can't find it, it will create it again,

you can also state to rebuild it from darwin prompt at boot time using the switch -f see this post for further information.

How to Load and UnLoad Kext?
Kext can be loaded and unloaded during runtime using the kextload and kextunload command lines.

in order to load kext, from terminal write:
sudo kextload kextName (where kextName stands for the kext name you want to load)
enter your password and press enter
the system should reply with a success or fail message.
see the manual page for this command

in order to unload kext, from terminal write:
sudo kextunload kextName (where kextName stands for the kext name you want to unload)
enter your password and press enter
the system should reply with a success or fail message.
see the manual page for this command

you can also check the load status of your kext using kextstat, from terminal write:
sudo kextstat
the system will display a list of loaded kext and details on it
see the manual page for this command

How to Install a new Kext?
cd /System/Library/Extensions
mv KextName.kext KextName.old (where kextName stands for the kext you want to replace)this will rename the kext and this way back it up, it is highly recommended, warmly advised, very important to follow this step, it saved my OS many times

cd /path/to/new/kext (put your downloaded kext path here)
cp -R KextName.kext /System/Library/Extensions

next you need to fix permissions so the kext can be executed by OS user (root/system)
cd /System/Library/Extensions
chmod -R 755 KextName.kext
chown -R 0:0 KextName.kext (this will set the ownership on files to system user (root))
rm /System/Library/Extensions.mkext (this will reset all kext caching done by OSX)

KextHelper


there is an easier method (not appropriate for all kext installs but works for 99% of them),
it is a little utility named KextHelper and can be downloaded here.

kext helper is a window that allow a drag and drop interface to install quickly a kext (including fix permissions).

in order to install new kext using KextHelper follow these steps:
1. launch KextHelper
2. drag and drop to the center of the application the kext you wish to install
3. enter your password in the bottom textfield
4. press the "Easy Install" button
5. wait for success reply
6. reboot

there are also advanced features such as backup, run script, etc.
if you are a developer you might want to read apple "Kernel Extension Programming"

Enjoy.

No comments:

 
the menu is from: Milonic DHTML menus