0

I have raspbian setup and configured ready to replicate to other pi's. The source sd is a 16GB memory card but only 5GB is used. When I use win32 image to backup, it images the whole 16GB. How do I image just the 5GB so I can buy the cheaper 8gb cards rather than 16gbs?

Thanks

resolver101
  • 213
  • 1
  • 3
  • 9
  • [Read this](https://www.marksanborn.net/howto/make-a-backup-image-of-your-hard-drive-with-dd/), and [especially this](https://stackoverflow.com/questions/19355036/how-to-create-an-img-image-of-a-disc-sd-card-without-including-free-space). It won't help you now because the decompress will need a 16GB card... but at least you'll know. – Seamus Feb 11 '20 at 21:38

3 Answers3

1

You can create an empty image file of any size you want. It has empty formatted partitions, one fat32 boot partition and one ext4 root partition. But you are free to create partitions as much as you like and format them as you like. Then you can mount the empty partitions and the partitions of your source SD Card and copy its files to the new image as long as all files fit into the partitions of the new image. When finished you can just flash the new (smaller?) image to an SD Card. How to use it, look at How to make an image file from scratch.

Ingo
  • 40,606
  • 15
  • 76
  • 189
0

First: What Win32diskimager does is creating a bit-to-bit copy of the SD card. This means it copies every bit, even if it stores no data.

There are several tutorials how to to that on a Linux machine, like this one https://raspberrypi.stackexchange.com/a/56312/71377

Furthermore there are automatized scripts to to that on Linux, e.g. https://github.com/qrti/shrink.

I don't know a way to handle this problem on Windows (which you seem to be using) properly. I would recommend you using a Linux VM (virtual machine) or Linux live system which can be booted from a USB stick.

To do so, download e.g. a Ubuntu image from here. Copy it to a USB stick the way you copied Raspbian to your SD card using Win32DiskImager. Boot your PC from this USB stick and click on "Try Ubuntu". Now you have a working Linux environment which can be used to shricńk the image following the guides I linked above.

tr01
  • 125
  • 7
0

Short answer: buy an 8GB SD card and use that as your source.

You can then copy the 8GB .img file 8GB or other larger SD cards. Incidentally when you first boot from the larger SD card, Raspbian automagically expands to use all the card.

I also found that 8GB microSD cards are becoming scarce, so I picked up a couple now.

Don Burch
  • 21
  • 4
  • Your answer is wrong. A cloned image is not expanded automagically on its first boot. This is only true for a fresh virgin [Raspbian image from the download page](https://www.raspberrypi.org/downloads/raspbian/). – Ingo Feb 12 '20 at 08:20