Xen Disk Hot Add (Block Device) Howto
Tags: block, block-attach, block-detach, disk, hot-add, howto, linux, storage, sysadmin, unix, Xen, xm
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.