Technical Resources for Technical People
Header

SATA Direct Local Disk Access on Xenserver

July 8th, 2011 | Posted by techblog in Linux | Virtualization

There are several reasons why you may wish to attach a physical disk to your existing Xenserver installation, in our case we use it for both a permanent storage solution as well as moving large sets of data around (such as copying out virtual disks or data intensive backups). It’ll treat the SATA (or better yet eSATA) disk similarly to plugging in an external USB drive to the Xenserver host, but at much higher throughput.

One of our servers utilizes a 3 disk RAID5 array which is primarily used for VM and VM data storage. However we do have a NAS virtual machine that stores quite a lot of backup data; and rather then use up a bunch of space on our RAID array and subsequently have to transfer the data off again anyways, we prefer to use a single hard disk formatted in EXT3. This disk can be treated like any typical hard disk data store and is not Xenserver dependent. Once the drive reaches capacity, we can detach from the virtual machine, pull it out and swap in a new one.  (And of course mount it on any Linux box and access the data directly).

In order to get Xenserver to recognize the SATA drive we’ll need to create some symbolic links in the hypervisor’s /dev/xapi/block directory by editing the /etc/udev/rules.d/50-udev.rules file. (The udev daemon in the kernel properly abstracts USB and SATA while placing the appropriate node into the /dev directory).

Using /dev/sdb as the drive we wish to attach, add the following lines to /etc/udev/rules.d/50-udev.rules which are modified from similar USB mass storage detection rules.

ACTION=="add", KERNEL=="sdb", SYMLINK+="xapi/block/%k", RUN+="/bin/sh -c '/opt/xensource/libexec/local-device-change %k 2>&1 >/dev/null&'"
ACTION=="remove", KERNEL=="sdb", RUN+="/bin/sh -c '/opt/xensource/libexec/local-device-change %k 2>&1 >/dev/null&'"

You can add additional lines for additional devices (such as sdc, sdd) if you wish.

Save and reboot Xenserver. Your attached SATA hard disk should now be recognized as a removable storage device, which can now be attached to a virtual machine via the XenCenter console. It’ll be using an emulated SCSI controller instead of USB, which means full read/write throughput! Don’t forget to attach/detach the drive via XenCenter to/from the VM of your choice – while it’s physically “hot swapable”, you can’t just yank the physical drive out of a running VM that’s using it.

This change will be persistent through reboot, but remember that any product updates to the core Xenserver installation will likely overwrite these modifications, please bookmark this page for future reference.

 

You can follow any responses to this entry through the RSS 2.0 You can leave a response, or trackback.

46 Responses

  • Andy says:

    Works in XenServer 8.2

    They have /etc/udev/rules.d/58-xapi.rules now, but it has a bug so that my USB device isn’t detected as USB. So I added -60 as per the post.

    Use udevadm control –reload-rules to avoid reboot, and udevadm trigger –action=add /dev/sda to avoid reinsertion. The drive is a fairly strange USB3 Bulk Transpared SCSI (so not UAS if I understand correctly). Appears as SCSI:8:0:0:0 in Removable Storage.

  • Michael says:

    in XenServer 7 it is differently. In file: /etc/udev/rules.d/59-udev.rules

    touch /etc/udev/rules.d/59-udev.rules

    and add lines like this for each disk (here sdc to sdf):

    ACTION==”add”, RUN+=”/bin/sh -c ‘mkdir -p /dev/xapi/block/'”
    ACTION==”add”, RUN+=”/bin/sh -c ‘ln -s /dev/sdc /dev/xapi/block/'”
    ACTION==”add”, RUN+=”/bin/sh -c ‘ln -s /dev/sdd /dev/xapi/block/'”
    ACTION==”add”, RUN+=”/bin/sh -c ‘ln -s /dev/sde /dev/xapi/block/'”
    ACTION==”add”, RUN+=”/bin/sh -c ‘ln -s /dev/sdf /dev/xapi/block/'”

  • Chris says:

    For Xen Server 7.0 this did not work. However,

    touch /etc/udev/rules.d/59-udev.rules

    and I added to its line:
    ACTION==”add”, RUN+=”/bin/sh -c ‘mkdir -p /dev/xapi/block/'”
    ACTION==”add”, RUN+=”/bin/sh -c ‘ln -s /dev/sdc /dev/xapi/block/'”
    ACTION==”add”, RUN+=”/bin/sh -c ‘ln -s /dev/sdd /dev/xapi/block/'”
    ACTION==”add”, RUN+=”/bin/sh -c ‘ln -s /dev/sde /dev/xapi/block/'”
    ACTION==”add”, RUN+=”/bin/sh -c ‘ln -s /dev/sdf /dev/xapi/block/'”

    worked

  • Spock says:

    Hi, has anyone have any success on xenserver 7.0? There is no /etc/udev/rules.d/50-udev.rules files in version 7. I added the file with the above, reboot, and no removable drive. Or is there new way to do this now? I am trying to move my fileserver to a vm, combining the fileserver with the xenserver. Thanks in advance!

  • Pingback: XenServer Whole Disk Passthrough - ODλ Zero Dispersion

  • Sebastian says:

    Hi, I have XP VM in XenServer6.5 I want connect to VM Sata Disk In RAW Format, (SCSI is a problem for me in this case)

    for me The most important part of this article is ” It’ll be using an emulated SCSI controller instead of USB” Is There ANY way to change its emulated controller driver and not use SCSI? I Prefeer to use SATA emulated controller or USB controller.

  • Clocky says:

    Not working on XenServer 7 – Unlicenced

  • Ed says:

    Any update for Xenserver 7?

  • Pingback: A Virtual Paradise | qbie.com



Leave a Reply

Your email address will not be published. Required fields are marked *