After having problems with one of my Xenservers in my lab, I decided to build a SAN to store my VMs. After building the SAN, I created an iSCSI target and added it to the Xenserver pool. Next, I started moving a Windows 7 VM to the new SR, but changed my mind while it was copying. After I got the copy to cancel, I still had the virtual disk showing in the repository, and it was eating up space. When I went to delete it, the delete button was greyed out. I tried restarting the toolstack, but no luck.

So I guess it’s time to go to the command line. First thing I do is get the UUID of the VDI using the “xe vdi-list sr-uuid=611441f9-20c7-6775-716a-37c78b6d672e”. I get a list of VDIs and quickly find the uuid of the disk I want to delete.

uuid ( RO) : 203137f6-d98b-4e8e-8940-263e26360559
name-label ( RW): Win7-Image 0
name-description ( RW): DELETE
sr-uuid ( RO): 611441f9-20c7-6775-716a-37c78b6d672e
virtual-size ( RO): 25769803776
sharable ( RO): false
read-only ( RO): false

Now let’s try deleting with “xe vdi-destory uuid=611441f9-20c7-6775-716a-37c78b6d672e”. Result: The uuid you supplied was invalid. Whoops. Entered the SR uuid. Ok, let’s try this again. “xe vdi-destory uuid=203137f6-d98b-4e8e-8940-263e26360559

This operation cannot be performed because this VDI is in use by some other operation
vdi: 203137f6-d98b-4e8e-8940-263e26360559 (Win7-Image 0)
operation: destroy

Eh boy. OK, so what is using it? When I’m looking at Xencenter, it shows the Virtual machine it is attached to is “Control domain on host xen1”, which is my first xenserver.

Next we need to look at the the virtual block devices that might be tying up this VDI by entering “xe vbd-list vdi-uuid=203137f6-d98b-4e8e-8940-263e26360559”. This should give you the result back similar to the following.

uuid ( RO) : fb58a7e8-6ad3-ed6b-05bb-817d6ff1e4f0
vm-uuid ( RO): 233c0fd0-1a4d-4746-8ae6-8d0bd642a145
vm-name-label ( RO): Control domain on host: xen1
vdi-uuid ( RO): 203137f6-d98b-4e8e-8940-263e26360559
empty ( RO): false
device ( RO): sm/backend/611441f9-20c7-6775-716a-37c78b6d672e/203137f6-d98b-4e8e-8940-263e26360559

Now, let’s delete that vbd so it releases the vdi by entering “xe vbd-unplug uuid=fb58a7e8-6ad3-ed6b-05bb-817d6ff1e4f0” followed by “xe vbd-destroy uuid=fb58a7e8-6ad3-ed6b-05bb-817d6ff1e4f0″.

You should now be able to delete the drive from Xencenter for from the command line.