All Linux HowTo's Security HowTo's

Freeing Space on Gentoo

Share This:

Gentoo machines (and Linux boxes in general) have a very nice habit of living for a long time and needing constant maintenance, while this is great it also means that they can go for long periods of time without a clean up and can start chewing up space on your disks. Luckily there are some simple steps to follow to get your server clean and give you your disk space back.

If you are using Gentoo then continue on reading if you are using RHEL or Ubuntu it would be best to go and read the article written by Andrew here as the process differs somewhat.

First thing to do is get rid of all the old things in your distfiles and packages directories. If you have the gentoolkit install (You should it is a great set of tools) then you can run the following commands.

#This removes old outdated packages and sources and will not touch the ones that are in use
/usr/bin/eclean distfiles ; /usr/bin/eclean packages

Depending on how regularly you run eclean you can often free up a few GB straight away, for example on our test system we opened up 3GB just by running the above commands.

Another directory that can grow quite large is /var/tmp/portage, if you are building a large package or multiple packages and they fail for some reason they will not be deleted automatically, they will sit in the /var/tmp directory.

rm -rf /var/tmp/portage

For our test system that was another 2MB cleaned.

User cache files are another thing that can take up space on a system, for example if a user views a folder full of images a .thumbnails folder would be created to store all of the thumbnails for the images.

Please be careful with the below command, just because it works on our test system does not mean that it will on yours, check your data first. Run the below command, if that only returns files you want to delete the uncomment the other command below.

find /home -name ".thumbnails" -exec echo "Found File:" {} \;
#Only uncomment if you are happy with the output of the first command
#find /home -name ".thumbnails" -exec rm -rf {} \;

Depending on how many users you have the gain from this can be pretty significant, on our test system it only cleared about 300k but on one of our production systems the above command cleaned out about 1GB of just thumbnails.

Another program that is good to run on a long living Gentoo box is eclean-kernel, chances are that you have been through a few kernel upgrades in the time you have had your box running and have not removed the old kernels from the system. To install eclean-kernel just follow the steps below

printf "#eclean-kernel requirements\n=dev-python/pymountboot-0.2.2 ~amd64\n=app-admin/eclean-kernel-0.4.1 ~amd64\n" >> /etc/portage/package.keywords
emerge --ask -jv app-admin/eclean-kernel
#Now just run
/usr/bin/eclean-kernel --ask

After running eclean-kernel you will either be prompted to get rid of old kernels or you will be told that there are no outdated kernels. You can also decide to keep around a number of latest kernels so that you don’t have to live on the bleeding edge if you don’t want to. Just issue the eclean-kernel command with the -n switch and tell it what number of kernels you would like to keep as in the example below

/usr/bin/eclean-kernel -n 2

One of the final things that I would suggest in order to get some of your disk space back is to do an audit of what is sitting in /root, depending on how many sysadmins are using your system this has the potential to run out of control for sometime when most of the files in there could have been deleted if people cleaned up after themselves.

du -ch /root

Lastly, go have a read of Andrew’s article as he covers things like local backups, user home directories etc that are not specific to any distro.

Thanks for reading, good luck liberating your storage space

Leave a Reply

Your email address will not be published. Required fields are marked *