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?

Peter Mortensen
  • 12,090
  • 23
  • 70
  • 90
my_question
  • 229
  • 5
  • 11
  • 1
    This is a mega duplicate. It should be covered by [the last 13 years](https://superuser.com/questions/1/). What is the canonical question? Why isn't there any effort to find the canonical question to such basic questions? – Peter Mortensen Dec 29 '22 at 18:34
  • Some starting points (but they are more specific): *[Cloning an SD card onto a larger SD card](https://superuser.com/questions/460657/)*, *[Can I use dd to clone a larger SD card to a smaller SD card if the actual partitions will fit?](https://superuser.com/questions/568236/)*, *[Using dd to copy partition to another partition, while using physical drive](https://superuser.com/questions/553238/)*, and *[Archiving old, outdated hard drives](https://superuser.com/questions/447374)*, – Peter Mortensen Dec 29 '22 at 18:35
  • Some low-scored questions (also more specialised): *[How to move data on internal storage of embedded Linux](https://superuser.com/questions/1186525/)* and *[SD card, corrupted, data recovery, file type unrecognized, allocated memory not recognized, all data recovery software fails to even scan correctly](https://superuser.com/questions/1389091/)* – Peter Mortensen Dec 29 '22 at 18:45

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,383
  • 2
  • 36
  • 47
  • 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