Initially, I just did a search on the web and found a few different posts and conversations that dealt with removing the GUI and combined them to get things slimmed down quit a bit. After that, I started listing the installed packages and removing the ones that looked like they would not be needed. (It was at this point I noticed the firmware-ralink package that I could have probably installed on Minibian to get the WiFi adapter working there – maybe next time).
My first stop was a conversation on raspberrypi.stackexchange.com where it was suggested that you could rip out the X window system by the roots by simply removing ''libx11-.*''. That did remove a lot of packages from the system! Other blog posts like this one at Richard's Ramblings added to the list of packages to remove.
Finally, I used the dpkg --get-selections | grep -v deinstall command (thanks askubunut.com!) to list all the remaining packages on the Raspberry Pi and removed all the ones that look like I could do without. There were a few times when I removed too much and had to re-install a package or two, but eventually boiled it down to the following commands to convert a normal GUI Raspbian installation to a lean command-line only version (Be sure you don't have any important files or configuration on your system before doing this, and don't blame me if your mission critical Raspberry Pi application gets lost in the process!).
A word of caution: One of the uninstalled packages took the /etc/network/interfaces file with it, so before stripping all these packages, you should make a copy somewhere else on the device and then restore it before rebooting your system, or you will have no networking available after rebooting!
sudo apt-get remove --auto-remove --purge libx11-.* sudo apt-get remove --purge raspberrypi-artwork triggerhappy shared-mime-info gcc-4\.[0-7].* sudo apt-get remove --purge gdb gdbserver penguinspuzzle samba-common omxplayer sudo apt-get remove --purge alsa-.* build-essential gstreamer1.0-.* lxde-icon-theme sudo apt-get remove --purge desktop-file-utils gnome-themes-standard-data menu menu-xdg sudo apt-get autoremoveAfter all was said and done, I was able to reduce the size of the file system from 2.5GB down to just 800MB. Along with the size savings, there are also fewer programs running and fewer packages that need updating. Not to mention having less software on the system creates a smaller attack area for hackers to leverage.
So if you find that you need to remove the GUI from your Pi, hopefully this information will help you with your cleaning task. And of course, if you need something even smaller, there's always Minibian for a really stripped-down configuration.
Another really good compromise is to use a distro that's *meant* to be run and administered headlessly. I'm quite fond of dietpi for this task.
ReplyDeleteTheir web site looks a little game-centric, but the code has been lovely for me over several generations.
https://dietpi.com/docs/
Actually, these days I just use either Raspberry Pi OS Lite (https://www.raspberrypi.com/software/operating-systems/) or Debian (https://raspi.debian.net/) when I need a less bloated install.
ReplyDeleteI haven't looked at DietPi, but next time I'm setting up a headless 'Pi I'll have to check that out... Thanks!