Matt Coneybeare

MC

I Accidentally Deleted libSystem.B.dylib, Now What?

| Comments

I was testing the dynamically loaded dependencies of a static ffmpeg binary today, and I saw that libSystem.B.dylib was indeed a dependency.

1
2
3
coneybeare $ otool -L ffmpeg
ffmpeg:
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 159.0.0)

Attempting to be thorough, I decided to test what happened when I ran this binary on a machine that did not have the libSystem.B.dylib library in this exact path.
WARNING: DO NOT TRY THIS AT HOME

1
coneybeare $ sudo mv /usr/lib/libSystem.B.dylib /usr/lib/_libSystem.B.dylib

The library moved and I tried running a command using the ffmpeg binary, when BAM, I got a missing library error. I did some research and found that the libSystem.B.dylib library should exist on any functional OS X install, so I decided to not worry about the error and attempted to move the library back:

1
coneybeare $ sudo mv /usr/lib/_libSystem.B.dylib /usr/lib/libSystem.B.dylib

… Missing Library Error. Then it hit me, sudo, mv and all other bash goodies were dependent on this library and in order to move the library back to its original position, it needed to be loaded. It could not be loaded though because the library was in an unexpected location. Shit.

I tried sshing in to see if I could do something that way, didn’t work. ssh must also depend on the library. I tried a restart in safe mode, but the safe-mode boot must also depend on the library as it spun on the gray load screen for ever. I tried setting up the computer in target mode, but that did not work as well. I tried to open the cd tray to load in my OS X disc and get the terminal but my bluetooth keyboard was not working, probably because of the missing library. I really thought I was fucked here.

At long last I remembered the low level boot disk switcher! I tracked down a USB keyboard and mouse, plugged them in and restarted the computer holding down the Option key. After a short while, I was presented with the Boot Disk selection screen! I tapped the eject button and threw in my Restore disk. After choosing the default language, I went to the title bar and opened up terminal. then I was able to run my command:

1
coneybeare $ mv /Volumes/Macintosh\ HD/usr/lib/_libSystem.B.dylib /Volumes/Macintosh\ HD/usr/lib/libSystem.B.dylib

After a reboot, all was working once again :) Hope this helps anybody else who made the same bonehead mistake that I did.

Comments

My name is Matt Coneybeare, I design and develop for iOS (iPhone, iPad and iPod Touch), Mac OS X and the Web out of New York. In 2008 I started a software company called Urban Apps that has made some pretty popular apps such as Ambiance and Hourly News. My current Stack Overflow reputation is about 27k.

I was a Rockstar a decade ago, but then went back to school and collected a Bachelor's Degree in Computer Science from U.C. Berkeley. Now I am settled down with my beautiful wife Di and our two doggies Hamachi and Foxy. While coding, I walk several miles/day on my Treadmill Desk. When not at my desk, I love exploring New York City as a Yelp Elite, or training for marathons.

Contact information

Name
Matt Coneybeare
Email
Website
Twitter
Instagram
GitHub
LinkedIn
Google+