Clone RPi

From XPUB & Lens-Based wiki
Revision as of 18:25, 8 March 2017 by Andre Castro (talk | contribs) (Created page with "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 a...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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/)

https://cdn-learn.adafruit.com/assets/assets/000/032/661/medium640/raspberry_pi_device-menu-2.png?1464112076

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.

https://cdn-learn.adafruit.com/assets/assets/000/032/665/large1024/raspberry_pi_root-resize.png?1464112213

https://cdn-learn.adafruit.com/assets/assets/000/032/717/thumb160/raspberry_pi_root-resize-2.png?1464288970

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 a new card to where you'll clone the image

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