2

So I want to backup what I have done to Raspian using my Ubuntu laptop and followed the advice at the below link. so using this command... sudo dd if=/dev/mmcblk0 of=~/sd-card-copy.img bs=1M status=progress this is all very good, however, my laptop only has 24Gb spare and the memory card is 128Gb! this command seems to want to write the entire memory card size even though it is only 10Gb of data.

I have a server address I can share to that has the space, but how do I direct the 'dd' command to another area? At first I thought I could change to that directory and run the command but that starts putting it into my 'home' folder. thanks in advance for help.

SD card cloning using the dd command

1 Answer 1

4

First, I think its important to understand the command you're using. dd by its very nature is a bit-by-bit copy of the if (input-file) which results in a perfect copy of the file when you give it an of (output-file). This includes any zeros. You also have to remember that the file table does not actually represent what is on the device, just what you can normally see. That's why when you try and recover files using recovery software you can often times recover files that are not yet overwritten. Files are deleted from the table allowing the space they consumed to be listed as "free" and other files to write over top of those "deleted" files. They aren't typical scrubbed in most filesystems in the interest of saving time on a delete.

Your of= option takes a path to a file, so if you are trying to get the output in the directory you're currently working in pwd then of=sdcard-copy.img should suffice.

That being said, you have an alternative option for saving output:

You could compress the output with gzip to save it: dd bs=1M if=/dev/mmcblk0 | gzip -c > sdcard-copy.img.gz

and decompress it on the restore phase: gunzip -c sdcard-copy.img.gz | dd of=/dev/sdb bs=1M or whatever your intended target device is (I would suspect sda)

The downside to this is that it will take some time to compress/decompress vs just plain copying. For your case that may actually be pretty fast if the source is mostly zeros (which it sounds like it is).

1
  • OK, that works on making the img and compressing it. Thank you, at least I have a backup of the image now and it's much smaller as expected. Having trouble mounting a different card for now, will try the de-compression when I've figured that out. Thank you.
    – styleruk
    Mar 2, 2022 at 16:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .