Linux – How to minimize a Linux server

linux

I'm in the process of building a minimal linux boot image based on Ubuntu.

I started by using debootstrap and then installing the things I absolutely needed.

What general approach can I take to reduce this 3GB+ linux installation down to
something much much smaller suitable for pxe booting?

What things does debootstrap install that I can look at removing?

For example, there seems to be a lot of stuff in /usr/share
What can I safely remove?

Best Answer

See this document for ReducingDiskFootprint.

It includes instructions about how to disable apt caches, have any package installations skip installing the documentation or locales that don't apply to your system. It suggests how you can modify log rotation setups to minimize log storage.

My dpkg config file for small storage system looks like this. /etc/dpkg/dpkg.cfg.d/01_smalldisk.

# block documentation
path-exclude /usr/share/doc/*
# keep copyright files for legal reasons
path-include /usr/share/doc/*/copyright
path-exclude /usr/share/man/*
path-exclude /usr/share/groff/*
path-exclude /usr/share/info/*
# lintian stuff is small, but really unnecessary
path-exclude /usr/share/lintian/*
path-exclude /usr/share/linda/*
# block non-us locales
path-exclude /usr/share/locale/*
path-include /usr/share/locale/en*

Obviously you need to be very careful about the package you select. Avoid those huge meta-packages that include tons of crap. You may need to consider using equivs to make empty packages in some cases where a dependency is set, but you don't need the functionality the dependency makes possible.