Clone RPi

From XPUB & Lens-Based wiki
Revision as of 17:48, 8 March 2017 by Andre Castro (talk | contribs)

Cloning a Raspberry Pi disk onto a image file can be quite useful, as it will safe you the time of installing the whole system, applications, etc. And you can have a copy of an disk in an image, ready to be cloned onto another SD-card and ran.

the following steps will show how do this.

Resizing the partitions

Shutdown the Pi and remove its SD-card.

Insert the SD-card to you computer and run gparted software, as sudo.

Select the SD-card (/dev/mmcblk/)

raspberry_pi_device-menu-2.png

Select the larger partition (the one with loads of empty space) and reduce the empty space, leaving a bit of empty space (around 2000 MB) for temporary files,caches,log files,etc.

raspberry_pi_root-resize.png

raspberry_pi_root-resize-2.png

When done close the Gparted

Clone

from SD-card to image file

sudo fdisk -l /dev/mmcblk0

Will give the length of each partition, in my case it is:

Disk /dev/mmcblk0: 3.8 GiB, 4025483264 bytes, 7862272 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: 0x0004a452

Device         Boot Start     End Sectors  Size Id Type
/dev/mmcblk0p1         16   97727   97712 47.7M  b W95 FAT32
/dev/mmcblk0p2      97728 3766271 3668544  1.8G 83 Linux

The "Start" and "End" units are sectors, and notice the sector size is given, 512 bytes.

You can start cloning using the dd cloning tool, the sector (or block size) bs and <>count</count> with the unit + 1. Cloning the SD-card (/dev/mmcblk0) to an image file (rpi.img).

sudo dd if=/dev/mmcblk0 of=rpi.img bs=512 count=3766272

When done eject the SD-card

from image file to card

Insert the new card, to where you'll clone the image

sudo dd bs=4M if=rpi.img of=/dev/mmcblk0

Once done,

  • eject the new card
  • insert it in the Pi
  • connect the network port
  • power the Pi

If all is good you will see crazy blinking leds. Wait for the them to stop and look for the Pi's IP address with

nmap -sP 192.168.1.1-255