How to dynamically attach a disk to running DomU in Xen?

I want to attach a disk to a DomU.

The Xen DomU is running and should not be rebooted. Hence, changing its configuration file is not an option.

How to dynamically attach a disk to running DomU in Xen?

To attach phy:vg_xen/vm-228-large to vm-228 as xvdb, run this on Dom0:

# xl block-attach vm-228 phy:vg_xen/vm-228-large xvdb w

With the old xm tool stack, replace xl with xm.

In the VM vm-228, a new device /dev/xvdb should appear.

The general format for block-attach is as follows.

xl [-v] block-attach <Domain> <BackDev> <FrontDev> 
[<Mode>] [BackDomain]

Bonus:

Using this method, you can also mounting a USB drive to a DomU by attaching the whole USB drive (e.g./dev/sde, not the partition /dev/sde1) to a VM as a disk like

# xl block-attach vm-228 /dev/sde xvde w

Note that do not mount the USB drive on Dom0 and umount it if the OS automatically mounted it.

Detach a disk:

# xl block-detach vm-228 xvde

Eric Ma

Eric is a systems guy. Eric is interested in building high-performance and scalable distributed systems and related technologies. The views or opinions expressed here are solely Eric's own and do not necessarily represent those of any third parties.

Leave a Reply

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