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?

2
  • Please compress it with something like zip or gzip and tell us what was the result. If your SD has lots of unused space that is filled with predictable patterns (lots of 0 for example) you will notice a significative size reduction. The problem is that it isn't a default behavior to fill in freed space with anything. If you write all 0 to the SD and then partition, format and do everything else, you should be fine. Let me check if I can find some way of filling it on your current stage.
    – Marco Poli
    May 7, 2014 at 14:32
  • As I have said many times before, SD card image is not a backup, because backup is meant to be restored, and SD image would not restore properly unless it's exactly the same (size/manufacturer) SD card. Use Linux to copy files instead, something like bootable CD or USB stick will do just fine.
    – lenik
    May 8, 2014 at 16:41

3 Answers 3

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.

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.

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.