NOTE - Official Raspbian Lite Distribution Now Available!: As of November 2015, the official Raspbian image is now maintained in a full GUI and 'lite' GUI-less flavor. This project has now been deprecated as of the 2.0.0 ('Jessie') release, and you should switch your servers over to the official Lite image instead.
Trim the fat from the default Raspbian image.
Many minimal Raspbian images are based on very old versions of Raspbian and aren't built in an open/simple way.
Diet Raspbian uses Ansible to take a system built with the official Raspbian image, and strip it of extraneous bits like default IDEs, languages, Wolfram, a window manager, etc. Why? If you're running a Raspberry Pi as a small headless server (e.g. for home automation, a fun robot project, or in a clustered configuration), there's no need for all the extra cruft.
You can skip all of these directions and download a pre-generated Diet Raspbian image directly from the Midwestern Mac Files site (under the 'Raspberry Pi Images' section).
Everything should be done on your local host machine—nothing needs to be done on the Raspberry Pi itself!
ssh-copy-id pi@[IP-ADDRESS]
), and make sure you can login to the Pi without a password (e.g. ssh pi@[IP-ADDRESS]
).
passwd
to change the pi
account password from the default, raspberry
.raspi-config
at this time.inventory
file and set the IP address to the address of your running Pi.$ ansible-playbook -i inventory diet.yml
.After 10-20 minutes, the space consumed by Raspbian should go from ~2.5 GB to ~700 MB (or lower, depending on how far along this project has come!). If you'd like to create a new image for cloning purposes, run the command ansible all -i inventory -a "shutdown -h now" -s
to shut down your Pi, then follow the steps under 'Creating a new Diet Raspbian disk image'.
IMPORTANT: The
diet.yml
playbook is meant to be run prior to any other Raspberry Pi configuration; it changes locale settings, general configuration, etc. (seevars/main.yml
). This is meant to be run on a freshly-imaged Raspbian microSD/SD card.
If you want to do the first couple setup steps using the GUI instead of just connecting to the Pi via SSH headlessly, you can do so using the steps below; then go to step 3 in the above directions from your local host machine.
ifconfig
, to get your Pi's IP address.Once you've run the diet.yml
playbook on your Pi, you can create a new diet-raspbian.img.gz
compressed disk image that you can use to clone (or re-clone) to your microSD cards, so you don't have to run the diet.yml
playbook in the future, or if you want to quickly rebuild your existing Pi's OS.
$ sudo apt-get install -y gparted
$ sudo gparted
/dev/sdb
) from 'Devices' in the GParted menu.ext4
(should be ~4 GB) and boot
volumes and unmount them.ext4
volume and resize it to a smaller value (e.g. 1024 MB
).$ diskutil list
(should be something like /dev/disk2
)dd
:
pv
: $ sudo dd if=/dev/disk2 bs=1m count=1536 | pv | gzip > ~/Desktop/diet-raspbian.img.gz
pv
: $ sudo dd if=/dev/disk2 bs=1m count=1536 | gzip > ~/Desktop/diet-raspbian.img.gz
WARNING: Double-check that you're using the right
if
disk andof
orgzip
destinations; these values will be different on your system.The
count=1536
above will create an image that is 1.5 GB. If it needs to be larger to contain all the partitions on the microSD card, you'll need to increase the size here.
At this point, you should have a disk image you can write to new SD cards, or use to overwrite your existing SD card.
$ diskutil list
(should be something like /dev/disk2
)$ diskutil unmountDisk /dev/disk2
pv
: $ gzip -dc ~/Desktop/diet-raspbian-2.0.0.img.gz | pv | sudo dd of=/dev/disk2 bs=1m
pv
: $ gzip -dc ~/Desktop/diet-raspbian-2.0.0.img.gz | sudo dd of=/dev/disk2 bs=1m
WARNING: Double-check that you're using the right
if
disk andof
orgzip
destinations; these values will be different on your system.
sudo swapoff -a && sudo rm -f /var/swap
$ sudo raspi-config
, and select the first option ('Expand Filesystem').Created in 2015 by Jeff Geerling, author of Ansible for DevOps.