Ubuntu – How to convert existing Ubuntu install to minimal


I'm trying to convert an existing Ubuntu installation to a minimal config so it can run off of a 2 GB SD card (or even smaller).
Right now, the current hardware (a Pi like board) needs a custom 16.04 build to support network and other on-board devices and takes up 4+ GB of space.

So the question is how to remove most packages (e.g. terminal, network, Wi-Fi and other board-specific drivers) to make it really small and lightweight? Are there any guides or recommendations on how to make it safe?

I know I can do something like this to identify and remove optional packages:

dpkg-query -Wf '${Package;-40}${Priority}\n' | awk '$2 ~ /optional|extra/ {print $2,"\t", $1}'

But what else can be safely removed?

Best Answer

If you are willing to do some manual work, this may help:

The installation image for ubuntu server is about 800M, and it has fairly minimal installation options:

enter image description here

With ubuntu server 16.04 if you choose only openssh and standard system utilities the resulting system takes about 1.4Gb of space.

You can then try setting up a VM with a minimal installation of the same ubuntu version that your "custom ubuntu" is using. Then and export the list of all the installed packages of this VM, and compare with those of your target system using the command dpkg --get-selections.

You will then be able to identify packages that are not essential (you will need to be careful about not removing the custom drivers that you are trying so hard to preserve).


Restoring all data and dependencies from dpkg --set-selections '*'

How do I replicate installed package selections from one Debian system to another?

How do I transfer installed packages and settings from one distro to another?