geerlingguy / raspberry-pi-dramble

DEPRECATED - Raspberry Pi Kubernetes cluster that runs HA/HP Drupal 8
http://www.pidramble.com/
MIT License
1.67k stars 259 forks source link

Build lightweight Raspbian image for easier resetting #6

Closed geerlingguy closed 9 years ago

geerlingguy commented 9 years ago

Since I'm going to be doing a lot of testing on this platform, I want to have a really stable and easy way to get things back into a pristine condition.

Currently, Raspbian's default image weighs in at a hefty 2.5G (once fully installed and updated) according to df -h, but I think I can trim that down considerably by removing cruft I don't need for a bunch of headless servers.

I'd like to wrap up the process in an Ansible playbook, so I can rebuild this lightweight image (and allow others to do the same) as-needed. I might even be tempted to host a lightweight zipped .img file on http://files.midwesternmac.com/, but we'll see.

There are a few guides to the process, but nothing authoritative (or updated):

It looks like this would be the process:

  1. Set up config defaults for the Pis:
    1. Locale/timezone (locales, keyboard, localtime, etc.)
    2. /boot/config.txt values (see one of my Pis for current defaults; this should be specific to Pi revision)
  2. Delete files and folders you don't need:
    1. /home/pi/python_games
    2. /home/pi/Desktop
    3. /usr/share/icons/gnome/icon-theme.cache
    4. /opt/vc/src/hello_pi/hello_video/test.h264
    5. etc...
  3. Purge packages and repositories you don't need, for example:
    1. Wolfram: $ sudo apt-get remove --purge wolfram-engine
    2. Desktop GUI: $ sudo apt-get remove --purge desktop-base lightdm lxappearance lxde-common lxde-icon-theme lxinput lxpanel lxpolkit lxrandr lxsession-edit lxshortcut lxtask lxterminal
    3. Other X-related packages: $ sudo apt-get remove --purge obconf openbox raspberrypi-artwork xarchiver xinit xserver-xorg xserver-xorg-video-fbdev x11-utils x11-common
    4. Multimedia-related packages: $ sudo apt-get remove --purge esound-common freepats sonic-pi jackd2 omxplayer
    5. Pi-related packages that I don't need: `$ sudo apt-get remove --purge python-pifacecommon python3-pifacecommon
    6. Other packages: $ sudo apt-get remove --purge dillo squeak-plugins-scratch netsurf-gtk netsurf-common epiphany-browser-data fonts-droid gsfonts ruby1.9.1
    7. etc... (looks like there are still many things installed in /usr/share!).
  4. Remove packages that are no longer needed: $ sudo apt-get autoremove
  5. Clean apt caches: $ sudo apt-get clean
  6. Clear any log file entries.
  7. Disable swap and fill free space with 0s.
  8. Shut down, pop out the SD card, pop it into my Mac, build a new image, compress the image...

Helpful hints:

geerlingguy commented 9 years ago

I have an initial version ready to go (locally), but I'm considering breaking this entire aspect of the project out into a separate GitHub project, maybe named diet-raspbian or something like that. That way I can use it more generically, and configure it in ways that help other projects.

I could include it as a submodule of this repo, perhaps.

So far here are the preliminary space saving results:

BEFORE:

$ df -h
Filesystem      Size  Used Avail Use% Mounted on
rootfs          7.2G  2.4G  4.5G  35% /
/dev/root       7.2G  2.4G  4.5G  35% /

$ free -m
52M used

AFTER:

$ df -h
Filesystem      Size  Used Avail Use% Mounted on
rootfs          7.2G  1.5G  5.4G  22% /
/dev/root       7.2G  1.5G  5.4G  22% /

$ free -m
51M used
geerlingguy commented 9 years ago

See: https://github.com/geerlingguy/diet-raspbian

geerlingguy commented 9 years ago

I've added diet-raspbian as a submodule, so at this point I just need to keep it up to date from time to time, and I should be fine.