How to safely clean out /lib, /usr/lib?

Garance A Drosihn drosih at
Mon Oct 11 10:56:01 PDT 2004

At 11:23 AM -0500 10/11/04, Kirk Strauser wrote:
>On Monday 11 October 2004 11:01, Matthew Dillon wrote:
>  >     (this assumes you don't use 'tar' or 'cp' to backup your
>  > system, which would skew the results, and that you haven't
>  > already blown it by doing something right aweful in /usr/lib
>  > to open and read all the files.     :-).
>Unfortunately, I do in fact use tar (via Amanda) for backups.  :-/

I assume you're running 5.x or 6.x (since this is the mailing
list for freebsd-current).

One of the really useful features in 5.x is the ability to take
snapshots of a disk partition.  So, you could take a snapshot
of / and /usr, mount those snapshots read-only, and then do
backups of the files as they appear in the snapshots.  I *think*
that won't update the last-reference times on any of the files,
but you might want to check that to be sure.

Secondly, if you have a snapshot, you could leave the snapshot
mounted and then remove the original lib files (once you decide
which ones are safe to remove!).  If the removal of some file
does cause a problem, you can then copy the file back from the
matching snapshot.  This allows you to fix the problem without
having to reference your backup tapes.

Two things to remember if you try this:  Mount the snapshots
*before* you start removing lib files, and remember that /rescue
has statically-linked versions of several key commands in case
you mistakenly remove a critical lib file.

>Now, I just did an installworld and "portupgrade -fa" yesterday.
>Under these particular circumstances, does it seem reasonably
>safe to trust libchk's idea of what's referenced and what isn't?

At least for me, on my systems, that would not be completely safe.

While you have rebuilt all your ports, you have not necessarily
*run* all of them.  I think that leaves open the possibility of
some programs which will reference libraries when run, but which
did not need to open those libraries during the build process.
(they may check that the library exists, but not actually open
the library to read anything).  I am not sure about that, though.

But in my case, I also have plenty of other programs on the system
which did not come from the ports collection.  Rebuilding all of
my installed ports will not do anything with those other programs.
And since those programs were not built via ports, it is much more
likely that they have not been rebuilt in a long time, and are
therefore referencing some ancient libraries.

Garance Alistair Drosehn            =   gad at
Senior Systems Programmer           or  gad at
Rensselaer Polytechnic Institute    or  drosih at

More information about the freebsd-current mailing list