If you have an install of pi os or anything else you want to backup you can copy it to an img file which can then be burned to a new sd card. This is accomplished with the dd command.

  1. turn off the device andtake the sd card out and put in an sdcar reader on another machine.
  2. In the example below we will assume the sdcard is assigned to /dev/sdc you can find out through running lsblk or using the dmesg command after inserting the card. we will also assume we are making the image in the home folder of current user afleak

sudo dd if=/dev/sdc of=/home/afleak/sdcard-backup.img bs=64K status=progress

The img file created will be the size of the sdcard so if for example it is a 64gb sdcard the img will also be 64gb in sixe

  1. There is a tool pishrink which is a bash script for shrinking the image file pishrink

To use: A good idea is to make a copy of your image just in case something goes wrong. Then sudo pishrink -v nameof.img

The -v turns on verbose messages so you know what pishrink is doing. you can also specify a second image name in the command line if you don’t want to overwrite the first one.

the image should rezise itself the first time it is copied back to an sd card and ran.