BSD DevCenter
oreilly.comSafari Books Online.Conferences.


FreeBSD Basics Cleaning and Customizing Your Ports

by Dru Lavigne

We've spent the last few articles discussing how to use the built-in ports utilities and portupgrade to keep your installed applications up to date. Today, I'd like to finish the series by demonstrating how to keep your system clean of uninstalled applications and how to customize your ports tree with pkgtools.conf.

Anyone who installs or uninstalls software soon realizes what a messy business this can be. Installations can clutter the hard drive with temporary files, unread READMEs, and unnoticed directories. Sometimes a program uninstall will leave behind souvenirs: files that are no longer required but still take up disk space. Worse, an install might overwrite, or an uninstall might remove, libraries that were being used by other applications. These frustrations seemingly transcend operating-system boundaries and often result in a user reinstalling the operating system from scratch just to start over with a clean slate.

Keeping Your Ports Clean

Fortunately, there are tools available to help you intelligently manage software installation and keep your FreeBSD system happily humming along for years. For example, when you install a port, remember to include the word clean:

% make install clean

This will tell make to clean out its working directory once the port has successfully installed. If you forget to clean, you'll soon find that working directories can consume a lot of disk space.

Depending upon your needs and the amount of disk space you have to work with, you might consider using this command instead:

% make install distclean

When you install a port, the required source files are downloaded from the Internet and copied into /usr/ports/distfiles. If you ever want to reinstall that port, the necessary source files are already on disk. distclean tells make to erase those files once the port is successfully installed. When deciding whether or not to use distclean, balance your available disk space with the speed and reliability of your Internet connection. Also, for license reasons, some ports require you to fetch the source manually and save it to /usr/ports/distfiles. I find it more convenient to save those files on disk, so I don't use distclean when building those ports.

The Complete FreeBSD

Related Reading

The Complete FreeBSD
Documentation from the Source
By Greg Lehey

Those two switches can go a long way in conserving disk space. However, if you've installed portupgrade, check out the portsclean utility that came with it. As the name suggests, this utility is designed to clean out what may have been left behind from using the ports collection.

I have a system that I use to test applications, meaning I've used it to install and uninstall hundreds of ports. I usually remember to use clean and sometimes remember to use distclean. Let's take a look at its current condition and see if portsclean will make a difference. First, I'll check how much disk space is free on /usr:

% df /usr
Filesystem  1K-blocks    Used   Avail Capacity  Mounted on
/dev/ad0s1f  13360662 6189648 6102162    50%    /usr

Next, I'll look for disk hogs in /usr/ports. This command will show the disk usage, sorted by largest usages first and piped to head so I can see the top ten disk wasters:

% du /usr/ports |sort -rn|head
3110862	/usr/ports
1848846	/usr/ports/distfiles
822278	/usr/ports/editors
816710	/usr/ports/editors/openoffice-devel
816592	/usr/ports/editors/openoffice-devel/work
604784	/usr/ports/editors/openoffice-devel/work/oo_644_src
362536	/usr/ports/distfiles/KDE
295404  /usr/ports/distfiles/openoffice
211718  /usr/ports/editors/openoffice-devel/work/mozilla
211654  /usr/ports/editors/openoffice-devel/work/mozilla/work

Hmmm. Looks like I haven't used distclean as much as I thought, and I still have working files left behind from the OpenOffice build.

I'll start by cleaning out all of those missed working directories:

% portsclean -C

Did it make a difference in disk space?

% df /usr
Filesystem  1K-blocks    Used   Avail Capacity  Mounted on
/dev/ad0s1f  13360662 5160664 7131146    42%    /usr

Oh yeah. I just increased my disk capacity by 8%. Remember, cleaning out working directories is a good thing, as they are only used during the build process. They aren't needed once the port successfully installs.

The next portsclean switch is pretty cool. Let's say you've decided to keep /usr/ports/distfiles intact. For the past few years. And you've uninstalled a few applications along the way, and upgraded others to the latest versions. There's a very good chance that some outdated and unneeded source files are collecting dust in /usr/ports/distfiles. To find and remove those relics:

% portsclean -DD
Detecting unreferenced distfiles...
<output varies>

and to check out the impact:

% df /usr
Filesystem  1K-blocks    Used   Avail Capacity  Mounted on
/dev/ad0s1f  13360662 4092490 8199320    33%    /usr

Whoa. Another 9% in disk savings. I should also see a major difference in the du command:

% du /usr/ports | sort -rn | head
1011998	/usr/ports
780760	/usr/ports/distfiles
161724	/usr/ports/distfiles/openoffice
137010	/usr/ports/distfiles/staroffice52
122648	/usr/ports/distfiles/KDE
55478	/usr/ports/distfiles/xc
24936	/usr/ports/distfiles/rpm
20536	/usr/ports/devel
18194	/usr/ports/distfiles/AbiWord
17704	/usr/ports/distfiles/ghostscript

Notice that while disk usage has decreased considerably, my system still holds the distfiles referenced by my currently installed applications.

Pages: 1, 2

Next Pagearrow

Sponsored by: