0

I downloaded official Raspbian image, did expand_rootfs, updated everything, installed needed packages, removed unneeded packages. So, now after everything is setup fine, I wanted to backup this image to an .img file again to save time if I ever need to re-setup this or another Pi.

I'm flashing and backing up the card in Windows with Win32 Disk Imager. But the problem is: now that I did expand_rootfs it backs up the full mainly empty 32 GB of my card. But I want a backup only of the actually used ~500 MB space (just like one only downloads an image that is just the size of the non-zero space).

How can I create a minimal image file for backup out of the expanded SD card under Windows?

Foo Bar
  • 453
  • 3
  • 18

3 Answers3

1

I used live USB with GParted for same purpose. Just boot your PC with that tool and MicroSD card in the reader and you can easily manage partitions how you want.

Vir
  • 196
  • 6
1

The exists a nice tool called pishrink which reduces the size of a dd image as much as possible by shrinking the root partition. If you start up the restored image the first time the partition is expanded to it's maximum size again. If you run Windows just use your Linux on your Raspberry to shrink the image.

framp
  • 896
  • 7
  • 17
0
  1. Zero free space on the running system (there are a few ways but zerofree is a simple one)
  2. Make the .img
  3. Compress with 7z (zip and rar also work but 7z as they can use 7z's open LZMA2 compression).
  4. Using backup software will store only the differences in each backup (more effectively without step #3)

You can further reduce .img size by clearing logs, caches, unused packages etc.

As a system backup solution it is often best to keep an install.log you can run (or follow) on a fresh install as you will want to upgrade, or use a different distribution and guessing what you did and why from a backup image is not worth the effort.

If you are backing up data and not the OS then backup software has numerous advantages.

Steve Robillard
  • 34,988
  • 18
  • 106
  • 110
user1133275
  • 2,216
  • 16
  • 32