📜 ⬆️ ⬇️

Wars with Citrix XenServer

Introduction


The other day, my employee accidentally deleted several virtuals in Citrix XenServer.
Everything was complicated by the fact that virtual machines were on a snapshot disk.
Under the cut, I tell you how I took them out of there in the absence of any backups and transferred them to KVM.
I did not do a lot of command examples, since the purpose of the article was to describe the concept. Below cited the necessary links.


Training


I took the hard drives myself, put it on a test machine.
Loaded xen did not want, went into a cyclic reboot.
Consequently, I had to download the new version and install it on another disk.
Download, install. Next, it was necessary to connect the old drives.
Xen was in the most standard configuration, virtualka on LVM.

First disappointment


All articles say that LVM in XenServer should back up changes to daddy
/etc/lvm/archive

But it was not there. In version 5.5 in the LVM config, automatic saving is turned off.
Fortunately, I have already dealt with LVM and I know that it stores copies of data in the initial blocks of PV.
')
Using the command:
dd if=/dev/sda3 bs=512 count=255 skip=1 of=./lvmbackup.img
copied the first blocks of the section

With vim, this picture can be perfectly open and pull out the necessary information.
There by the way you can see a lot of configurations. The last but one came up to me. Since the previous ones did not have the necessary sections yet, and in the following ones already!

And so, having found the necessary configuration piece, I tore it out and copied it into a new file.
Then, reformatting it a little and, if I'm not mistaken, changing the uuid of the physical partitions, I got the working lvm configuration of the volume.

After that, in the / etc / lvm / backup folder, I replaced the lvm group description file with my own.
And launched vgcfgrestore with the name of the group.
It is not strange but all sections are hooked.

Second disappointment


And so, joyful that everything I had successfully got, and the disks are seen, I am trying to hook this storage in XenServer.
I did not expect such a breakup. SR connection is successful. Not a single mistake. But! Disks are seen only those that have not been deleted. No deleted.
The lvs team also showed only new discs. That is, XenServer found somewhere a repository description.
There is nothing to do, I restore lvm a second time. (To be honest, I did it 10 times until I realized that Zen considers disks to be remote and does not want to see them at all)
The same thing was complicated by the presence of snapshots from these disks.

proper restoration


At about 10 pm I received insight that the LVM volume of the server's zen is nothing but VHD disks.
Armed with a notepad and vhd-util, I recorded the data on the parents of all snapshots. Snapshots in Zen server are differential VHD drives.
Further dd in files of all necessary volumes.

After that, the vhd-util check check showed that all the checksums are correct and the files are working.
Through the same utility, I pointed out new parents to snapshots and started merging (coalesce parameter).

Here, by the way, I still have a question: when creating one snapshot, the zen makes 2 differential disks. One is the size of the original, and the second is very small. It was enough for me that the size of the original. Small did not merge.

Final stage


Transferring files to the server with KVM I tried to feed him vhd. He naturally did not eat him.
But I was helped out by the qemu-img utility which didn’t convert the raw files to me very well.

In general, all is well that ends well. Now users work well.
Please do not kick much - the first experience of an article on Habré.

About the lack of backups - their absence is not an accident, and not negligence.

VHD for xen is a little different and you can’t connect them directly to Hyper-v, you also need to convert.

Links


  1. How to Reinstall XenServer and Preserve Virtual Machines on a Local Disk
  2. Linux LVM: Recovering a lost volume.
  3. Qemu disk image conversion


Thank you for your attention!

Source: https://habr.com/ru/post/141870/


All Articles