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?

  • 1
    That's very difficult to do, because apt won't autoremove orphaned dependecies that were part of the initial install. It's a apt-mark hack intended to prevent users from accidentally removing big chinks of their system. It's much easier to build your system up from the minimal image. – user535733 Dec 18 '17 at 23:15
  • 2
    Wouldn't it be easier and cleaner to just do a fresh minimal install? What speaks against that? Please edit and clarify. – dessert Dec 18 '17 at 23:15
  • yeah, it seems like I would have to go with minimal image supplied by board manufacturer. I'm kinda scared to go with the official ubuntu minimal image because of all sort of custom drivers required by this board. – Alex D Dec 19 '17 at 12:04
  • @AlexD i'm in exactly the same situation as you with a custom image for a SBC. Did you find a good solution to your problem? – Hilikus Oct 5 '18 at 3:36
  • yes, I just did alter standard install manually and made an image I can reuse. basic commands to bring the size down are sudo apt-get remove x11-common midori lxde python3 python3-minimal then sudo find / -type f -size +10000k -exec ls -lh {} \; | awk '{ print $NF ": " $5 }' and remove unused cache, etc. then remove all dev libs from the system by typing in sudo apt-get remove `sudo dpkg --get-selections | grep "\-dev" | sed s/install//. There's more steps involved if you wanna get rid of display manager and/or whole x11 system.... right now my 16.04 image is about 160mb – Alex D Oct 5 '18 at 23:06

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?

  • 1
    well, the problem is that I can't find installation image for this board. All the images I've seen so far were pre-installed OS images. Would have done minimal install if I had this option available – Alex D Dec 19 '17 at 12:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.