Citrix Xen: How to attach an existing vdi to any virtual machine

root's picture

Identify the uuid of the disk you want to attach but also the uuid of the target machine.

You can get the uuid disks with xe vdi-list or even with lvscan.
The VM's uuid you can get in many ways. One of them is:

[root@xengz ~]# xe vm-list params=uuid name-label=debian
uuid ( RO)    : 36f3763b-4011-055f-4945-92fe13a0027b

So, once you have all that you need, you can proceed.
In our example below, we will attach the vdi with uuid 3950c41a-39ef-439f-bd02-a6e346a60b99 to debian vm with uuid 36f3763b-4011-055f-4945-92fe13a0027b.

List the vm's disks before the operation:

As you can see, for each vdi you have a vbd. As a side note, when you want to boot from any medium (disk or cd), the target uuid is the vbd one.

[root@XenGz ~]# xe vm-disk-list vm="debian"
Disk 0 VBD:
uuid ( RO)             : 20b45191-8a7c-1c97-8995-8b1776866965
    vm-name-label ( RO): debian
       userdevice ( RW): 0


Disk 0 VDI:
uuid ( RO)             : 60a0f79f-2158-4d4b-8eba-8684d4197373
       name-label ( RW): 0
    sr-name-label ( RO): Local storage
     virtual-size ( RO): 8589934592

Create the corresponding vbd for the vdi and then list again the vm's disks:

[root@XenGz ~]# xe vbd-create vm-uuid=36f3763b-4011-055f-4945-92fe13a0027b device=1 vdi-uuid=3950c41a-39ef-439f-bd02-a6e346a60b99 bootable=false mode=RW type=Disk
2acbffca-fb41-b41f-a66e-3e403ad5aeb5
[root@XenGz ~]# xe vm-disk-list vm="debian"
Disk 0 VBD:
uuid ( RO)             : 2acbffca-fb41-b41f-a66e-3e403ad5aeb5
    vm-name-label ( RO): debian
       userdevice ( RW): 1


Disk 0 VDI:
uuid ( RO)             : 3950c41a-39ef-439f-bd02-a6e346a60b99
       name-label ( RW): 0
    sr-name-label ( RO): Local storage
     virtual-size ( RO): 53687091200

Disk 1 VBD:
uuid ( RO)             : 20b45191-8a7c-1c97-8995-8b1776866965
    vm-name-label ( RO): debian
       userdevice ( RW): 0


Disk 1 VDI:
uuid ( RO)             : 60a0f79f-2158-4d4b-8eba-8684d4197373
       name-label ( RW): 0
    sr-name-label ( RO): Local storage
     virtual-size ( RO): 8589934592

Once you have this done and you are sure the disk is not used, you can plug it in:

[root@XenGz ~]# xe vbd-plug uuid=2acbffca-fb41-b41f-a66e-3e403ad5aeb5
[root@XenGz ~]#

After this command, you will be able to see the disk in debian vm, without reboot.

Thou shalt not steal!

If you want to use this information on your own website, please remember: by doing copy/paste entirely it is always stealing and you should be ashamed of yourself! Have at least the decency to create your own text and comments and run the commands on your own servers and provide your output, not what I did!

Or at least link back to this website.

Recent content

root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root