Skip to content

Instantly share code, notes, and snippets.

@dakridas
Last active December 20, 2017 19:51
Show Gist options
  • Save dakridas/7b8f8dbf7858c4a7610bd8e5f571b579 to your computer and use it in GitHub Desktop.
Save dakridas/7b8f8dbf7858c4a7610bd8e5f571b579 to your computer and use it in GitHub Desktop.
Copy a Raspberry Pi image from the sd card to your host
  1. Insert the Pi's SD card to host

  2. Find the device of the SD card with

sudo fdisk -l

For MacOS you can use the command

diskutil list

For a pc with one physical disk, the output will be look like this

da@agile images$ sudo fdisk -l
Disk /dev/sda: 931.5 GiB, 1000204886016 bytes, 1953525168 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: dos
Disk identifier: 0xd1654e20

Device     Boot      Start        End    Sectors   Size Id Type
/dev/sda1  *          2048 1936928767 1936926720 923.6G 83 Linux
/dev/sda2       1936930814 1953523711   16592898   7.9G  5 Extended
/dev/sda5       1936930816 1953523711   16592896   7.9G 82 Linux swap / Solaris

Partition 2 does not start on physical sector boundary.

Disk /dev/sdb: 14.9 GiB, 15931539456 bytes, 31116288 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xfea8d6fe

Device     Boot Start      End  Sectors  Size Id Type
/dev/sdb1        8192    93596    85405 41.7M  c W95 FAT32 (LBA)
/dev/sdb2       94208 31116287 31022080 14.8G 83 Linux

To track the device of the sd card check the disk size. If your sd card is 16 GB (like mine) then the /dev/sdb is the device we looking for.

  1. Copy the image to the host with dd program. Be careful! If there is already an image named as of argument (raspimage.img in our case) this commands will overide this image.
sudo dd bs=4M if="/dev/sdb" of="raspimage.img" status=progress conv=fsync
  1. Now your have the raspberry image to your host. You will notice that the size of the image is too large. Your can reduced it with a programm like PiShrink
git clone https://github.com/Drewsif/PiShrink
cd PiShrink
./pishrink raspimage.img
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment