SkillAgentSearch skills...

Shrinkwrap

No description available

Install / Use

/learn @mtyka/Shrinkwrap
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

RaspberryPi Image Shrinkwrap

I often make images of Raspberry Pi sdcards for easy installation and cloning. Unfortunately the size of the image will always be that of the size of the card, which is usually much larger than the amount of actual data. Thankfully there is a way to shrink an image, though every tutorial i've seen online is cumbersome and manual (e.g. using gparted). Instead I wrote a script that does it automatically and shrinks the image to it's minimal size.

NOTE: USE AT OWN RISK - THIS IS UNTESTED. ALWAYS BACKUP YOUR IMAGE BEFORE TRYING THIS.

Copy the sd card over

Find your sdcard device, might be /dev/sdb or /dev/mmcblk0 or other.

lsblk

Copy the image locally to an img file

sudo dd bs=4M if=/dev/mmcblk0 of=myimage.img conv=fsync status=progress

Shrink the image

./shrinkwrap.sh myimage.img

Copy the image to new sd card

sudo dd bs=4M if=myimage.img of=/dev/mmcblk0.img conv=fsync status=progress

Boot from the card

You can now resize the image back to take the full SD card size by going to:

sudo raspi-config

And then choose "Expand root partition to fill SD card" option under Advanced Options.

View on GitHub
GitHub Stars24
CategoryDevelopment
Updated27d ago
Forks14

Languages

Shell

Security Score

85/100

Audited on Mar 5, 2026

No findings