4

I have a microSD card. It was created from an embedded Linux image and it is used to boot up a device. I like to make a copy in case the card gets damaged.

So should I use the dd command to copy the card to some file and save that file as backup? What is the dd command?

1 Answers1

7

Could you show me the dd command?

If you're using a USB adapter, the SD card will show up as a /dev/sdx device node. If so use

dd if=/dev/sdx of=sd_image.bin bs=32768

If your computer has an integrated card reader, then the SD card will probably show up as a /dev/mmcblk0 device node. If so use

dd if=/dev/mmcblk0 of=sd_image.bin bs=32768

These commands will copy the entire SD card (that is, its MBR sector, all partitions, and all unallocated sectors), and terminate when the device reports that the "end" has been reached. The resulting image file can only be copied back to an SD card of the same (or larger) capacity.

sawdust
  • 17,804
  • 1
    Instead of the "magic" 32768 one can use 32KiB (or 1MiB, because why not) – gronostaj Dec 29 '22 at 07:40
  • Another option is to use PV if you have it installed pv < /dev/sd_whatever > /BackupDestination/whatever.bin

    or

    pv /dev/sd_whatever > /BackupDestination/whatever.bin

    – Beige The Color Dec 29 '22 at 07:40
  • Btw, I would suggest this to be done offline, i.e., all the (including but not limited to /) filesystems unmounted. – Tom Yan Dec 29 '22 at 08:42
  • Note, pv -pterb ... will give nice progress indicator with the current copying speed and a expected time to finish the copy operation. With dd status=progress ... you can also have some ongoing progress display, albeit not as pretty as pv does. – Nikita Kipriyanov Dec 29 '22 at 09:29
  • 1
    dd is unnecessary here. You can just use cat or pv if you want a progress indicator and you don't have to explicitly set a block size in order for it to be efficient. – eesiraed Dec 30 '22 at 00:35