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?

asked Dec 11, 2014 by Eric Z Ma (44,280 points)

1 Answer

 
Best answer

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
answered Dec 11, 2014 by Eric Z Ma (44,280 points)
edited Mar 7, 2017 by Eric Z Ma

Please log in or register to answer this question.

Copyright © SysTutorials. User contributions licensed under cc-wiki with attribution required.
Hosted on Dreamhost

...