Skip to content

Instantly share code, notes, and snippets.

@jmsaavedra
Last active July 24, 2017 23:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jmsaavedra/d8375a91f24b8ed15282 to your computer and use it in GitHub Desktop.
Save jmsaavedra/d8375a91f24b8ed15282 to your computer and use it in GitHub Desktop.
raspberry Pi SD card formatting and image copying

SD CARD IMAGE COPY AND RESTORE


great for RaspberryPi disk imaging and copying.

LOCATE AND UNMOUNT DISK

insert SD card into computer. to see all volumes mounted to machine:

$ diskutil list

locate your SD card. going forward, change {N} to your disk number.

unmount (but don't eject) the disk you’re speaking to

$ diskutil unmountDisk /dev/disk{N}

CREATE AN IMAGE OF EXISTING SD CARD

$ sudo dd bs=1m if=/dev/rdisk{N} of=/Users/Desired/Path/To/Image/rpi_image_new.dmg

FORMAT YOUR EXTERNAL VOLUME

format the disk to FAT32

$ sudo newfs_msdos -F 32 /dev/disk{N}

FLASH PRE-EXISTING IMAGE

execute the dd utility.

  • change the if (infile) path to the path of your image.
  • for the of (outfile) make sure you use the disk number with r in front (rawdisk).
    $ sudo dd bs=1m if=/Users/Path/To/Existing/Image/rpi_image.dmg of=/dev/rdisk{N}

note: you can check the progress of the by hitting ctrl + t. be careful to not accidentally quit the process (ctrl + c) or you will need to execute the command again.

EJECT THE DISK

after imaging or writing any external volume, you'll want to safely eject the disk.

$ diskutil eject /dev/disk{N}

credit: chris piuggi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment