Skip to content

Instantly share code, notes, and snippets.

@sean-smith
Last active December 21, 2024 03:19
Show Gist options
  • Save sean-smith/de4322f2e079bcdb979802a4147150e7 to your computer and use it in GitHub Desktop.
Save sean-smith/de4322f2e079bcdb979802a4147150e7 to your computer and use it in GitHub Desktop.
Create an image for raspberry pi on MacOS

Copy Raspberry ISO on MacOS

based on https://opensource.com/article/21/7/custom-raspberry-pi-image

  1. First image the raspberry pi and make any changes you need via SSH. When you're done make sure to install cockpit:
sudo apt install cockpit
  1. Next plug in the SD card into your mac and list the attached disks:
diskutil list
  1. We need to unmount the attached disks like so:
diskutil unmount /dev/disk4s1
diskutil unmount /dev/disk4s2
  1. Next copy the contents of that disk into an image file, you can call raspberry-pi-image.img whatever you want.
sudo dd if=/dev/disk4 of=raspberry-pi-image.img bs=32M
  1. Next shrink down the image with pishrink
  • Installer Docker.
  • Clone this repo and cd into the pishrink directory:
    git clone https://github.com/Drewsif/PiShrink && cd PiShrink
  • Build the container by running:
    docker build -t pishrink .
  • Create an alias to run PiShrink:
    echo "alias pi-shrink='sudo docker run -it --rm --platform linux/amd64 --privileged=true -v $(pwd):/workdir pishrink'" >> ~/.bashrc && source ~/.bashrc
  • run it
    sudo pi-shrink raspberry-pi-image.img

To flash the image open the raspberry pi image flasher:

  • Select the type of Raspberry Pi
  • Select the image you just created
  • Select the SD card to write too
image
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment