Clear disk space on Gentoo

Freeing up disk space on Gentoo can be complex. Read this wiki article for an introduction: Knowledge Base:Freeing disk space - Gentoo Wiki.

Here’s what I do…

Clean portage files

Check usage:

me@pc ~ $ sudo du -hs /var/tmp/portage
0	/var/tmp/portage
me@pc ~ $ sudo du -hs /usr/portage/distfiles/
1.7G	/usr/portage/distfiles/
me@pc ~ $ sudo du -hs /usr/portage/packages
du: cannot access ‘/usr/portage/packages’: No such file or directory

So I don’t need to delete /var/tmp/portage because it’s empty (though I could, assuming emerge isn’t running), I have a lot of source files and no binary packages.

Temporary files

You can delete /var/tmp/portage if emerge isn’t running.

Source code

The following command removes any source code that does not belong to an available ebuild. It takes ages on my machine (at least 10 minutes).

me@pc ~ $ sudo eclean-dist
 * Building file list for distfiles cleaning...
 * Cleaning distfiles...
 [    6.6 M ] adobe-flash-
 [    6.9 M ] adobe-flash-
 [   44.1 M ] firefox-bin_x86_64-38.6.0.tar.bz2
 [   57.7 M ] Total space from 3 files were freed in the distfiles directory

   The following unavailable installed packages were found

That ‘unavailable installed packages were found’ message means that the listed packages, which you have installed, are no longer available in portage.

Destructive option

You could use the --destructive flag, which would remove any source code that doesn’t belong to your installed packages.

eclean-dist --destructive

This will free up more space but will prevent you from doing a rebuild of a package that is no longer in portage.

Binary packages


Clean dependencies

You may need to clean up your dependencies (AKA depclean) to remove old packages.

Important: Cleaning your dependencies can break your system. Be very careful.


Because the dependency clean will remove packages that could be required by other packages, it’s best to first make sure that your system is up to date:

emerge -avDuN --with-bdeps=y world

This will install/update all packages and their dependencies.


Next, run the depclean with the -a (AKA --ask) flag, so that you can see what packages it plans to remove:

me@pc ~ $ sudo emerge -a --depclean

 * Always study the list of packages to be cleaned for any obvious
 * mistakes. Packages that are part of the world set will always
 * be kept.  They can be manually added to this set with
 * `emerge --noreplace <atom>`.  Packages that are listed in
 * package.provided (see portage(5)) will be removed by
 * depclean, even if they are part of the world set.
 * As a safety measure, depclean will not remove any packages
 * unless *all* required dependencies have been resolved.  As a
 * consequence of this, it often becomes necessary to run
 * `emerge --update --newuse --deep @world` prior to depclean.

Calculating dependencies... done!
>>> Calculating removal order...

>>> These are the packages that would be unmerged:

    selected: 0.1.3
   protected: none
     omitted: none
>>> 'Selected' packages are slated for removal.
>>> 'Protected' and 'omitted' packages will not be removed.

Would you like to unmerge these packages? [Yes/No]

Check over the list of packages before you agree to remove them. Make absolutely sure that none of the listed packages are needed for your system to function.

In general, the depclean shouldn’t remove anything important - it won’t remove any packages listed in /var/lib/portage/world nor their dependencies.

Saying that…

  1. To be on the safe side, watch out for linux-headers, glibc, binutils, gcc-config, libtool, gcc, glibc, python or any packages that you use regularly.

  2. The depclean may want to remove old versions of a package that your system is configured to use. Before proceeding, check any important packages that are listed (e.g. gcc, python) and make sure that your system is configured to use one of the versions that is not listed (i.e. a more recent version). See Current gcc removed by depclean for an example of this potential problem.


After the depclean, use revdep-rebuild to check that no dependencies are broken:

revdep-rebuild -i

This won’t pick up everything.

For example, it won’t pick up the removal of your currently selected gcc version (though it shouldn’t remove all versions of gcc, since it’ll be a dependency and it is also probably listed in your /var/lib/portage/world file).

Delete user cache and thumbnails

me@pc ~ $ du -hs .cache
2.1G	.cache
me@pc ~ $ du -hs .thumbnails/
739M	.thumbnails/

Stop as many programs as possible, then delete user cache and thumbnails. They will be automatically recreated when needed.

me@pc ~ $ rm -r .cache
me@pc ~ $ rm -r .thumbnails


Last modified: 27/03/2016 Tags: ,

This website is a personal resource. Nothing here is guaranteed correct or complete, so use at your own risk and try not to delete the Internet. -Stephan

Site Info

Privacy policy

Go to top