After setting up the Raspberry Pi, it’s a good idea to make your own installation image
from it. This mainly involves using the
dd command to clone the SD card into a file.
However, there are some extra steps that can be used to produce a smaller file, and to
provide a helpful login message to anyone using the image.
Preparation on the running system
After setting up your Raspberry Pi - but before shutting it down - prepare the installed system for imaging.
Edit the login message to detail setup tasks required on logon:
Clean up the system by removing any unneeded files and private user data.
Zero fill the unused SD card space for better compression. This can instead be done with an image file1 if you’re concerned wearing out the card, or just want better speed.
Here’s the basic command to copy an SD card into a file. The size is correct for the
current Raspbian image at raspberrypi.org, and can be confirmed
by viewing the size of the original uncompressed image:
unzip -l raspbian.zip, or
The easiest way I’ve found to mount the image as writable, is to first create loopback devices using
gnome-disk-image-mounter -w. You can also calculate the partition offsets and use
fdiskto view the partition table info of the SD card, then calculate the total amount to copy using
# confirm the above values sudo fdisk $dev # append '-l' flag on linux # on OS X, add the last partition start to its size bc -l <<< '(122880+5662720)/2/1024' # on Linux, use the last partition block bc -l <<< '(5785599+1)/2/1024'