Cloning disks or partitions using dd
Home > CentOS > CentOS 6.x > Dd > Cloning disks or partitions using dd
We can backup entire hard-disk or partition or clone hard-disks using dd and nc command combinations. To clone hard-disk from one machine to another we can use:
On destination machine:
- Boot using Linux live CD
- If Live CD is cached in RAM then use 'eject /dev/scd0' to eject cd
- Use 'dhclient eth0' to get IP from DHCP server. Note that IP address obtained.
- Start data receiver using:
- nc -l -p 9000 | dd of=/dev/sda bs=40000000
On source machine:
- Boot using Linux live CD
- If Live CD is cached in RAM then use 'eject /dev/scd0' to eject cd
- Use 'dhclient eth0' to get IP from DHCP server. Note that IP address obtained.
- Start data sender using:
- dd if=/dev/sda bs=40000000 | nc <IP_of_destination> 9000
Note:
- The above process can also be used for copying VM images from one machine to another machine. Copying sparse VM images would cause ballooning on destination. Then we can use 'cp --sparse=always' to reduce the ballooned image to normal size if required. It should be noted that this finishes faster than rsync with '-Sz' combinations
- If network is slow (Internet or 100mbps) then use "gzip -4" at source and use "gunzip -4" at destination.
Seeing progress
To see progress of how much data is copied we can use:
ps -C dd while true; do kill -USR1 <process_id>; sleep 1; done
on any of source and destination. In case source is serving multiple destinations than preferably do it on destination.
Performance
It is better to use udpcast in case you want to copy same source to more than one destinations
When using same source to copy data to three destinations parallely, try to start source to send data to all three soon one after other. If there is large gap while trying to send same data to three destinations the data read from hard-disk into RAM cache may get replaced and hence require re-reading of hard-disk. This may lead to hard-disk becoming bottle-neck and not network. It was observed that copying to more than three destinations at same time does not works well and causes machines to hang for some unknown reason.
Home > CentOS > CentOS 6.x > Dd > Cloning disks or partitions using dd