- I have a 8gb sd card with raspian image. Also I had expanded filesystem using sudo raspi-config.
- After that I had crated image using win32diskimager. Image size is around 8,068,792,320 bytes . However when I try to burn same image back to same sd card, win32imager shows error that not enough space.
- Strange thing is sd card is same, same image is read , but when I write back it fails.
Each and every SD card, even Hard Drive always has a different amount of usable sectors.
This is a common issue when cloning your expanded Raspbian and trying to rewrite it to another SD card, as it most probably has less usable sectors.
The same may apply to the the exact same card, due to different sector alignments caused by partition aligning and various other little things. Usually these get overcompensated so the actual image is slightly larger than the SD card that way.
One way to overcome this, is to setup your image from scratch without expanding the file system to 8GB. Dump the image (which will be 4GB), then write it to another 8GB card. Boot the new card up and only then expand the File System.
You can reduce the file system on the existing image, using
resize2fs by 100MB for example. The problem is you only resized the file system but the image is still the original size. You would just need to redo the DD and limit the size by 99MB (so there will be roughly 1MB of unused space in the image), not to hit the newly resized file system. This will be sure it will fit all next 8GB sized cards.
I find option 1 easier and faster to be honest but we had to learn the hard way.
If you have access to a Linux system check out mvp's answer.
I followed this answer as I had the same issue as you. First you will create a compressed image of the SD card. Then you will write this image to the SD card. This will fail as the image is too large for the SD card however the data that cannot be written to the SD card is empty space so everything will work as before.