When creating a Raspberry Pi system image (img file), we typically copy the TF card using a tool. This results in an img file that is the same size as the TF card. If you want to burn this file onto a smaller TF card, an awkward situation arises.
At this point, you need a bash script called PiShrink. It can make the Raspberry Pi image smaller.
PiShrink automatically reduces the image size and then expands it to the maximum size of the SD card upon boot. This allows for faster copying of the image to the SD card, and the smaller image will compress better. This is particularly useful for fitting large images onto smaller SD cards.
In this brief guide, we will learn how to shrink a Raspberry Pi image to a smaller size on Unix-like systems.
Installing PiShrink
To install PiShrink, first download the latest version using the following command in the Linux terminal:
wget https://raw.githubusercontent.com/Drewsif/PiShrink/master/pishrink.sh
Next, make the downloaded PiShrink executable:
chmod +x pishrink.sh
Move it to the bin
directory:
sudo mv pishrink.sh /usr/local/bin/
Making the Raspberry Pi Image Smaller
Raspberry Pi OS is the official operating system for the Raspberry Pi. The Raspberry Pi Foundation has developed a desktop version for PC and Mac. You can create a live CD and run it in a virtual machine, or even install it on a desktop. There are also a few unofficial operating system images for the Raspberry Pi. For testing, I downloaded the official Raspberry Pi OS from the official download page.
Unzip the downloaded system image:
unzip 2019-04-08-raspbian-stretch-lite.zip
The command above will extract the contents of the 2019-04-08-raspbian-stretch-lite.zip
file in the current directory.
Check the actual size of the extracted file:
du -h 2019-04-08-raspbian-stretch-lite.img
1.7G 2019-04-08-raspbian-stretch-lite.img
The size of the extracted Raspberry Pi system image is 1.7G.
Now use PiShrink to reduce the size of this file:
sudo pishrink.sh 2019-04-08-raspbian-stretch-lite.img
Output:
As you can see in the output above, the size of the Raspberry Pi image has been reduced to 1.2G.
You can also use the -s
parameter to skip the automatic expansion part of the process.
sudo pishrink.sh -s 2019-04-08-raspbian-stretch-lite.img newpi.img
This will create a copy of the source image file (2019-04-08-raspbian-stretch-lite.img
) as a new image file (newpi.img
) and process it. For more details, please check the official GitHub:
https://github.com/Drewsif/PiShrink
The links in the text can be clicked to read the original article at the end
More Exciting Content
Creating a Motorcycle Dashboard with Raspberry Pi
Building a Smart Pet Feeder with Raspberry Pi
Creating a Smart Planetary Observer Based on Raspberry Pi
Handmade Metal Wireframe X-Wing Clock
Arduino + 280 LEDs DIY Music Spectrum Light
DIY Stanford Pupper 12-Degree of Freedom Quadruped Robot Dog
Barrier: A Keyboard and Mouse Sharing Solution Between PC and Raspberry Pi