# 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

- A microSD card to backup https://amzn.to/36CpShC | https://amzn.to/3CXJngt | https://amzn.to/3JqyxSP
- A Linux based VirtualBox VM https://youtu.be/V4pNO3amhV4 | https://youtu.be/wIa07KhkQOg | https://youtu.be/mmTCh1NG3AM

## Creating the Base Image

1. Insert the SD card into the Windows PC
2. Download Win32DiskImager Download
3. Extract the downloaded .zip file
4. Run Win32DiskImager.exe
5. Select the SD card from the Device dropdown
6. Click the folder icon > Browse to a location to save the SD card image > Enter a file name > Click Open
7. Click the Read button at the bottom of the application window
8. 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

1. Launch VirtualBox
2. Select the Linux based VM > Settings > Shared Folders
3. Click the Add Share icon to the right
4. Click the Folder Path dropdown > Other... > Browse to the folder containing the Win32DiskImager .img
5. Check the Auto-mount box, set the Mount point to /host and check the Make Permanent box > Click OK
6. Right click the VM > Start
7. Log into the guest OS
8. 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%>
9. PiShrink should complete in just a minute or two
10. If no errors occurred, shutdown the VM

## Compressing the Image Further

1. Download and install 7-zip Download
2. Right click on the shrunken .img file > 7-Zip > Add to archive...
3. Set the Archive format to xz and the Compression level to 9 - Ultra > Click OK
4. Wait while 7-Zip compresses .img file