In a previous blog post, I had mentioned that I had run out of space on the out of the box 4 GB SD card with the Raspbian OS. As it turned out, I found the Raspbian had a lot of pseudo-bloat. The out of the box system comes with components meant alike to be used for software development and as a GUI desktop. I wanted neither of these, as I was running it as a pure WordPress stack server. This meant there was a lot of scope for minimizing Raspbian.
If you know how packages in Linux are organized, you will know that there are a lot of inter-dependencies between them. Even the advanced user would soon get lost in a maze of dependencies. The trick then is to get to the smallest set of packages on which the largest set of installed applications depend. You get rid of those packages then everything depending on them will go away too in a sort of a “cannon-ball tied to the end of a string pushed into the ocean” kind of way.
Taking a look at the list of pre-installed components, among language tools I had only PHP installed, so nothing there to remove. The challenge was X11, that on its own has a ton of packages and then all the X-apps that come installed with it. However, all of them ultimately depend on one package, and that is the libx11
. Removing it then is a piece of cake:
# apt-get remove --auto-remove --purge libx11-.*
This will take a long time. It took about 20 minutes on my Raspberry Pi 2. After that, I found some forum threads asking me to install and run a package called “deborphan
”. This tool finds orphaned files and packages (that have bad dependency information or got left behind by previous uninstalls) and removes them. However, I decided to skip this, and use apt-get
’s own command:
# apt-get autoremove
This command did nothing on my system, indicating it was clean as a whistle.
The next task is to re-role the Raspbian to a non-desktop role. The Debian OS on which the Raspbian is based comes with a tool called “tasksel
” to do this for you. To run it:
# tasksel --list-tasks
It will take some time to figure out what roles are installed already. After about nearly a minute, it printed out a bunch of items. Of these, I needed to remove only the “desktop
” role. So issue the next command:
# tasksel remove desktop
If all the packages were already removed with the apt-get
commands above, this should finish pretty quickly and it did. Although the system did not ask me to, I went ahead and rebooted the Raspberry Pi 2.
From the 4GB plus system I had earlier, the newly minimized system now occupied under 1 GB.