Question How to copy an SD card?

jk_1966

Commendable
May 28, 2021
36
1
1,535
Hello,
I work in a school lab with 12 PRi's. One SD card got lost though.... How can I copy it from another machine?
Tnx
 

OldSurferDude

Reputable
May 18, 2019
168
30
4,640
I'm not an expert at this, but what I would do is use the dd command.
I'd use two two mircoSD usb card readers, but you might just need one. Look at these instructions. The trick is, which one is the if file and which is the of file? /dev/sda is usually the boot disk, but apparently not for the RPi.

On one of your working RPi's, before you plug in either of the USB card readers, from a terminal window, execute the command:
lsblk
You'll get something like:
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
mmcblk0 179:0 0 29.1G 0 disk
├─mmcblk0p1 179:1 0 256M 0 part /boot
└─mmcblk0p2 179:2 0 28.9G 0 part /

Then plug in the card reader with your source sd card and repeat the command and you'll get something like:
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 1 954M 0 disk
└─sda1 8:1 1 954M 0 part
mmcblk0 179:0 0 29.1G 0 disk
├─mmcblk0p1 179:1 0 256M 0 part /boot
└─mmcblk0p2 179:2 0 28.9G 0 part /

sda will be your if device
Now plug the destination, repeat the command and you'll get something like:
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 1 954M 0 disk
└─sda1 8:1 1 954M 0 part
sdc 8:32 1 29.1G 0 disk
└─sdc1 8:33 1 29.1G 0 part
mmcblk0 179:0 0 29.1G 0 disk
├─mmcblk0p1 179:1 0 256M 0 part /boot
└─mmcblk0p2 179:2 0 28.9G 0 part /

sdc will be your of device.
The command will be as simple as:
dd if=/dev/sda of=/dev/sdc
be patient, it will take a while.

You may be able to get away with just one SD card reader. After determining the destination device, the command would be:
dd if=/dev/mmcblk0 of=/dev/sda
In theory this will copy the SD card of the RPi to the destination SD card.

Oh, yeah, you may have execute the dd command as sudo

OSD

(I'd appreciate it if someone with more experience than I would confirm what I write here :)
 
  • Like
Reactions: jk_1966

OldSurferDude

Reputable
May 18, 2019
168
30
4,640
dd takes a very long time! Hours of nothing but hope that it is working. I forgot to mention status, the the level of information to print to stderr. So the command would be:

sudo dd if=/dev/mmcblk0 of=/dev/sda status=progress

which will show the progress

OSD
 
I would create an image of 1 of the SD cards to save it as a backup on your computer or school LAN storage. Then you can create as many SD cards as you want from that one image. You can do this using WIN32DISKIMAGER which is free.

Just follow these steps, you can create the image and save it somewhere. Then write the image to as many SD cards as you want. To get the READ button to work, you have to type in the file name and file path manually.
 

Nice Nicer

Commendable
May 24, 2021
103
3
1,595
If you have a USB to SD card adapter , you might have the possibility to just copy the entire content of the SD card directly from a pi to a new SD card. The method should be kind of simple. I haven't tried this. But it might be worth a try to just copy and paste everything from one to the other card.