Preparing Lion to Boot Quickly: Create an Extensions.mkext

EDIT 10/18/2011:  This doesn’t seem to be working with 10.7.2 (causes a kernel panic on boot).  Also tried adding <UseKernelCache><Yes> to org.chameleon.boot.plist (Chameleon 2.1 build 1627) and got a different KP.  More updates to follow.

Update: Fix is below in red.

– – –

I’m done with the real-life Lion metaphors after this.  Promise.  If only Apple would quit infusing interface metaphors into every other application it releases.

In other news, my Lion hackintosh never seems quite ready to boot.

It's like the folks at Apple had never even heard Scar's famous song. Isn't Steve Jobs on Disney's Board of Directors?

The Problem

Lion boots sloooooooooooooooowly.  Verbose output from the boot log indicates that Lion is processing every single kernel extension prior to booting (as if the -f flag was used), rather than caching the kernel extensions in a .mkext kernel extension boot cache.  TL;DR: Lion isn’t caching kernel extensions.

The Solution

It’s simple, really: force Lion to rebuild the kextcache and use it to boot.  The solution thread on InsanelyMac.com (one of many like it) contains a good explanation of what’s actually happening, but here’s the code to build the cache (Edit: to make OS X also build a cache for your /Extra/Extensions folder, add “/Extra/Extensions” to the code below):


sudo kextcache -v 1 -a i386 -a x86_64 -m /System/Library/Caches/com.apple.kext.caches/Startup/Extensions.mkext /System/Library/Extensions

This *should* accomplish the same thing as setting the “kernelcache = yes” flag in com.apple.boot.plist.  What does setting this flag do? tonymacx86.com has a very straightforward answer here.  Please note that many a contributor to the InsanelyMac.com forum has reported kernel panics resulting from using this flag, while others have reported Lion booting fine (and quickly) but ignoring the kernel extensions placed in the /Extra/Extensions directory.

I have ONLY created the Extensions.mkext using the terminal code above; I HAVE NOT added the “kernelcache = yes” flag to com.apple.boot.plist.

The result?  My machine now boots in seconds instead of minutes.  That simple.

The Big Picture

What confuses me more than the problem itself (the solution is rather trivial) is why Apple decided to not include kernel extension caching automatically in Lion.  OS X can clearly still read the kextcache– so why doesn’t it write one?

I’m not entirely sure, but it may be hackintosh-specific.  I’m in the process of upgrading my brother’s MacBook Pro at the moment, so I will boot it with verbose logging and check back with the results.

Until then, enjoy the weekend!  And don’t spend your whole weekend playing with your hackintosh… It’s beautiful outside.      🙂

Advertisements

9 Comments Add yours

  1. Hi, is this code right ?
    ==begin==
    sudo kextcache -v 1 -a i386 -a x86_64 -m /System/Library/Caches/com.apple.kext.caches/Startup/Extensions.mkext /System/Library/Extensions
    ==end==

    1. yeah it’s work! thank you so much 🙂

    2. Chris says:

      I believe so, yes.

  2. ganjar says:

    how to undo those commands in terminal?

    1. Chris says:

      You can just navigate to the directory and delete the Extensions.mkext file. Otherwise:

      sudo rm -rf /System/Library/Caches/com.apple.kext.caches/Startup/Extensions.mkext 
      
  3. zeraien says:

    I found a pretty nice way to make things faster without caching:

    Edit your Boot.init and add the property GUI = No, this will not display the fancy gui at boot time, but will nonetheless boot in 5 seconds instead of the usual 60.
    It seems the chameleon gui is very slow…

    You can try it without editing the boot file by simply pressing TAB when the boot loader pops up (at least i think it was tab).

    1. Persephon says:

      I recommend trying this. It worked for me when nothing else was really helping boot times without breaking my boot.

  4. songuke says:

    mkext seems to be a legacy format now (see man kextcache). OS X Lion seems to use kernelcache instead. This post may help:
    http://www.insanelymac.com/forum/index.php?showtopic=259801&view=findpost&p=1773669

    For me I have kernelcache in /S/L/Caches/com.apple.kext.caches/Startup and then set UseKernelCache key to Yes in /Extra/org.chameleon.Boot.plist. Lion now loads the kext cache at boot, which is fast.

  5. Son says:

    mkext seems to be a legacy format now (see man kextcache). OS X Lion seems to use kernelcache instead. This post may help:
    http://www.insanelymac.com/forum/index.php?showtopic=259801&view=findpost&p=1773669

    For me I have kernelcache in /S/L/Caches/com.apple.kext.caches/Startup and then set UseKernelCache key to Yes in /Extra/org.chameleon.Boot.plist. Lion now loads the kext cache at boot, which is fast.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s