Squeeze disk space on a Debian system

Do you have your root filesystem on a small SSD? are you working on an embedded system, maybe a Raspberry Pi on a 2 GB SD card? Sooner or later we need to have a look at what is chewing up our space. Here is a quick reference.

Basic maintenance

There is a couple of things to do when we want to free space in a no-brainer way. First, we want to remove those deb packages that get cached every time we do apt-get install.

Also, the system might keep packages that were downloaded as dependencies but are not needed anymore. We can get rid of them with

If we want things tidy, we must know that whenever we apt-get remove  a package, the configuration will be kept in case we want to install it again. In most cases we want to use apt-get purge. To clean those configurations from removed packages, we can use

So far we have not uninstalled anything. If now we want to inspect what packages are consuming the most space, we can type

Entering the danger zone

The next step would be to inspect our filesystem and see where the space is wasted. This is were we start breaking things, so more care is needed, proceed at your own risk!

The most basic way of discovering this from the command line is to use du

If we want a little eye candy, we can install durep

If we find some big file and we want to know what package it belongs to, we can do

, also we quite often ask ourselves what files does a package install. We can list those with

Some other locations can be using up a lot of space as execution byproducts. We might find huge logs in /var/logs , or maybe lots of cached things in /var/cache. It is generally ok to get rid of those.

If we have gotten this far, we can see that much of the space left is used by icons, fonts and locales. We can investigate what icons and fonts we do not need. This will vary from system to system, but generally we will have them at /usr/share/fonts  and /usr/share/icons, maybe ~/.local/share/fonts .

List installed fonts with

We can investigate which one our X server uses looking at $XDG_CONFIG_HOME/fontconfig/fonts.conf , the X server logs or Xorg.conf

The way we installed icons will depend on our setup and the particular desktop environment that we using. Again, see the X server logs.

At this point, the biggest part is taken by locales. A safe and clean way to get rid of unused locales is localepurge .This tool get rid of locales that we do not use, as well as localized packages and man pages.

More exotic stuff

Aside from cleaning up our desktop, we might need to use these basic tools for more advanced purposes where space requirements are really tight.

We might be interested in things like creating really tiny docker containers to test out LAMP systems, or putting together a small chroot to access a full fledged debian system on a non-debian system like OpenWRT or Android.

In those cases we really do not need the kernel, drivers, boot, systemd, bash, man pages, nor many other things so you can literally destroy the distro as long as the libraries and binaries are there, and you have access to apt  and dpkg.

We will do some of these things in the next posts.


25 Useful Basic Commands of APT-GET and APT-CACHE for Package Management

Arch Linux Wiki – Fonts

Humbly sharing things that I find useful [ github | gist ]