How to clone a memory card in Linux


You have a memory card, for example a CF card which is corrupt or which needs to be cloned to another memory card. This article provides instructions on how to clone a memory card in Linux. To implement this solution you need to have a memory card reader. In most cases a reader comes in the form of a memory card to USB converter, which plugs into a USB port of your computer and allows for reading of any type of memory card.


Boot your computer from a Linux bootable image. In this example we will be using Linux Ubuntu 22.04 LTS. After booting into the Linux environment, either on an installed Ubuntu system or from the Ubuntu desktop .iso (USB drive), open a terminal by hitting the combination of Ctrl-Alt-T keys on your keyboard and run the following commands.

#Check first the device structure of your Linux system and pinpoint the source memory card you need to clone. In this example we assume that the card is /dev/sbc. 
#Clone the entire disk corresponding to the bootable memory card to an output file.
sudo dd if=/dev/sdc of=mycfcard.img
#Copy back the generated .img file to the target memory card, ensure first that the new memory card has been inserted.
sudo dd if=mycfcard.img of=/dev/sdc

If the target memory card has multiple partitions, you can erase all partitions by using fdisk. You should leave only one partition in the target memory card by running the following commands.

sudo fdisk /dev/sdc
#View partition table
#Delete a partition, run this command as many times as needed to delete all partitions
#Write changes to memory card partition table

You can also use the Windows disk manager MMC console or the command line diskpart utility to fdisk and format the target memory card.

Note that the above solution can be used when trying to restore a malfunctioning or dead hard drive. To streamline your recovery process, you can make use of a disk drive cloning and docking station, which essentially takes a full image copy (sector by sector) of the source (faulty) disk into a new target (functional) disk. In this way, the disk data is preserved and cloned into a functional disk. You can find plenty of options when considering purchase of a cloning station, such as the following examples:

Also you can use third party software such as GParted, EaseUS, Acronis Cyber Protect Home Office, Steven Gibson’s Spinrite (DOS-based app written in Assembly) and Clonezilla, which can greatly reduce your time when troubleshooting disk issues.

Was this article helpful?

Related Articles