If get the VDI is not available when scanning SR
xe sr-scan uuid=[uuid of the SR]
Should give you a more verbose error message, also
/var/log/SMlog
Should give an even more verbose error, eg VDI header error
Get the VDI uuid
xe vdi-list
Forget the VDI and re-scan the SR
xe vdi-forget uuid=[vdi uuid]
xe sr-scan uuid=[sr uuid]
Might fix the issue, otherwise, if need to preserve the data, need to restart the host
If can trash the data, can try to delete the vdi
xe vdi-destroy uuid=[vdi uuid]
Might not work, if not, try restart. May also need to manually remove the LVM volume
lvremove /dev/VG_XenStorage-[uuid of sr]/VHD-[uuid of vdi]
Then restart the machine or Xen is confused by missing volume
If really need the data, there might be a way to fix broken headers/footers. If the data on the VDI has issues, though, create a new VDI (larger than original), use dd to copy data from broken VDI to new one, mount new one and use a recovery tool on the VM to recover data.
Instructions taken from post on Citrix Forums by Fabian Baena:
xe vdi-create sr-uuid=bc4c43f3-1321-2b17-bef0-3b58686a8075 name-label=copy virtual-size=210130436096
the sr-uuid is the storage where you want to put the copy. Take note of the uuid that comes up after you execute the command
get the uuid of your xenserver control domain by doing
xe vm-list name-label=Control\ domain\ on\ host:\ <name of your xenserver host> params=uuid
then create the vbd
xe vbd-create vm-uuid=<;vm-uuid you got from the previous command>; vdi-uuid=<vdi uuid you got from the vdi-create command> device=0
plug the vbd
xe vbd-plug uuid=<vbd uuid you got from the previous command>;
then do the copy
dd if=/dev/mapper/VG_XenStorage–bc4c43f3–1321–2b17–bef0–3b58686a8075-VHD–b079b55a–6679–47a1–b2a2–d207a476494e of=/dev/xvda
The copy will take several minutes. When finished unplug the vbd
xe vbd-unplug uuid=<vbd uuid you got from the vbd-create command>
xe vbd-destroy uuid=<vbd uuid you got from the vbd-create command>
Afterwards, you can connect the new vdi to a vm and see if you can recover anything.