Skip to content

Latest commit

 

History

History
100 lines (64 loc) · 2.57 KB

clone-sd-card.md

File metadata and controls

100 lines (64 loc) · 2.57 KB

Clone and shrink a Raspberry Pi image

Raspberry Pi

WARNING The use of the dd tool can overwrite any partition of your machine. If you specify the wrong device in the instructions, you could overwrite your primary partition!

Linux

Determine SD device

First use fdisk to get the device id of you SD card (check the size):

sudo fdisk -l

Copy SD card using dd

Use the dd command to write the image to your hard disk:

time sudo dd if=/dev/sdb of=${HOME}/Downloads/rpi-clone.img && sync

The if parameter (input file) specifies the file to clone. In this example, it is /dev/sdb, which is the SD card's device name. Replace it with the device name of yours. The of parameter (output file) specifies the file name to write to.

macOS

Determine SD device

Connect the SD card reader with the SD card inside and run the following command:

diskutil list
/dev/disk0 (internal, physical):

/dev/disk1 (synthesized):

/dev/disk2 (external, physical):
    #:                     TYPE NAME    SIZE       IDENTIFIER
    0:   FDisk_partition_scheme        *31.9 GB    disk2
    1:           Windows_FAT_32 boot    268.4 MB   disk2s1
    2:                    Linux         31.6 GB    disk2s2

Copy SD card using dd

The disk must be unmounted before copying the image:

# This example uses /dev/disk2
diskutil unmountDisk /dev/disk2

Copy the image:

time sudo dd if=/dev/rdisk2 of=${HOME}/Downloads/rpi-clone.img && sync

Replace disk2 with the number that you noted before. Note the rdisk ('raw disk') instead of disk, this speeds up the copying.

Eject the SD card

After the dd command finishes, eject the card:

sudo diskutil eject /dev/rdisk2

Shrink the image using PiShrink-docker

PiShrink-docker automatically shrink a Raspberry Pi image in order to reduce the final image size.

  1. Install Docker following the Get Docker instructions.

  2. Using the Terminal, access the directory containing the Raspberry Pi image:

    cd ~/Directory-with-RPi-image
  3. Run PiShrink dockerized:

    docker run --privileged=true --rm \
        --volume $(pwd):/workdir \
        monsieurborges/pishrink \
        pishrink -Zv IMAGE.img NEW-IMAGE.img

References

[1] PiShrink by Drew Bonasera.

[2] PiShrink-docker by Monsieur Borges.