Reducing Debian's footprintPublished: 2014-08-13
This procedure is best started right after the installation. If you know how to tweak Debian's installer so dpkg already skips locales etc., even better, then you can apply this during installation. Either way, the sooner you do it, the better.
Removing redundant packages
You need to determine yourself what you do and do not need. No system is identical. Keep an eye on the dependencies packages want to remove. If you're not sure about what a package provides or does, check it:
$ dpkg -l systemd-sysv
or, if you want more elaborate output, like dependencies etc.:
$ apt-cache showpkg systemd-sysv
To see what packages depend on the package you want to remove, run
$ apt-cache rdepends tmux
Removing orphaned packages
After you cleared the packages you don't need, there's a chance there will be some leftover libraries etc. Use deborphan to track these down and remove them:
$ sudo aptitude purge $(deborphan)
Preventing apt from installing additional packages
This is as easy as an extra configuration snippet in
# echo 'APT::Install-Recommends "0" ; APT::Install-Suggests "0" ;' > /etc/apt/apt.conf.d/01footprint
Localisation files take up a surprising amount of space on your system. You can tell dpkg to keep only the ones you need (or none at all, if you prefer English). You can make this permanent by reconfiguring dpkg. In my case, all I want is English - some stuff might not have been translated - and Dutch.
Redefine this as needed.
$ cat /etc/dpkg/dpkg.cfg.d/excludes path-exclude=/usr/share/locale/* path-include=/usr/share/locale/en/* path-include=/usr/share/locale/nl/* path-include=/usr/share/locale/nl_BE/* path-include=/usr/share/locale/locale.alias path-exclude=/usr/share/man/* path-include=/usr/share/man/man[1-9]/* path-include=/usr/share/man/en/* path-include=/usr/share/man/nl/* path-include=/usr/share/man/nl_BE/*
The dpkg tweaks only take effect upon upgrades or installation of new packages. Either you reinstall everything by calling
sudo aptitude reinstall (I do not recommend this if you wiped your package cache already) or you manually
rm -rf the concerned directories. This can save multiple tens (or hundreds!) of MiB, on embedded systems this can make quite the difference. If you're looking for more ways to slim down your installation, take a look at the Debian Wiki. You can achieve the same by using localepurge. For its first run, tell it not to rely on dpkg, since you want it to remove redundant locales and manpages.
$ sudo localepurge
After that is done, you can run
dpkg-reconfigure localepurge and this time tell it to rely on dpkg, so future installations should filter out the stuff you don't need. However, this does not seem to work reliably, so for me, localepurge is nice as a one-time tool (after installation, before you configure dpkg's exclusions).
Lastly, clean out your cache:
$ sudo apt-get clean