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.







August 28th, 2007 at 9:05 pm
How could I find the file disk2.img? In fact, there is no file in this directory /var/lib/xen/images/
August 30th, 2007 at 4:10 am
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)
September 7th, 2007 at 5:32 am
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!
September 7th, 2007 at 5:34 am
In this conmmand: xm block-attach 1 phy:/dev/sde xvdb w
1 is the ID of the guest.
January 16th, 2009 at 6:46 am
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).