Freeing Up Disk Space

Introduction
In Linux and Gentoo both there are ways to reduce disk space that doesn't break the system and can help low end or full systems get some needed space, such as: There are also some additional tips in other places on this wiki on how to do such things. As you come across them, please copy the snippets over here! :-D
 * Portage garbage
 * Incomplete merges
 * Multiple versions of the same software
 * Temporary files

Read through this guide once, digest the information, then head over to the system, guide in hand or on screen, and get the work done. Blindly removing packages from the system could have a disastrous effect on your computer's health.

Required tools
Gentoolkit includes two useful programs – euse and equery – which have excellent documentation in their man pages:

Be sure it is installed, or install it:

Eix: Optional but very handy, eix builds an index so that searches through portage are considerably quicker.

Updating your system
Should you still have some free space to proceed a system update, you are encouraged to do so before any maintenance:
 * Eix users:
 * Others:

Bring your system up to date:

Fix any binaries that may be pointing to shared libraries that don't exist anymore:

Compile Options: CFLAGS in
For the average desktop user it really makes no sense to your system. In fact, it may make it slower. Using or  is much more effective on a desktop system and can shave off more than 30% of the size. This is because larger binaries (like the HUGE ones produced by -O3) take longer to load, and occupy more RAM.

To harness this newfound speed and size reduction you'd need to. Note that causes portage to have temporary memory loss – remembering all of the packages you want installed, but not rememebering that any of them are installed. Also note that it could literally take 2 or 3 days and make your system quite a bit bigger before it makes it smaller.

Compile Options: USE Flags
Use flags can be set in three places. The default flags are set by your profile (refer to the Handbook). Then, you can tweak them in, thus deviating from your profile. Then again, for a specific ebuild, you can tweak them in. This file might not exist if you haven’t used it. In this section, do not care of.

Finding information about a use flag
Use the command to find more information. Run which will list every known flag along with its description. Look for the first character inside the square brackets. If you have a + (plus) then it is on and if you have a - (minus) then it is off.

You can also lookup individual flags. For example, if you have arts enabled and you don't know what it is

Updating global use flags
Note|You can change the global USE Flags by:
 * editing
 * using . For example to disable, run To enable , run

Gnome only users (and, by extension, KDE only users)
If you're using GNOME exclusively, then you don't need things like, so remove them from your USE Flags or add them preceded by a minus signs. This will remove extra bulk from applications that have support for both KDE and GNOME so that only the one is supported.

Taking advantage of the new use flags
Once you've done that and you are fairly confident about your settings, proceed to recompile.

To take advantage of your new USE Flags you'd need to Note that causes portage re-emerge any package that were previously compiled with a different set of USE Flags than your current ones. Also note that it could take several hours and download several new packages.

Do Not Compile
Compiling generates a lot of garbage in a lot of places. If you're using Gentoo because of portage but would rather not compile, don't feel ashamed, use. Check out the TIP Using PORTAGE BINHOST.

Removing Temporary Files
Empty the following directories:


 * Some running programs may get confused if you do this, for example the X window system.


 * Especially . The temporary directories in which packages are compiled from source during an emerge. Whenever an emerge fails or is interrupted, it often leaves huge directories here.


 * or : If you use Xfce or any other freedesktop.org compliant program. Trashed files go to the latter instead of the former.


 * The cache of source code tarballs that have been downloaded over the Internet. A smart way to clean this directory is described in the next section.

Removing Ancient Distfiles and Binaries
After using Gentoo for a long time, you accumulate a lot of obsolete binaries and/or distfiles. Some of these are obvious candidates for removal (Xorg, OpenOffice) simply because they are large. But many may not be. Gentoolkit has a recent tool, eclean, that can remove all of these for you. Simply run:

Or alternatively:

Note that eclean-dist has a "destructive" option, which clears out all unused distfiles. This can save far more space, but is slightly more dangerous in that you might have to download files again if there is a downgrade of a package (either by your choice or by developers').

Removing Packages
This is the simplest way to remove things from your system and slim down your install. Here, you just remove packages that you don't use anymore. This frees up space, and in the case of libraries, reduces future bloat by making sure nothing links against them.

Have a quick look using eix
First, remember it’s portage’s job to care about dependencies. You only care about what you want installed, that is what is written in your file. It’s there you’ll find the packages you installed a long time ago and even don’t remember what it is. IF you want to take a deeper look, zap this section.

Show me the world

This shows you what you decided to install. Aside, as root, when you want to remove a package, do:

If you went wrong, you can record again a package in the world file with.

Once you’ve cleaned-up the list, you can remove all uncesseray packages (the one you selected and no more necessary dependencies) with:

.

As usual, repair what might be broken with

Slotted installations You may also want to take a look at packages which are installed several time.

Have a thorough look
One way to obtain a list of everything installed is to look at the output of "emerge -ep", which can be very unorganized and massive and may not work anymore. So we're not going to do that. Instead, we're going to browse through portage's list of installed packages in order to maintain our sanity. Navigate to the directory /var/db/pkg. This directory contains an organized list of everything installed in the [package category]/[package-name]-[package-version] format.

Simply look through the package category names and see if there is a program you use or not. The more you know about your system, the easier this is, because you know what you need, and what you don't. Make sure that you know what you are removing. Be careful when removing libraries, as you can damage your system in doing so (libraries typically have "lib" in the package name or package category).

TIP: You can use the q command to find out more about packages. For example you can find out which packages own a file or directory using qfile file_or_directory. Use emerge -pv portage-utils for these utilities.

qfile /usr/share/devhelp

You can also easily find out how big installed packages are using qsize package_name:

qsize gtkmm

You can then find out which packages depend on this one using equery depends package_name

equery depends gtkmm

You can find out about the package slowly using emerge --search package or quickly using eix package

eix gtkmm

If you wish to see the list of installed packages sorted in ascending order by the amount of space they take:

For example, I look at my x11-wm folder, and I see that I've managed to install metacity, fvwm, blackbox, openbox, and ratpoison (I like to try stuff out). I know metacity is part of gnome, which I use, and I like fvwm, which I also use, but I decide the others can go. So as root, I simply emerge -C x11-wm/blackbox x11-wm/openbox x11-wm/ratpoison Removing old versions of software

Carefully examine the output of emerge --prune --pretend and then selectively remove packages. Removing dependencies of software no longer installed

It is important to note that I cannot advise doing this on a critical production machine. If you've read the whole article, or done it before, you'll know why. The first step is to emerge --depclean -p. This will create a list of programs that are possibly no longer needed.

Now the tricky part is this: sometimes packages wont be kind enough to ask us if we want features, and will auto-detect them at compile time. So even if we've said we don't want something...say oss... to be enabled, some programs (like wine) will decide to build support for it anyway when you merge them if you just happen to have the oss libraries installed. This creates problems because there is no way that portage can know about this.

Fix What You Just Broke
Run revdep-rebuild --pretend to list any packages which need re-emerging. You'll need to emerge --ask gentoolkit if you haven't already. If revdep-rebuild insists on continually re-emerging any binary packages you have installed, try:

to open the file in your favorite editor, and remove all the "/opt"s from the SEARCH_DIRS line.

For good measure, run:

to give you a list of any software that was removed that you still need.

Purge Unused Locales
Another way to reduce disk space usage is to remove unused locales. See the Official localization guide section on "Generating locales".

Remove Foreign Language Manual Pages
It is possible to remove the foreign man pages as follows:

A nicer way to accomplish this is with localepurge. Set which locales you want to keep in. For example:

Then comment out the #NEEDSCONFIGFIRST line and run.

Remove Unused Documentation Files
Another good thing is to remove unwanted documentation (AUTHORS.txt, CHANGELOG.txt) which is located in /usr/share/doc as it takes up a fairly huge amount of disk space.

If you only want to remove certain files that are probably not needed by you like the changelogs or author files:

And for the future: If you are sure you won't need doc anymore (e.g. because you have this great gentoo-wiki ;D ) you can add "nodoc" option to FEATURES in make.conf. This will prevent installing any doc in your system.

Removing foreign language scrollkeeper files
With appropriate privileges, it is possible to remove the foreign language scrollkeeper files as follows:

Remove Unnecessary Kernel Sources
Take a look in. There are hundreds of MiBs taken up by each unnecessary Kernel source tree:

du -sh /usr/src/*

You only need to keep a kernel source tree around if you think you might need to recompile it. For an old reliable kernel that you are keeping around as a fall back, you don't need the sources, and if by some chance you do need to recompile it, you can re-emerge it.

You will want to keep the most recent kernel source tree, however, as there are several programs that compile against it. Additionally, you will want to hang onto the from your most recent kernel build as it will save you some time and hassle.

To see which kernel source tree you are currently using:

ls -shl /usr/src/ As you can see, is linked to. That's the kernel source tree you want to keep. The others can be unmerged and deleted as there are some files that may have been compiled by you and not by Emerge. From the directory names, you can see that the source trees came from the gentoo-sources packages. Multiple packages can be unmerged using a space separated list:

Control Portage Space Usage
If this isn't your only gentoo box around, consider keeping portage on a NFS server. Just keep the server in sync and don't bother keeping the client metadata cache up to date, you will only sacrifice speed.

It is also possible to keep your portage tree in compressed form, making it take up 40 MB instead of closer to 400 MB. See the squashed portage tree article for details on how to do this.

Sprzątanie dysku