Cleaning up orphan VHDs when XenServer storage migrations fail
Created: 2018-09-10 23:11:16 | Last modified: 2020-05-22 01:16:06 | By: NovaAccess: Read | Visibility: Public | Views: 991 | Rating: +2 | Tags: xenserver linux vhd vdi
When a storage migration with XenServer fails, it can cause orphan VHD to be left on a particular storage repository
When performing a storage migration with XenServer, if the storage migration fails it can leave orphan VHDs on the storage repository filling it up. These VHDs need to be removed from XenServer to free up space in the storage repository. To do this, you need to get a list of all of the VDIs, then check each one to see if it is attached to a virtual machine (VM), if it isn't then you delete it.
Get a list of all of the VDIs for a particular storage repository, I copied this to a notepad
xe vdi-list sr-uuid= #Example xe vdi-list sr-uuid=adbdb53f-ef8f-4acc-d1c5-a53f0e15119e #Example2 - grep with before and after lines, 821dc416 is taken from doing a SR scan. #Check all VDIs in a tree before deleting (go bottom of the tree up) xe vdi-list sr-uuid=adbdb53f-ef8f-4acc-d1c5-a53f0e15119e | grep -B 4 -A 4 821dc416
uuid ( RO) : 821dc416-f61b-415c-a4e0-0457a5abfad5 name-label ( RW): VM1_SR name-description ( RW): sr-uuid ( RO): adbdb53f-ef8f-4acc-d1c5-a53f0e15119e virtual-size ( RO): 1202590842880 sharable ( RO): false read-only ( RO): false uuid ( RO) : d4bff1d5-cdca-4996-a347-7036437515f4 name-label ( RW): VM2_SR name-description ( RW): sr-uuid ( RO): adbdb53f-ef8f-4acc-d1c5-a53f0e15119e virtual-size ( RO): 107374182400 sharable ( RO): false read-only ( RO): false
Check if VDI is connected to a VM
xe vbd-list vdi-uuid= #Example - In this case you would NOT destroy VDI xe vbd-list vdi-uuid=821dc416-f61b-415c-a4e0-0457a5abfad5 uuid ( RO) : 0016efa0-a23e-5f13-0dc2-2ced08bb3e16 vm-uuid ( RO): 29d99bc4-7ded-2de0-317e-ccca01df2c04 vm-name-label ( RO): VM1 vdi-uuid ( RO): 6d720d19-c935-4720-a7ea-3458174629c0 empty ( RO): false device ( RO): xvdb #Example - In this case you would destroy the VDI xe vbd-list vdi-uuid=d4bff1d5-cdca-4996-a347-7036437515f4
If the above doesn't return anything, you are safe to delete the VDI
xe vdi-destroy uuid=
#Example
xe vdi-destroy uuid=d4bff1d5-cdca-4996-a347-7036437515f4Once complete, check your storage repository size in XenServer and you should notice its usage has dropped