Best way to backup micro-sd cards
You can still use the dd command to completely erase a microSD card on macOS, but the device naming convention is different from Linux. Instead of /dev/sdX, on macOS you will use /dev/diskX for the entire disk, where X is the number of the disk (e.g., /dev/disk2).
Here’s how to proceed with erasing the microSD card using dd on macOS:
1. List the Disks:
Use diskutil to find the correct disk identifier for your microSD card:
diskutil list
This will show all connected disks and partitions. Look for your microSD card in the list (likely something like /dev/disk2 or /dev/disk3), depending on how many drives you have connected.
2. Unmount the microSD Card:
Before using dd, you must unmount the card to prevent any file system corruption during the process:
diskutil unmountDisk /dev/diskX
Replace /dev/diskX with the correct disk identifier from the previous step (e.g., /dev/disk2).
3. Erase the microSD Card Using dd:
You can now safely use dd to zero out the entire microSD card. Here’s the command:
sudo dd if=/dev/zero of=/dev/rdiskX bs=4M status=progress
Important:
- Replace
/dev/rdiskXwith your actual device (/dev/rdisk2or similar). Therin front ofdiskX(e.g.,/dev/rdisk2) speeds up the process by using raw disk access. - This will overwrite the entire disk with zeros, effectively erasing all the data on the microSD card.
4. Wait for the Process to Complete:
Depending on the size of your microSD card, this may take some time. dd will display the progress as it writes zeros to the card.
5. Eject the microSD Card:
Once the process is complete, you can safely eject the microSD card:
diskutil eject /dev/diskX
Notes:
- macOS uses different disk names: Unlike Linux’s
/dev/sdX, macOS refers to disks as/dev/diskX(e.g.,/dev/disk2), and partitions as/dev/diskXsY(e.g.,/dev/disk2s1). To operate on the whole card, use/dev/diskX, not a partition like/dev/diskX1. - Erasing vs Formatting: The
ddcommand completely wipes the card. Afterward, you'll need to format it to a specific file system (e.g., FAT32) if you want to use it on a different device.
If you're planning to use the card on multiple devices, you may need to format it with diskutil afterward:
diskutil eraseDisk FAT32 SDCARD MBRFormat /dev/diskX
This method works just fine on macOS! Let me know if you run into any issues.
You said:
after sudo dd – if I wanted to duplicate anotehr micro ssd card onto it – would I leave it blacnk?
ChatGPT said:
ChatGPT
Yes, after using sudo dd to wipe the microSD card with zeros, the card will be "blank" (i.e., no partitions or file systems). If you want to duplicate another microSD card onto this blank card, you do not need to format it or create any partitions beforehand. You can directly use dd to clone the contents of the source microSD card onto the wiped card.
Steps to Duplicate Another microSD Card Using dd
Insert Both microSD Cards (Source and Destination) into your computer.
Identify the Device Names:
Use the following command to list the connected disks:
diskutil listIdentify both the source microSD card (which contains the data you want to clone) and the destination microSD card (the blank one you want to clone to). They will appear as
/dev/diskX(e.g.,/dev/disk2,/dev/disk3, etc.).
Unmount Both Cards:
Before using
dd, unmount the partitions on both microSD cards to avoid any file system issues during cloning.
e diskutil unmountDisk /dev/diskXRepeat this for both the source and the destination card, replacing
diskXwith the appropriate disk identifiers.
Clone the Source microSD Card to the Destination:
Use the
ddcommand to copy the contents of the source card to the blank destination card:
sudo dd if=/dev/rdiskX of=/dev/rdiskY bs=4M status=progressReplace
/dev/rdiskXwith the source card's identifier (e.g.,/dev/rdisk2) and/dev/rdiskYwith the destination card's identifier (e.g.,/dev/rdisk3).As mentioned before, using
rdiskinstead ofdiskgives you raw access to the device, which speeds up the process.
Wait for the Process to Complete:
- Depending on the size of the source card, this could take some time. The
status=progressoption will show you the progress of the cloning.
- Depending on the size of the source card, this could take some time. The
Eject the Cards:
Once the cloning is complete, safely eject both microSD cards:
diskutil eject /dev/diskX diskutil eject /dev/diskY
Notes:
- Exact Duplicate: Using
ddlike this will create an exact bit-for-bit clone of the source card, including all partitions, boot sectors, and file systems. The destination card will be an exact replica of the source card. - Different-Sized Cards: If the destination card is larger than the source card, the extra space will remain unused, but you can expand the partition later using a tool like
gparted. If the destination card is smaller than the source card,ddwill fail because there won’t be enough space to complete the clone.
Steps to Duplicate a microSD Card on Linux
From the output, I see the following:
sdc (29.8 GB): This is your destination microSD card, which is currently blank or unpartitioned.
mmcblk1 (29.8 GB): This is your source microSD card that contains your working Ubuntu installation. It has two partitions:
mmcblk1p1 (256 MB): Likely your boot partition (mounted at /boot/efi).
mmcblk1p2 (29.5 GB): This is likely your root filesystem partition.
Given this setup, you can clone the working mmcblk1 microSD card to the blank sdc card using dd.
Steps to Clone the Working microSD Card to the Blank Destination Card
Unmount the Destination microSD Card (sdc):
To ensure no processes are using the destination card, unmount any partitions:
sudo umount /dev/sdc*
Use dd to Clone the Source Card to the Destination:
Now, use dd to clone the entire mmcblk1 card (source) to the sdc card (destination):
sudo dd if=/dev/mmcblk1 of=/dev/sdc bs=4M status=progress
Insert Both microSD Cards (Source and Destination):
- Insert the source card (the one you want to clone) and the destination card (the one you want to write the clone to) into your computer using SD card readers.
Identify the Device Names:
Open the terminal and run the following command to list all block devices:
lsblkLook for your microSD cards in the output. They will usually be listed as
/dev/sdX(e.g.,/dev/sdb,/dev/sdc). You can identify them by their sizes to avoid confusion between your system's internal drives and the microSD cards.
Example:
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 256G 0 disk sdb 8:16 1 32G 0 disk # Source microSD card sdc 8:32 1 32G 0 disk # Destination microSD cardIn this case:
/dev/sdbis the source card./dev/sdcis the destination card.
Unmount Both microSD Cards:
Ensure both the source and destination microSD cards are not mounted before proceeding with the duplication:
sudo umount /dev/sdb* sudo umount /dev/sdc*
This unmounts all partitions on both the source and destination cards.
Clone the Source microSD Card to the Destination:
Use the
ddcommand to clone the source microSD card to the destination. Here’s the command:
sudo dd if=/dev/sdb of=/dev/sdc bs=4M status=progressif is the input file (source card,
/dev/sdbin this example).of is the output file (destination card,
/dev/sdcin this example).bs=4Msets the block size to 4 megabytes for faster copying.status=progressshows you progress during the cloning process.
Wait for the Cloning to Complete:
- This process can take some time depending on the size of the source card and the speed of your card readers. The terminal will show the progress of the operation.
Verify the Clone (Optional):
You can verify that the cloning process was successful by using the
lsblkcommand again to check the partitions on the cloned card, or by mounting the destination card and comparing its contents to the source card:
sudo mount /dev/sdc1 /mnt ls /mnt sudo umount /mnt
Eject the Cards:
Once the process is complete, safely eject both cards:
sudo eject /dev/sdb sudo eject /dev/sdc
Important Notes:
Exact Duplicate: The cloned microSD card will be an exact copy of the original, including all partitions, boot loaders, and data.
Card Size
:
- If the destination card is larger than the source, the extra space will remain unallocated, but you can expand the partition later using a tool like
gparted. - If the destination card is smaller than the source card,
ddwill fail because there isn’t enough space.
- If the destination card is larger than the source, the extra space will remain unallocated, but you can expand the partition later using a tool like
Data Integrity: If there’s any sensitive data on the source card, be cautious as
ddmakes a complete byte-for-byte copy, including deleted files, empty space, etc.
With these steps, you should be able to successfully duplicate a microSD card on Linux. Let me know if you encounter any specific issues!