How I Backup and Shrink My SD Card Images [Raspberry Pi | Armbian]
What is Win32DiskImager?
[Win32DiskImager] is designed to write a raw disk image to a removable device or backup a removable device to a raw image file. It is very useful for embedded development, namely Arm development projects (Android, Ubuntu on Arm, etc). -https://sourceforge.net/projects/win32diskimager/
Things You Will Need
Creating the Base Image
- Insert the SD card into the Windows PC
- Download Win32DiskImager Download
- Extract the downloaded .zip file
- Run Win32DiskImager.exe
- Select the SD card from the Device dropdown
- Click the folder icon > Browse to a location to save the SD card image > Enter a file name > Click Open
- Click the Read button at the bottom of the application window
- Wait while the contents of the SD card image is read
What is PiShrink?
PiShrink is a bash script that automatically shrinks a pi image that will then resize to the max size of the SD card on boot. This will make putting the image back onto the SD card faster and the shrunk images will compress better. In addition the shrunk image can be compressed with gzip and xz to create an even smaller image. Parallel compression of the image using multiple cores is supported. -https://github.com/Drewsif/PiShrink
Shrinking the Image Partitions
- Launch VirtualBox
- Select the Linux based VM > Settings > Shared Folders
- Click the Add Share icon to the right
- Click the Folder Path dropdown > Other... > Browse to the folder containing the Win32DiskImager .img
- Check the Auto-mount box, set the Mount point to /host and check the Make Permanent box > Click OK
- Right click the VM > Start
- Log into the guest OS
- Launch a terminal and run the following commands
# install prerequisites
sudo apt install parted xz-utils
# download the pishrink script
wget -O ./pishrink.sh https://raw.githubusercontent.com/Drewsif/PiShrink/master/pishrink.sh
# make the script executable
chmod +x ./pishrink.sh
# run pishrink on the .img file
sudo ./pishrink.sh -v /host/<%imagename.img%>
- PiShrink should complete in just a minute or two
- If no errors occurred, shutdown the VM
Compressing the Image Further
- Download and install 7-zip Download
- Right click on the shrunken .img file > 7-Zip > Add to archive...
- Set the Archive format to xz and the Compression level to 9 - Ultra > Click OK
- Wait while 7-Zip compresses .img file