With XenServer/XCP we did a meta data restore to restore a number of virtual machines on a storage repository when creating a clean install of XCP. All the VMs came up fine but the control domain still had a lock on the disk VDIs. We are unable to migrate the volume or perform other operations until this lock is removed.
Here is some instructions of how to remove the control domain lock on these;
List the domains to get the Dom0 UUID
list_domains
id | uuid | state
0 | ded17027-b863-47d4-9d63-b3b2c7daee46 | R
1 | f0535e79-01b3-51c5-015d-d217c4a7f63c | B
3 | 8bea4bb6-bda0-af7f-0373-36f6f905680e | B H
4 | fd02481b-756f-b593-2e75-dff0fe08075f | B
5 | b7ac7792-efba-dd88-beec-feaf87bb84dc | B H
8 | c642a181-aa97-23dc-9030-4879b7a4d52b | B Next list all of the vbd (Virtual Block Device) locks for the Dom0 UUID and get the VBD UUID
xe vbd-list vm-uuid=ded17027-b863-47d4-9d63-b3b2c7daee46uuid ( RO) : d3eadc3c-96c3-7031-1894-0f31d2d8b255 vm-uuid ( RO): ded17027-b863-47d4-9d63-b3b2c7daee46 vm-name-label ( RO): Control domain on host: nzvz2 vdi-uuid ( RO): efca45ac-6bed-47bc-9373-1417ee41f8d5 empty ( RO): false device ( RO): sm/backend/e9b8b43d-03ab-8947-2cf8-b8d867dbf30a/6t36222-2352-47bc-9373-1417ee41f8d5 uuid ( RO) : 013734c3-c6df-6c55-bd43-fdeb33eb35e7 vm-uuid ( RO): ded17027-b863-47d4-9d63-b3b2c7daee46 vm-name-label ( RO): Control domain on host: nzvz2 vdi-uuid ( RO): d9771f37-b0a3-4801-9a2f-aef8fc218e26 empty ( RO): false device ( RO): sm/backend/e9b8b43d-03ab-8947-2cf8-b8d867dbf30a/d9771f37-323-4801-9a2f-aef8fc218e26
Now try and detach the VBD. If this doesn't and you get a "The device is not currently attached" message you will need to destroy the VBD, this doesn't delete the VDI/Disk itself, just the lock that Dom0 has on it
xe vbd-unplug uuid=013734c3-c6df-6c55-bd43-fdeb33eb35e7
The device is not currently attached device: 013734c3-c6df-6c55-bd43-fdeb33eb35e7
The above failed, destroy the VBD, no output is displayed. When running the vbd-list again you will be able to see that the lock has gone.
xe vbd-destroy uuid=013734c3-c6df-6c55-bd43-fdeb33eb35e7