Sunday, 23 December 2012

Copy a hard disk between PC's

This is a variation on this post.

I use this when I have a machine that I want to convert to a virtual machine in cases where VMWare Converter is unsuitable. eg FreeBSD


1) Ubuntu LiveCD x 2 or a CD and an ISO image
2) A pre made virtual guest machine with a virtual HDD of sufficient size.
3) A working network connection between the two. You should also note down the ip address of the target machine

Step 1:
Boot both the source machine and the new virtual machine off the LiveCD. Choose "Try Ubuntu without changing my computer"

Step 2:
Partition the virtual hard disk on the target PC using fdisk or gparted. Make sure you use the correct partition type ie: FreeBSD

Step 3: (logged in as root on the virtual machine)
Start the netcat client listening on port 5000 and pipe its output to the virtual hdd (via gunzip)

nc -l -p 5000 | gunzip | dd of=/dev/sda1

Step 4: (logged in as root on the physical machine)
Do a dd of the source drive and pipe its output to nc using port 5000 (via gzip)

dd if=/dev/sda1 | gzip -1 | nc hostip 5000

You can increase the amount of compression done by gzip to a maximum of 9 but if you are using slow CPU's and a fast network then this can actually make the whole transfer slower. Feel free to experiment yourself.

No comments: