Back to Home

Forwarding block devices to the XenServer virtual machine

XenServer · citrix xenserver · xen cloud platform

Forwarding block devices to the XenServer virtual machine

    In the modern world, probably all adequate system administrators of corporate networks use virtualization. For small and medium-sized businesses, one of the most meaningful choices of a 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 huge flexibility , largely due to Linux, on which the designated hypervisor is based.

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

    To begin with, why might this be needed. 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 cleaning, and file cleaning will take up all available space. It makes no sense to fence RAID, and on top of it still make XenServer StorageRepository (SR) with type = lvm, in which there is no one single drive for the entire volume. It is much better to create a RAID, and to forward its block device directly into the virtual machine. It’s more reliable - in which case you can always get the hard drives from the server and stick them in any Linux machine that will immediately see all your data.

    In general, let's move on to practice. XenServer supports this type of SR as a udev. Its main purpose is to support external USB drives and forward them to virtual machines. This type of SR works extremely simply: all the block devices found in a folder act as VDI (Virtual Device Image). At the same time, VDIs are created automatically when scanning SR , you just have to add them to the necessary virtual machines.

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

    First, create a directory in which there will be symlinks to the block devices we need:

    mkdir /srv/block-devices

    Now make it a udev type 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 pereskaniruem the SR , in order to automatically create the necessary the VDI :

    xe sr-scan uuid=

    A new VDI should appear with the name-label “Unrecognized bus type” on our SR . You can verify this with the command

    xe vdi-list sr-uuid=

    Ok, all that remains to be done is to change the name and description of this VDI and attach it to the desired machine. You can do this already through XenCenter . By the way, do not be afraid, the SR and VDI created in this way will not disappear 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.

    Read Next