Xen Disk Hot Add (Block Device) Howto

Tags: , , , , , , , , , , ,


Xen allows you to hot add (and remove) disks to a guest domU while the system is running. To do this you’ll use the ‘xm block-*’ commands.

Hot Add

To hot add a disk we use the ‘xm block-attach’ command.

Usage: xm block-attach <Domain> <BackDev> <FrontDev> <Mode> [BackDomain]

Let me describe what each of these arguments means:

Domain: The name of the guest domU you wish to add a block device to.
BackDev: The location of the block device in the dom0
FrontDev: The device name to assign the new device in the domU
Mode: read-only or read-write (r or w)

For example, we have a physical (phy:) LVM device called /dev/vg0/vm_osol that we want to attach to a virtual machine named ‘comlag’ as /dev/xvda3.

xm block-attach comlag phy:/dev/vg0/vm_osol /dev/xvda3 w

The device /dev/xvda3 will become available on comlag. Because we used mode “w” the device is presented as read/write and we can now mount, format, enable swap and do anything else you normally would do with a block device.

Hot Remove

To hot remove we use the ‘xm block-detach’ command.

Usage: xm block-detach <Domain> <DevId> [-f|--force]

Domain: Name of the guest domU
DevId: Name of the device within the domU (same idea as FrontDev above)

Now let’s remove the device we just attached to comlag.

Note: Be sure that the device isn’t mounted, or you risk damaging the contents of the block device.

 xm block-detach comlag /dev/xvda3

And that’s it. Just be sure to update your xen config files to reflect any change you make by hot-add or these changes will go away when the domain is re-created.

2 Responses to “Xen Disk Hot Add (Block Device) Howto”

  1. Frank Vasquez Diaz Says:

    When I run the command on my server throws me this error:

    xl block-attach proxy phy:/dev/vgcmbo/compartidas /dev/vgcmbo/xvdc1 w
    libxl: error: libxl.c:2042:libxl__device_from_disk: Invalid or unsupported virtual disk identifier /dev/vgcmbo/xvdc1
    libxl: error: libxl.c:2128:device_disk_add: Invalid or unsupported virtual disk identifier /dev/vgcmbo/xvdc1
    libxl: error: libxl.c:1743:device_addrm_aocomplete: unable to (null) device
    libxl_device_disk_add failed.

    [Reply]

    David Bruha Reply:

    Don’t know if it is still interesting for you but when using xl toolstack you specify only the last part of the virtual disk identifier:

    xl block-attach proxy phy:/dev/vgcmbo/compartidas xvdc1 w

    [Reply]

Join the Conversation