02 PiShrink - schmoomers/Schmoomer-s-Wiki GitHub Wiki

2. PiShrink

Credits: Credits go to Vicious Computers for the steps I wrote here. I wrote them on videos linked below.

PiShrink allows you to shrink down the size of an image to just the size of the data within the image. This way the image file does not take up the entire size of the disk that the image was created from.

Example use case:

You are using a 512GB SD Card and want to create an image of file of the disk to either create a backup of an image or for the image to be able to be used on a different SD Card. The actual data usage on the source SD Card is much less than the 512GB SD Card, say 300GB for example. You would use the PiShrink process so that the file is not the full size of 512 GB, but instead only the data that is used up on the SD Card. If you did not use PiShrink, the file would be close to 512GB. If you did use PiShrink, the file would only be around 300GB.

To accomplish this, on a Windows 10 System, you must have WSL2 (Windows Subsystem Linux) installed on your Windows 10 System.

You will also need a .img file. This can be created by following the steps in the video mentioned in the Imaging section titled "How to make a backup of an SD Card".

Steps are detailed below for both installing WSL2 and using PiShrink. However there are some detailed guides posted below on this made by the YouTube Creator "Vicious Computers" if you prefer a video guide to a step-by-step guide.

If you are already running Linux you do not need to follow the steps on WSL.

WSL2 Video Guide:

https://www.youtube.com/watch?v=1bP3POWync8

NOTE: In the above video, if you follow those instructions instead of the ones in the step-by-step guide, He has you set the WSL version after you have installed Linux. You should set the WSL version to 2 before installing linux. See the step by step guide below for further details. If you do wind up installing linux before setting the WSL version, you can re-install or change the version by running the following command:

wsl --set-version 2

Example:

wsl --set-version Ubuntu 2

PiShrink Video Guide:

https://www.youtube.com/watch?v=77vOeofG0Kg

WSL2

Follow the steps on the WSL2 Wiki Article.

NOTE: If you are running a linux system already, you do not need to follow these steps. If you are using a Linux VM however, you will have difficulties in mounting and using a pi image. There are guides available on the internet for using VirtualBox, however they are outdated and require specific utilities and a specific version of VirtualBox that is no longer supported by Oracle. It is recommended to use a non-VM instance of Linux or WSL2 on Windows 10.

PiShrink

  1. Download PiShrink from the following location:

https://github.com/Drewsif/PiShrink

Click the "Code" button and select "Download ZIP"

  1. Extract the zip file using your preferred archive management software. 7-zip is recommended by most, however you can right-click -> select Extract, or you can use WinRAR, or whatever you prefer.

Create a directory on the root of your C: drive called "pishrink". Copy the pishrink.sh file from the files you extracted above, as well as the .img file you wish to shrink.

NOTE: In some of the screenshots below. The directory used is "e" instead of "c". This is due to size limitations in the testing environment requiring a different drive. Make sure you use a different drive with enough space for the entire non-shrunk image file to begin with.

  1. Launch Ubuntu, this can be done by clicking the windows start button and typing in Ubuntu and launching it there.

  1. Type the following commands:

cd /mnt/c/pishrink

Note: This directory was created in step "2" above. Substitute "c" with the drive you created the directory on and where you have the pishrink.sh script and image file.

  1. If you run the following command, you should see the pishrink.sh file and the .img file you created.

ls -al

NOTE: In the image above, the directory used is "e" instead of "c". This is due to size limitations in the testing environment requiring a different drive. You may need to use a different drive with enough space for the entire non-shrunk image file to begin with.

  1. Run the following command to execute PiShrink against the file:

sudo ./pishrink.sh image-name.img

Example:

sudo ./pishrink.sh retropie.img

NOTE: You may need to enter in the password you created when setting up WSL if prompted.

  1. This will run pishrink on the image file and shrink it down to just the space of the data that was used on the SD card or SSD.

NOTE: Your initial size and shrunk size will vary from the above image depending on the size of your SD Card or SSD, as well as the amount of data used up on the disk.