Shrink a Raspberry Pi or RetroPie .img On Windows with PiShrink

PiShrink is a bash script that automatically shrink a pi image that will then resize to the max size of the SD card on boot. However, thanks to Windows Subsystem for Linux (WSL), you can now run it on Windows!

Prerequisites

  • Install Linux on Windows with WSL
  • Rasberry Pi / RetroPie backup .img
    • An .img backup of a MicroSD includes all of the unused space and will be the size of the Micro SD Card (ie: a 16GB MicroSD Card will create about a 16GB .img backup). The simplest method for Windows is to use Win32 Disk Manager. Windows cannot read an EXT4, so it should show the Micro SD card as a Boot Drive (with a disk size of about 250MB) and another drive (with no disk size). Make sure you backup the second drive without a size listed in WIn32 Disk Manager, and this will backup the entire Micro SD card.
    • Note: Micro SD cards can vary slightly in size by manufacturer as well as between different models of Micro SD cards. Therefore, there’s no guarantee creating an .img backup of a Micro SD Card will be able to write back to the same size Micro SD card unless it’s the exact same manufacturer/model.
  • PiShrink.sh script
    • PiShrink will shrink an .img backup of Raspberry Pi / Retropie by removing the “unused” space. For example, if you create a backup image a 16GB Micro SD with 7GB of data on it, the original .img will be about 16GB but after running PiShrink, it will be about 7GB. Upon the first boot, the image will resize the max size of the SD card, so if you restore the 7GB image to a 32GB card, it will expand to have a max of 32GB.

Shrink Raspberry Pi / RetroPie .img on Windows with WSL

  1. Move your Raspberry Pi / RetroPie .img to C:\RPI\
    1. Ex: C:\RPI\RetroPie48.img
  2. Download PiShrink.sh and move it to C:\RPI\
  3. Open your WLS Linux Distro (ie: Ubuntu) and run the below commands:
    1. The time to complete will vary based on the size of the image and how much it can shrink. It took about 20min for me to shrink a 120GB image to 22GB.
cd /mnt/c/rpi
sudo ./pishrink.sh retropie48.img