I've been working on this same issue. I've gotten this to work 2 different ways.
Setup
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
- Create an LV on
hostA
.
- Copy
ubuntu-14.04.1-server-amd64.iso
to /var/lib/libvirt/images
- On a client running Ubuntu Desktop, run
virt-manager
.
- Connect to
hostA
.
- Open the
Details
window and use the Storage tab to add the LVM volume group.
- Configure a new machine, using the install ISO, the LV for storage,
br0
for the network.
- Restart, etc., make sure your LV is running great.
Part B - Configure Replication
- Shut down the KVM guest system.
- Use
lvresize
to increate the LV size by 1 lun. lvresize -l +1 vg/guestlv
- Initialize the
drbd
metadata. drbdadm create-md /dev/vg/guestlv
- 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 192.168.2.1:7789;
disk /dev/vg/guestlv;
}
on hostB {
address 192.168.2.2:7789;
disk /dev/vg/guestlv;
}
}
- On
hostB
- create an identically-sized (the new +1 size!) LV, using the volume group and lv names as in the resource file.
- Run
drbdadm create-md /dev/vg/guestlv
- Run
drbdadm connect --discard-my-data guest
- Run
drbdadm up guest
- On
hostA
- Run
drbdadm up guest
- Run
drbdadm primary guest
Part C - Switch the drbd device into the KVM config
- On
hostA
, run virsh edit guestlv
- Find the line
<source dev='/dev/vg/guestlv'/>
and change it to <source dev='/dev/drbd1'/>
- Save and quit, start your VM, verify that it works. Shut it down.
- Wait for the
drbd
sync to finish.
- Run
drbdadm secondary guest
.
- On
hostB
, run drbdadm primary guest
.
- 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.
- 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
- Set up
/dev/drbd1
, get it syncing.
- Create a KVM guest using a junk volume for the storage, abort the install.
- Use
virsh-edit
to swap in the /dev/drbd1
storage.
- Start it up and run the install.
Sometimes this worked, sometimes I'd get a show-stopping error at grub installation to
/dev/vda
.
- If you do get it working, shut down the VM, swap the
drbd
primary & secondary, configure your other host, test, etc.