For years I have had a problem with a few stale xen virtual servers. After some crashes, I have been unable to delete or stop the domains. When I try to run xm delete, I got this error message:
root@shire:/var# xm delete domain.phz.fi Error: Domain is not halted. Usage: xm delete Remove a domain from Xend domain management.
However the domain is not running, and you cannot xm reboot, restore, reboot or shutdown it.
root@shire:/var# xm list Name ID Mem VCPUs State Time(s) Domain-0 0 3354 4 r----- 3485.8 domain.phz.fi 256 1 11054.4 domain2.phz.fi 368 1 0.0
The only way I’ve been able to start the domain again was to create a second copy (of the config file) by name domain2.phz.fi.
Googling ”xm delete domain is not halted” has not been helpful, since the top results like this and this won’t really work.
But now I finally found out how to fix the issue: xend stores the domain run-time data to /var/lib/xend/domains. For example I found two saved states of the domain refusing to halt:
root@shire:/var# grep -r domain.phz.fi /var/lib/xend/domains/ /var/lib/xend/domains/1fada935-a352-daac-7142-d48ffc3dfc51/config.sxp: (name_label domain.phz.fi) /var/lib/xend/domains/1fada935-a352-daac-7142-d48ffc3dfc51/config.sxp: (name domain.phz.fi) /var/lib/xend/domains/1fada935-a352-daac-7142-d48ffc3dfc51/config.sxp: (uname file:/home/xen/domains/domain.phz.fi/disk.img) /var/lib/xend/domains/1fada935-a352-daac-7142-d48ffc3dfc51/config.sxp: (uname file:/home/xen/domains/domain.phz.fi/swap.img) Binary file /var/lib/xend/domains/1fada935-a352-daac-7142-d48ffc3dfc51/checkpoint.chk matches /var/lib/xend/domains/9f174da8-26cc-660b-0793-f493aac65b7f/config.sxp: (uname file:/home/xen/domains/domain.phz.fi/disk.img) /var/lib/xend/domains/9f174da8-26cc-660b-0793-f493aac65b7f/config.sxp: (uname file:/home/xen/domains/domain.phz.fi/swap.img)
Now you can just
rm -rf /var/lib/xend/domains/9f174da8-26cc-660b-0793-f493aac65b7f
After which
xm delete domain.phz.fi
works again.