How to Clone Linux disk partition over network using dd

In this tutorial, we will show you how to clone Linux harddisk partition over a network, in this tutorial we will use dd command. For the guys who don’t know what dd is – it is a command-line utility for Unix and Unix-like operating systems whose primary purpose is to convert and copy files.

Clone Linux harddisk has advantages because we don’t need to reinstall and configure again the applications especially in Linux that we used as a server.

Prerequisites

This article assumes you have at least basic knowledge of Linux, know how to use the shell, root user or non-root user account with sudo privileges set up on your server.

For other prerequisites :

  • Linux with network interface.
  • Make sure 2 linux have same storage size.
  • Both 2 linux has been booted using rescue OS or other live OS , so you not boot using installed OS in the disk.

We will use description for our example:

Source

server-A : /dev/sda

Destination

server-B : /dev/sda

Warning: Make sure all command below are executed under your rescue’s operating system.

1. Clone disk partition using dd over SSH

To clone entire Linux disk partition using dd over ssh from server-A to server-B. Let’s assume you use root user.

Run this command in server A (source):

# dd bs=16M if=/dev/sda | ssh root@serverB "dd bs=16M of=/dev/sda"

If you want to clone some partition only, just choose the partition you want to clone like these command below, for example, we will clone /dev/sda3 partition

Run this command in server A (source):

# dd bs=16M if=/dev/sda3 | ssh root@serverB "dd bs=16M of=/dev/sda3"

2. Clone disk partition using dd over telnet with bzip compression

Clone using telnet and bzip has advantages to reduce clone time, but make sure you use a secure network.

Lets assume server-B has ip address 192.168.100.2. Run this command in server B (destination):

# nc -l -p 19000 | bzip2 -d | dd bs=16M of=/dev/sda

Run this command in server A (source):

# dd bs=16M if=/dev/sda | bzip2 -c | nc 192.168.100.2 19000

Based on these 2 commands above we will connect to server-B using port 19000.

Conclusion

You can choose 2 kinds of the method above, clone disk partition over a network is useful when you need to migration from different datacenter with same disk storage space.

Related Post