Tuesday, 19 March 2013

Creating a disk image over the network

Before I start this post I think I ought to make clear that the setup I'm testing this on has 3 physical servers, 2 of which are in use and can't be taken down for more than a few seconds the 3rd is a big box of disks that I have put in place for storing the disk images and initial hosting of the Virtual machines. Once the 2 servers are virtualised I will be re-installing them as virtual hosts too. Maybe when I do that I'll detail how I did that bit too.

So I have got to the point where I need to move some physical servers into virtual machines. The first "issue' I have come across is that I need to get an image of the server to convert into a VM. I figured I could pull the disks from the physical box and put them in the one which will host the images or I could make the image on a usb drive and move it that way. Both these options however didn't quite seem right to me.

I hit upon the idea of creating the image and copying it directly over the network to the image machine no double handling of data, no downtime (although I'm sure some people will not like the idea of imaging a disk whilst it's live).

The command that did this for me is

dd if=/dev/cciss/c0d0 | ssh garethw@192.168.0.50 dd of=/home/garethw/server1-c0d0.img

dd if=/dev/cciss/c0d0 | ssh garethw@10.0.8.10 dd of=/srv/vhost1/finder-server-3/c0d0-v2.img


Backing up a 300gb drive over a 1gb network took about 8 hours.... oh eck.

There are a few examples of this kind of thing on the net most of which include gziping the stream from dd. I'm not sure if the vm software I'm using supports gzipped images so I left that out. It seemed to give about a 1/3 speed increase when copying with gzip though so it's probably worth it if it works.

The next thing to do is import the newly created disk image into your VM infastructure. I am using ubuntu with KVM as setup using the ubuntu server documentation (It's over Here)

The following line should import the disk and should only take a couple of seconds to run
virt-install -n vm1-svr3 -r 512 --disk   ./c0d0-1.img,device=disk,bus=virtio -w   bridge=br0,model=virtio --vnc --noautoconsole --import

This command should also start the vm for you. Be warned, if everthing is working this will mean the vm comes up with the same IP as the physical server so be sure you are ready to go or disconnect the network from your vm host before starting it.

Handy commands;
 virsh list
lists all the currently running vms, it does not list those that are not running

 virsh destroy vmname
Will unload the vm from memory, it does not (as the name suggests) destroy anything.

virsh vncdisplay vmname
show you which vnc "port" the VM is running on so you can connect to it remotely (after fixing the vnc binnd issue)