You have a 32GB SD card.
You are using 1.8GB of space on it.
You want to back it up into an image that is 1.8GB big, not 32GB big.
Then you want to be able to put it on an SD card that is 2,4,8 or 16GB big.
If you do a normal image backup, you'll end up with an image that is 32GB big. As a backup that's a lot of wasted of space. If you just want to store it as a backup you could gzip it, which would remove the wasted space, but you still won't be able to put it on a smaller SD card in a bootable format.
If you do a backup by copying the files, you'll end up with an SD card that won't boot unless you create different partitions that are in the correct filesystem format and make sure each file is in the correct partition. It's possible you could miss some hidden files and end up changing file permissions which you'd have to chmod back, so this way wouldn't work without a lot of messing about.
Thanks to help from "milhouse" on the forum, I now know how to make an image of the SD card that's the same size as the actual space being used. This cannot be done on the pi itself, you'll need a seperate linux machine.
Using Gparted (or parted), reduce the size of your main partition on the SD card to remove most of the empty space (You'll probably want to leave a little free space, maybe a few megabytes), but do not reduce the size of the other partitions. Then use Gparted to make sure each partition runs consecutively from the start without any unallocated space in between them. Take note of the total size all the partitions are using up and the location of your SD card (dev/mmcblk0 for example).
Next we're going to use dd. You need to be very careful when using dd, because you could end up wiping your hard drive if you mistype something.
Now run the command:(See below on how to adapt)
Code: Select all
dd if=/dev/mmcblk0 of=/home/YOUR_USERNAME/Desktop/backup.img bs=1M count=2048
"of=/home/YOUR_USERNAME/Desktop/backup.img" (This is where you want to send your backup. In this example it will go to your desktop, but you can send it anywhere you want.)
"bs=1M" (This specifies block size. Here we've said copy over blocks of one megabyte (1024x1024 bytes) at a time. Read the man page for dd if you want to change this value.)
"count=2048" (This is how many blocks to copy over. In this example we've said copy over only 2048 blocks and then stop. Because we set the block size as 1 megabyte, we will get an image that is 2048 times 1 megabyte, which is 2 gigabytes.)
The count can be adapted to any size, for example, if you wanted a 1.8 gigabyte image, the count should be set to around 1850: 1.8 gigabytes(1.8 x 1024 x 1024 x 1024) divided by megabytes(1024 x 1024) = 1843.2 (the count must be an integer number, so the smallest count could be set to is 1844)
It is very important you adapt the bs and count values to the size of all your paritions on the SD card combined. Storage device capacities are normally given in powers of 1000, not 1024. So what your operating system sees as a 2 gigabyte(2 x 1024 x 1024 x 1024 bytes) image probably won't fit onto a 2 gigabyte(2 x 1000 x 1000 x 1000 bytes) SD card. dd does give the option of specifying blocks in powers of 1024 or 1000, so read the man page.
Because Gparted doesn't show the exact size of each partition in bytes, you'll generally want to make the image a little larger than the total size of all the partitions, just incase you don't make it large enough. If it's crucial the image is the smallest possible size it could be, you can find out exactly how many bytes each partition is by running the command:
Code: Select all
df -B1
I hope this helps and thanks to milhouse for this method.