Monday, April 04, 2005

Cleaning up Solaris with removef

On Solaris, you can manage packages with the pkgadd and pkgrm commands. Those operate at the level of packages. What if you want to work at a finer level of granularity?

The removef command allows you to delete files, rather than packages.

So, for example, I want to remove the (very broken) copy of cc in /usr/ucb. One possibility is to remove the package (SUNWscpu) that contains it, but that removes the whole of /usr/ucb which could stop a lot of scripts working and removes some useful commands as well.

So, how do we remove /usr/ucb/cc cleanly?

If we look in /var/sadm/install/contents we can see that it's only used by the SUNWscpu package:

# grep /usr/ucb/cc /var/sadm/install/contents
/usr/ucb/cc f none 0555 root bin 3487 14483 1106351583 SUNWscpu

This means that we don't have to worry about dependencies, or other packages. So, we tell Solaris that we want to remove the file:

# removef SUNWscpu /usr/ucb/cc
/usr/ucb/cc

It prints out the names of those files you can remove. (If the file were also part of another package, you wouldn't be able to delete it.) This doesn't do the delete for you, it just marks it in the contents file:

# grep /usr/ucb/cc /var/sadm/install/contents
/usr/ucb/cc f none 0555 root bin 3487 14483 1106351583 -SUNWscpu

OK, so we can go and delete it for real:

# rm /usr/ucb/cc

And then we have to get Solaris to clean up the install database:

# removef -f SUNWscpu

And, yes, it's no longer listed:

# grep /usr/ucb/cc /var/sadm/install/contents

Alongside /usr/ucb/cc, it's an excellent idea to also eradicate /usr/ucb/lint and /usr/ucb/ld (and pkgrm the SUNWsrh and SUNWsra packages).

Note that, while useful, this technique isn't safe against patches, updates, and upgrades. They'll cheerfully put a copy back for you.

1 comment:

Anonymous said...

Thanks , dude.
Your masterpiece is so helpful!
Thanks and best regards

sillness lee