Rate this page del.icio.us  Digg slashdot StumbleUpon

Tips and tricks: How do I use the “xm block-attach” command to attach additional storage (like USB drive) to my running para-virtualized Xen guests?

by The editorial team

Contributed by Chris Lalancette and Eduardo Damato

Release Found: Red Hat Enterprise Linux 5

The xm block-attach command can be used to add additional storage to a running para-virtualized Xen guest. To ensure this succeeds, use the xvd device as the frontend device, and NOT sd or hd. For instance, the following command:

# xm block-attach  /var/lib/xen/images/disk2.img /dev/xvdb w

will export the file /var/lib/xen/images/disk2.img as /dev/xvdb inside the guest. The last parameter is the mode for exporting the disk. There are 3 modes currently available: r for read only, w for read/write, and w! for read/write with sharing.

Red Hat’s customer service and support teams receive technical support questions from users all over the world. Red Hat technicians add the questions and answers to Red Hat Knowledgebase on a daily basis. Access to Red Hat Knowledgebase is free. Every month, Red Hat Magazine offers a preview into the Red Hat Knowledgebase by highlighting some of the most recent entries. The information provided in this article is for your information only. The origin of this information may be internal or external to Red Hat. While Red Hat attempts to verify the validity of this information before it is posted, Red Hat makes no express or implied claims to its validity.

5 responses to “Tips and tricks: How do I use the “xm block-attach” command to attach additional storage (like USB drive) to my running para-virtualized Xen guests?”

  1. polasure says:

    How could I find the file disk2.img? In fact, there is no file in this directory /var/lib/xen/images/

  2. Laurentiu Coica says:

    I think that the correct syntax for xm block-attach is
    xm block-attach file://path/to/images.dsk

    For creating disk image, use something like:
    dd if=/dev/zero of=/path/to/image.dsk bs=1024k count=8192
    (for 8 Gb image size)

  3. polasure says:

    In fact, I found that “xm block-attach 1 phy:/dev/sde xvdb w” can work for para-virtualized Xen guests, but not for full-virtualized Xen guests.

    I also tried the commands as you said, but still failed.

    Hope for your help! Thank you!

  4. polasure says:

    In this conmmand: xm block-attach 1 phy:/dev/sde xvdb w
    1 is the ID of the guest.

  5. Chris says:

    Keep in mind that if you want to mount a tap:aio volume on dom0 that you likely need to run “modprobe xenblk” to load the blkfront driver first.

    Then you can run something like “xm block-attach 0 tap:aio:/var/lib/xen/images/server.img /dev/xvda w”, which will create the /dev/xvda device(s) which can then be mounted (if LVM is used then “vgchange -a y” and “vgmknodes” need to be run to make the volumes appear in /dev).

Leave a reply