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

2 minute read

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

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

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:

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:

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