Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

i have two KVM servers with some virtual machines.

Server (A) KVM with qcow2 images

Server (B) KVM mount NFS for partiton (with qcow2 images present on server A).

My question is simple, what is the best solution for creating virtual disk copies on server B (with virtual machines running obviously). DRBD is one solution??

share|improve this question
up vote 2 down vote accepted

If you just want to replicate the server A qcow2 images on the server B, but they don't have to be accessed at the same time on both A and B, then you may use DRBD with any file system on it (like ext4), running as Primary on A and Secondary on B. When A fails you will be able to switch DRBD on B to Primary and use the images there.

In case you want those images available and used on A and B at the same time – then this will be more tricky. A clustered file system may help, but I don't think performance will be right.

If you just want to make a one time copy of the images, then just stop the VMs on A, copy the images with scp/rsync/over-NFS/whatever. If the VMs must be running on A, then, for a consistent image, you will need to make some kind of snapshot. I don't know KVM and QCOW2, but maybe they provide some snapshot functionality. If not, then LVM snapshots may have if you store the images on an LVM volume.

share|improve this answer
Thank Jacek, one last question, in first case: If you just want to replicate the server A qcow2 images on the server B, but they don't have to be accessed at the same time on both A and B, then you may use DRBD with any file system on it (like ext4), running as Primary on A and Secondary on B. When A fails you will be able to switch DRBD on B to Primary and use the images there. DRDB replicate the qcow images with VM running, is true? – Giovanni Bennelli Nov 15 '12 at 18:50
Yes. Each change made by the VM will be written to disk on both servers (unless DRBD is disconnected or not fully synced – both cases are no problem, as recovery by re-synchronisation is possible). – Jacek Konieczny Nov 15 '12 at 18:53
ok, is all clear, many thanks :) – Giovanni Bennelli Nov 15 '12 at 19:23
If you like my answer, would you up-vote and accept it, please? – Jacek Konieczny Nov 15 '12 at 19:56

Take a look at it will take you through the steps.

share|improve this answer

For high availability with virtual machines you can either Try Ganeti and DRBD as your resource but there will be little extra work in setting up the ganeti, but the pain would worth as it will make your VM management real smooth.

Another option that I could think of is using gluster volumes. It will be super easy to setup and install and if you have good hardware then performance should be good.

As of now I use simple DRBD style the way Jacek has explained, I am also exploring other ways as well.

share|improve this answer

I've been working on this same issue. I've gotten this to work 2 different ways.


I'm choosing to build my kvm guest systems on top of LVs using the raw format. I don't know that this is better than having them on image files on the LVs, but that's what I'm going with. It would be much simpler to use drbd to sync the LVM physical partition, but I want to run multiple LVs, and have one be running on hostA (requires drbd primary role) and the other on hostB (also requires drbd primary role). So I'm stuck unless I go to gluster, but I'm reluctant to adopt yet another technology at this point. My storage stack is already:

KVM guest
drbd (drbd1)
lvm2 logical volume (guestlv)
lvm2 volume group (vg)
lvm2 physical volume (crypt)
dm-crypt (crypt)
gpt partitions (md_d0p1=root, md_d0p2=swap, md_d0p3=crypt)
mirror-RAID (md_d0)
gpt partition (single)
hard drive (2)

The biggest issue I have to work around is that virt-manager won't recognize or let you work with drbd volumes (virt-install and vmbuilder don't work for me). So here's what I've done:

hostA and hastB are running Ubunut 14.04LTS, installed with the OpenSSH Server and Virtualization Host packages, with lvm2 and drbd8-utils also installed. Each has 4 NICS, bonded in pairs. bond0 is bridged to br0 and used by the guests, bond1 is not bridged and uses a subnet reserved for drbd.

KVM + DRBD Method 1

Part A - Create the KVM guest

  1. Create an LV on hostA.
  2. Copy ubuntu-14.04.1-server-amd64.iso to /var/lib/libvirt/images
  3. On a client running Ubuntu Desktop, run virt-manager.
  4. Connect to hostA.
  5. Open the Details window and use the Storage tab to add the LVM volume group.
  6. Configure a new machine, using the install ISO, the LV for storage, br0 for the network.
  7. Restart, etc., make sure your LV is running great.

Part B - Configure Replication

  1. Shut down the KVM guest system.
  2. Use lvresize to increate the LV size by 1 lun. lvresize -l +1 vg/guestlv
  3. Initialize the drbd metadata. drbdadm create-md /dev/vg/guestlv
  4. Create the drbd resource file. file:/etc/drbd.d/guest.res resource guest { device /dev/drbd1; meta-disk internal; startup { become-primary-on hostA; wfc-timeout 30; outdated-wfc-timeout 20; degr-wfc-timeout 30; } net { cram-hmac-alg sha1; shared-secret sync_disk; } syncer { rate 100M; verify-alg sha1; } on hostA { address; disk /dev/vg/guestlv; } on hostB { address; disk /dev/vg/guestlv; } }
  5. On hostB
    1. create an identically-sized (the new +1 size!) LV, using the volume group and lv names as in the resource file.
    2. Run drbdadm create-md /dev/vg/guestlv
    3. Run drbdadm connect --discard-my-data guest
    4. Run drbdadm up guest
  6. On hostA
    1. Run drbdadm up guest
    2. Run drbdadm primary guest

Part C - Switch the drbd device into the KVM config

  1. On hostA, run virsh edit guestlv
  2. Find the line <source dev='/dev/vg/guestlv'/> and change it to <source dev='/dev/drbd1'/>
  3. Save and quit, start your VM, verify that it works. Shut it down.
  4. Wait for the drbd sync to finish.
  5. Run drbdadm secondary guest.
  6. On hostB, run drbdadm primary guest.
  7. On your workstation, use virt-manager to create a new guest with some junk volume for the storage. Shut it down as soon as the install starts.
  8. On hostB, use virsh edit guestlv and set the storage to /dev/drbd1. Start the VM, verify that it works, etc.

KVM + DRBD Method 2 Very similar to the above, but

  1. Set up /dev/drbd1, get it syncing.
  2. Create a KVM guest using a junk volume for the storage, abort the install.
  3. Use virsh-edit to swap in the /dev/drbd1 storage.
  4. Start it up and run the install. Sometimes this worked, sometimes I'd get a show-stopping error at grub installation to /dev/vda.
  5. If you do get it working, shut down the VM, swap the drbd primary & secondary, configure your other host, test, etc.
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.