Unix systems make storage devices available via a device file. Device files behave like ordinary files in many ways. In particular, to make an exact copy of storage device, you just copy the content of the source device into the target device.
First you need to determine the source device file and the target device file. The name depends on your Unix variant and how it's configured, but in practice device files are always under the
/dev directory. If you have the SD card mounted, you can find what the device file is with
The device file is in the first column. Other tools can provide the same information, for example kernel log messages when you insert the SD card, or the
lsblk command on Linux.
There may be partitions on the card. If so, copy the whole card, even if there is a single partition, because some boot-time information may be located outside of the partition. For example, if
/dev/sdb1 on Linux, copy
/dev/sdb and not just
If you pull the SD card out and reinsert it, it will usually have the same device file name as before, but this is not guaranteed.
Before copying, make sure that:
- The source device is not mounted or is only mounted read-only.
- The target device is not mounted at all.
- The target device is at least as large as the source. On Linux,
lsblk displays the device size.
- You have the correct target device. Note that the command below will overwrite its contents without asking for confirmation!
Suppose that you've identified that the source device is
/dev/sdb and the target device is
/dev/sdc. To copy the contents, run the following command as root:
cat /dev/sdb >/dev/sdc
If you use sudo, the redirection
> needs to happen as root, so you need to write something like
sudo sh -c 'cat /dev/sdb >/dev/sdc'
Alternatively, to make sure you don't accidentally overwrite the wrong device, you may proceed in two steps:
- Give the user (
gatorback in my example) permission to read from the source device (
dev/sdb in my example) and to write to the source device (
/dev/sdc in my example).
sudo setfacl -m user:gatorback:r /dev/sdb
sudo setfacl -m user:gatorback:w /dev/sdc
- Perform the copy without sudo.
cat /dev/sdb >/dev/sdc
You can copy the disk image to a file, then copy the image file to the target device. This is useful if you need to make multiple copies, or if you only have one SD card reader, or to reduce the risk of copying in the wrong direction.
sudo cat /dev/sdb >sdcard.image
- Pull out the source card and insert the target card.
- Optionally, verify the content by mounting the image, e.g.
sudo mount -o loop -r sdcard.image /mnt.
sudo sh -c 'cat sdcard.image >/dev/sdb'
If you want to see progress information conveniently, use
pv instead of
pv is rarely installed by default, but it's available as a package on most distributions).