Virtualisation procedures

Introduction

This page lists various virtualisation-related small procedures mainly of use to the author.

Migrating VMs from an old one-legged cluster into a new one-legged cluster

This procedure assumes that torchio is the old one-legged cluster and fiori is the new one-legged cluster. Perform the procedure for each VM.

  1. Log in as root on a host with unfettered ssh access to the new virtualisation server (fiori).
  2. Download create-perfect-drbd-vol.
  3. Edit the following settings in the script:
    DRBD_CLUSTER_NODES=( fiori torchio )
    DRBD_CLUSTER_NODE_PRIVATE_LAN_IPS=( 192.168.3.6 192.168.3.7 )
    NODE_STATUSES=( up down )                #  note that we're migrating to fiori and that torchio is marked down!
    VOLGROUP="vg0"
    BASE_DEVICE_MINOR=0
    BASE_TCP_PORT=8790                            #  set this so that there's no danger of the new server talking to the old server
  4. Create a new DRBD volume by running:
    create-perfect-drbd-vol <vm-name> 20.01 fiori    #  fiori is the preferred immediately-primary server, 20.01 is because 20 is not always quite enough for 20!
  5. Create a VM using virt-manager, but
    1. use a dummy disk device instead of the DRBD device, which is currently empty (and one-legged)
    2. create additional vNICs as required, copying the MAC address from the running instance of the VM
  6. Start the VM (it will fail to boot but the installation step will be deemed successful and VM definition therefore persistent) and immediately shut it down again.
  7. Use virsh edit to change the disk definition to the DRBD device.
  8. Shutdown the old VM.
  9. Use dd+ssh+dd to read the old VM’s DRBD device and write it to the new VM’s DRBD device.
  10. Start the new VM.

Adding a second leg to a one-legged cluster

This procedure assumes that torchio is the old one-legged cluster and fiori is the new one-legged cluster. Perform the procedure for each VM.

  1. Log in as root on a host with unfettered ssh access to both virtualisation servers (fiori and torchio).
  2. Run:
    VMNAME=<vm-name>
    
    ssh -n fiori lvs --noheadings --units m 2>/dev/null | grep $VMNAME | while read LV VG FLAGS SIZE; do
        ssh -n torchio lvcreate --name=$LV --size=$SIZE $VG
    done
    scp -3 fiori:/etc/drbd.d/$VMNAME*.res torchio:/etc/drbd.d/
    ssh -n fiori virsh dumpxml $VMNAME | ssh torchio 'cat > /tmp/$$.xml; virsh define /tmp/$$.xml; rm -f /tmp/$$.xml
    ssh -n torchio "sed -rn 's@.*device +/dev/([^ ]+).*@\\1@p' /etc/drbd.d/$VMNAME* | xargs -n 1 drbdadm -- --force create-md"
    #  If you want to immediately sync then run this but read on first
    #ssh -n torchio "sed -rn 's@.*device +/dev/([^ ]+).*@\\1@p' /etc/drbd.d/$VMNAME* | xargs -n 1 drbdadm up"
    
  3. Like the comment in the code above says, it’s possible to sync each VM’s DRBD devices immediately, but syncing in serial might add less load.

See also