Clone RPi: Difference between revisions

From XPUB & Lens-Based wiki
 
(7 intermediate revisions by the same user not shown)
Line 1: Line 1:
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.
Cloning a Raspberry Pi disk onto a image file can be quite useful, as it will spare you from installing the whole system, applications, and configuration files that you set up for a specific project, using the Raspberry Pi.  
 
By cloning the Raspberry file-system, contained in the SD-card to and image file, you'll have a copy of an disk in file, ready to be cloned onto another SD-card and ran.


the following steps will show how do this.
the following steps will show how do this.
Line 36: Line 38:
/dev/mmcblk0p2      97728 3766271 3668544  1.8G 83 Linux
/dev/mmcblk0p2      97728 3766271 3668544  1.8G 83 Linux
</pre>
</pre>
What to look for:
* '''Start''' and '''End''' units are sectors,
* '''sector size''' is  512 bytes


The "Start" and "End" units are sectors, and notice the sector size is given, 512 bytes.
To clone use the <code>dd</code> cloning tool.
 
* The sector (or block size) <code>bs</code> will be the value of the '''sector size'''
You can start cloning using the <code>dd</code> cloning tool, the sector (or block size) <code>bs</code> and <code>count</code> with the unit + 1. Cloning the SD-card (/dev/mmcblk0) to an image file (rpi.img).   
* <code>count</code> will be given the '''End''' of the last device (/dev/mmcblk0p2) + 1: 3766271+1 .  
* <code>bs=512</code> is the '''sector size'''
* <code>if=/dev/mmcblk0</code> from /dev/mmcblk0
* to image file (rpi.img) <code>of=rpi.img</code>  
  sudo dd if=/dev/mmcblk0 of=rpi.img bs=512 count=3766272
  sudo dd if=/dev/mmcblk0 of=rpi.img bs=512 count=3766272


When done eject the SD-card
When done eject the SD-card and you'll have your Raspberry Pi image clone to a file


==from image file to card==
==Clone: from image (file) to card==
Insert the new card, to where you'll clone the image
Insert the new card, to where you'll clone the image


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


==expand file-system==
using gparted you can enlarge the partition we shrunk while making the img in [[#Resizing the partitions]].
== Test ==
Once done,  
Once done,  
* eject the new card
* eject the new card
Line 54: Line 66:
* connect the network port
* connect the network port
* power the Pi
* 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
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
  nmap -sP 192.168.1.1-255
Once you have found the Pis IP address ssh into it.
ssh root@pi.ip.address
And expand the file-system with raspi-config, since in the image we reduced the empty space of the partition.
raspi-config
Expand and reboot.
Cloned image is there.


[[Category:Cookbook]] [[Category:RaspberryPi]]
[[Category:Cookbook]] [[Category:RaspberryPi]]

Latest revision as of 18:19, 16 January 2018

Cloning a Raspberry Pi disk onto a image file can be quite useful, as it will spare you from installing the whole system, applications, and configuration files that you set up for a specific project, using the Raspberry Pi.

By cloning the Raspberry file-system, contained in the SD-card to and image file, you'll have a copy of an disk in file, 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

What to look for:

  • Start and End units are sectors,
  • sector size is 512 bytes

To clone use the dd cloning tool.

  • The sector (or block size) bs will be the value of the sector size
  • count will be given the End of the last device (/dev/mmcblk0p2) + 1: 3766271+1 .
  • bs=512 is the sector size
  • if=/dev/mmcblk0 from /dev/mmcblk0
  • to image file (rpi.img) of=rpi.img
sudo dd if=/dev/mmcblk0 of=rpi.img bs=512 count=3766272

When done eject the SD-card and you'll have your Raspberry Pi image clone to a file

Clone: 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

expand file-system

using gparted you can enlarge the partition we shrunk while making the img in #Resizing the partitions.

Test

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


Once you have found the Pis IP address ssh into it.

ssh root@pi.ip.address

And expand the file-system with raspi-config, since in the image we reduced the empty space of the partition.

raspi-config

Expand and reboot.

Cloned image is there.