Citrix Xen Recover VDI UUID - jasonbeitler/www GitHub Wiki

Back Story

This post came about when we had a hard drive fail in our NAS, then during the rebuild of the raid a second drive crashed. Yes it was a very very bad day. I spend the next 3-4 days recovering data and getting everything back up and running.

Little back story - At the time we had backups of data, but due to budget restraints we did not have full VM backups. The following is how I was able to map VDI's back to VM's.

If you have ever migrated from ESX to Citrix Xen, then you might have noticed that VDI names come across as is. In ESX when you create a VM it creates a folder and with in that folder you have a few files, mainly the machine_name.vmx and Hard Disk1.vmdk. If you every have to restore them from a backup it is pretty easy to map them back.

When using Citrix Xen, this does not happen for ova / ovf imports. When you import an ova / ovf into Citrix Xen it keeps the .vmdk name from ESX. If you have a few VM's you end up with something like this.

Xen VHD View

Now if you remember exctally which machines had what disk size you might be able to map them easily. However odds say that will be rather difficult. Just because the VHD is 30GB does not mean it will map back to VM 30GB HDD, this is because of dynamic provisioning of HDD's.

Now the fun part, when you look at the VHD Store in Citrix Xen you dont see Hard Drive1 as the name. That would make this way way to easy. No instead you see something like this

021a205b-6dd6-4735-9cf3-18567730cbc9.vhd 6f82f7b9-ad26-41c5-928b-21fd8bd06951.vhd 121e66b6-600b-4c87-b787-1b44ff32a663.vhd 761e17dd-9a11-499e-9235-e00c79080c99.vhd 19808c74-3241-450d-b11f-e661fc18478e.vhd

Now you are scratching your head right. How the bloody hell am I going to map Hard Disk1.vhd back to 021a205b-6dd6-4735-9cf3-18567730cbc9.vhd? Well that part is rather easy, but not very obvious.

Mapping to VDI's

Now there are a few commands you can use to pull some info from Citrix Xen in the cli.

  1. $xe vm-list
  • This just gives you the list of VM's and their UUID, not very helpful
  1. $xe sr-list
  • This only gives you SR's and their UUID, not helpful again
  1. $xe vbd-list
  • And we have a winner, this gives us exactly what we need.

Samle output of vbd-list

uuid ( RO) : e33a6433-d31f-8a92-6145-6d0370ff0f6c vm-uuid ( RO): 3afba9ea-c9c4-4cc3-92d0-6a916f872a3b vm-name-label ( RO): Machine Name vdi-uuid ( RO): c6c4cc52-4479-49b8-bdb4-d094412aaaae empty ( RO): true device ( RO): xvdd

I will take a break here so you can get a pen, some paper and maybe coffee. Moving forward you will need to take some notes.

Now the long boring part

Now that you have machine names + vdi-uuid you can play the migrate game, but you need to be carful here as well. If you mess this part up you will back to square one. For now leave the old vdi's in the old SR and follow these steps, very closely.

  1. Identify which vdi you want to move first
    • Only do one at a time trust me
  2. Create a new VM with the same specs and place the new vdi in the new SR
  3. Look at the new vdi-uuid from the new SR and make note of the uuid
  4. Move the old vdi to the new SR
  5. From the CLI you will move the old vhd to the new vhd
    • Example
      • old uuid equals - 272626748u2yt6ye6.vhd
      • new uuid equals - 362637uu626yfyu63.vhd
      • $mv 362637uu626yfyu63.vdi 272626748u2yt6ye6.vhd
  6. Now try to boot the new VM
    • If it boots to the old OS you are good to go.. for that VM. Now repeat the above steps for all vdi's

You might be asking "Why the hell do I have to do all of this just to migrate a vdi?". Well that is a valid question.

Citrix Xen mapps uuids of vdi's to vms, if the vdi-uuid does not match it will not work. So you have to trick Citrix Xen into thinking it is using the correct vdi. Yes it is a pain compared to ESX, but with all the cool free things you can do with Citrix Xen vs ESX this is just a small hiccup that is easy to fix once you know how it works.