From time to time you may want to quickly copy a raspberry pi image from one system to another....but only have a smaller SD card. Or you started your project as a tryout on a crazy 64GB sd card, and realize later that 8GB would be way enough. So what you want to do, is resize the source image to the smallest size possible, flash it to the new smaller SD card, and expand it again to its new maximum on the new SD card. And so far that process can be very long and painful....but luckily there is a very handy script for that, called PiShrink. I am using the mac version, but there is also a linux version.
First create a image from your existing Raspberry PI. I would suggest using my Backup script for raspberry pi.
Once you have that made and copied the *.img file over to you Mac, we can install the actual ShrinkPi tool.
Open your Mac OS terminal. With the following commands we will download the source code, unzip the archive, go to the new directory, and then start making it with make.
curl -LO https://github.com/lisanet/PiShrink-macOS/archive/master.zip unzip master cd PiShrink-macOS-master make sudo make install
Take a coffee, this may take a while.
When its successful done, you have a new command available in your terminal:
pishrink imagefile.img [newimagefile.img]
So its time to resize our image. Lets say its called raspi.img and you placed it in Downloads. This is the image with your working system on it. Now we create the much smaller resized version of it with:
cd ~/Downloads/ pishrink raspi.img newSmallRaspi.img
This command will resize your image and if successful you end up with a new and much smaller image called "newSmallRaspi.img" in your Downloads folder.
You can now flash that image to your empty smaller SD card with a tool like etcher for example.
Thats it, no more headache about resizing your Raspberry Pi system 🙂