📜 ⬆️ ⬇️

Forwarding block devices to a XenServer virtual machine

In the modern world, probably all adequate system administrators of corporate networks use virtualization. For small and medium businesses, one of the most sensible choices of the hypervisor is the free version of Citrix XenServer . Its main advantage for a small company that does not have the ability to buy hardware for tasks is a huge flexibility , largely due to Linux, on which the designated hypervisor is based.

The biggest problem XenServer, like the Xen Cloud Platform, is in very limited documentation. More precisely, in its absence for non-standard situations. In particular, nowhere in official sources did I manage to find instructions for forwarding a block device directly to a virtual machine .

For starters, why it may be necessary. The simplest example is that you have a server without a reliable hardware RAID controller. But you want a raid. No problem - Linux (and XenServer) contains a great thing - mdadm. And you need this RAID for file storage, and the file storage will take all the available space. It makes no sense to fence the RAID, and on top of that you still need to do XenServer StorageRepository (SR) with type = lvm, in which there is no one single disk for the entire volume. It is much better to create a RAID, and forward its block device directly to a virtual machine. It is also more reliable - in which case you can always get the hard drives from the server and stick them into any Linux machine that will immediately see all your data.
')
In general, we turn to practice. XenServer supports SRs such as udev . Its main purpose is to support external USB drives and forward them to virtuals. This type of SR works is extremely simple: all block devices found in a folder act as VDI (Virtual Device Image). In this case, VDIs are created automatically when scanning SR , all you have to do is to add them to the necessary virtual machines.

Since there is no difference what type of block device in Linux to use, and the flash drive is no different from the mdadm array and LVM volume, you can manually create an SR with type udev and manually add a symlink to it on the block device we need. For example, on the array md0 .

To begin with, we create a directory in which there will be symlinks on the block devices we need:

mkdir /srv/block-devices 

Now make it an udev SR with content-type = disk :

 xe sr-create name-label="Block devices" name-description=" ,       " type=udev content-type=disk device-config:location=/srv/block-devices 

Add the device we need:

 ln -s /dev/md0 /srv/block-devices/md0 

Then rescan SR to automatically create the necessary VDI :

 xe sr-scan uuid=<uuid__SR> 

There should be a new VDI with the name-label "Unrecognized bus type" on our SR . You can verify this with the command

 xe vdi-list sr-uuid=<uuid__SR> 

Ok, all that's left to do is change the name and description of this VDI and attach it to the right machine. This can be done already through XenCenter . By the way, do not be afraid, SR and VDI created in this way will not disappear anywhere after a reboot and will not change their parameters.

That's all. It is a little strange that there is not a word about such a primitive method in the official documentation.

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


All Articles