This script allows you to clone an SD card on macOS by creating a disk image (dump) and writing it to another SD card. It provides options to create a dump of an SD card, burn an existing dump to an SD card, or clone an SD card directly by performing both actions sequentially. Progress is displayed during the operations.
- Create Dump: Create an image of the selected SD card.
- Burn Dump: Write an existing image to an SD card.
- Clone SD Card: Create a dump of an SD card and burn it to another SD card.
- Progress Visualization: Shows progress during dump creation and burning process.
- Size Verification: Checks if the destination SD card has enough capacity before writing.
- macOS: The script is designed to run on macOS.
- Administrative Privileges: Some operations require
sudo
privileges. - Tools Used: The script uses built-in macOS tools like
diskutil
,dd
,awk
,bc
, andgrep
.
-
Download the Script: Save the script as
clone_sd.sh
in your desired directory. -
Make the Script Executable: Open Terminal, navigate to the directory where you saved the script, and run:
chmod +x clone_sd.sh
Run the script from the Terminal:
./clone_sd.sh
Upon execution, you will be prompted to choose one of the following options:
- Create SD card dump
- Burn dump to SD card
- Clone SD card (dump and burn)
- Select the SD Card: The script will display a list of available disks. Enter the identifier of the SD card you wish to clone (e.g.,
disk2
). - Confirmation: Confirm that you have selected the correct SD card.
- Dump Creation: The script will unmount the SD card and create a disk image (
.img
file) with a timestamped filename. - Progress Display: The
dd
command will display progress information during the dump creation. - Completion: Once completed, the SD card will be remounted, and the dump file will be saved in the current directory.
- Provide Dump File: Enter the path to the existing dump file you wish to burn.
- Insert Destination SD Card: Remove any SD cards and insert the SD card you wish to write to.
- Select the SD Card: The script will display a list of available disks. Enter the identifier of the new SD card (e.g.,
disk2
). - Confirmation: Confirm that you have selected the correct SD card to write to.
- Size Verification: The script will verify that the destination SD card has enough capacity to hold the dump.
- Burning Process: The script will unmount the SD card and write the dump file to it.
- Progress Display: The
dd
command will display progress information during the burning process. - Completion: Once completed, the SD card will be ejected.
This option combines both Option 1 and Option 2:
- Select the Source SD Card: Follow the steps from Option 1 to create a dump.
- Insert Destination SD Card: Follow the steps from Option 2 to burn the dump to a new SD card.
- Caution: The script uses the
dd
command, which can overwrite any disk if used incorrectly. Ensure you select the correct disk identifiers to avoid data loss. - Administrative Privileges: You will be prompted for your administrator password when required.
- Progress Visualization: The script uses
status=progress
withdd
to display the progress. This requires a version ofdd
that supports this option (available in recent macOS versions). - Alternative Progress Visualization: If
status=progress
is not supported, you can installpv
(Pipe Viewer) and modify thedd
commands accordingly. - Compression (Optional): You can modify the script to compress the dump file using
gzip
orxz
to save disk space.
- dd Command Not Found: Ensure that you are running the script on macOS and have the necessary command-line tools installed.
- Permission Denied: Make sure you have executable permissions for the script (
chmod +x clone_sd.sh
) and run it with the necessary privileges. - Incorrect Disk Identifier: Double-check the disk identifiers using
diskutil list
before confirming to prevent accidental data loss.
Use this script at your own risk. The author is not responsible for any data loss or damage caused by misuse of this script. Always ensure that you have backups of important data and double-check disk identifiers before proceeding.
This script is provided under the MIT License.