Raj Shekhar Dev

Back

Create a custom Raspberry pi image

Step 1: Prepare your current Pi

  • Boot your Raspberry Pi using SD card with a default base image of your choice.
  • Run system updates: sudo apt update && sudo apt upgrade -y
  • Clean up temporary files: sudo apt autoremove && sudo apt autoclean
  • Setup the Pi exactly the way you want you new image to be i.e.
    • Install all the software you need
    • Setup any new configurations you want

Step 2: Create the image

  • Shut down the Pi and remove the SD card
  • Insert it into a computer with a card reader
  • Use imaging software to create a backup:
    • Windows: Win32DiskImager or Raspberry Pi Imager (Not tested. Not a Windows user. Sorry!)
    • Linux/macOS: dd command

Example with dd:

  • Find the disk path of your SD card using lsblk or df -h
  • Run the following replacing /dev/sdX with the path found using above.
sudo dd if=/dev/sdX of=my-custom-pi-image.img bs=4M status=progress

Step 3: Shrink the image (optional)

  • Use PiShrink to reduce image size: wget https://raw.githubusercontent.com/Drewsif/PiShrink/master/pishrink.sh
  • Make it executable: chmod +x pishrink.sh
  • Shrink: sudo ./pishrink.sh my-custom-pi-image.img