(Disclaimer: I am by no means an expert with XenServer. So please don’t take anything you read here for granted. It’s my own experience and what I found in documentation and online.)
In my previous post, I described how to add a Storage Repository to a XenServer using the xe command line tool.
Now, since I have installed the device driver for the RAID controller, created a RAID 5 and added it as Storage Repository (in the same way as described in the linked article), I want to get rid of the SATA drive which I had added as a temporary measure. Guess what, there seem to be no way of doing that using the XenCenter tool (even though the second link below mentions a “Detach” option I could not find it, see the disclaimer above). So, again, it’s the xe command line to the rescue.
xe help
writes a list of supported commands to the console which only contains one command with an sr- prefix: sr-list. Only if you tell it to give you a complete list, you will see what we need here, the sr-destroy command.
xe help --all [... very long list of commands ...] xe help sr-destroy command name : sr-destroy reqd params : uuid optional params : description : Destroy the SR.
But where do we get that uuid? Simple, by asking for it:
xe sr-list [...] uuid ( RO) : 3f1d80c6-929a-f547-9ab1-63a2ca638cbf name-label ( RW): XenServer Tools name-description ( RW): XenServer Tools ISOs host ( RO): xenserver1 type ( RO): iso content-type ( RO): iso [...] uuid ( RO) : <UUID of SR> name-label ( RW): temporary-sata-disk name-description ( RW): host ( RO): xenserver1 type ( RO): lvm content-type ( RO): user
As you can see, there is one Storage Repository with the label temporary-sata-disk. That’s the one I want to remove (the actual list is longer). So
xe sr-destroy uuid=<UUID of SR>
should delete that Storage Repository, right?
No, of course not, you get the error message
The SR is still connected to a host via a PBD. It cannot be destroyed or forgotten. sr: <UUID of SR> (temporary-sata-disk)
There is also an sr-forget command but it displays the same error message.
So simple guessing doesn’t get us any further. Maybe we should read the docs? Nah, we don’t do that yet, we google and find this and also this.
One of the answers in the second link gives an extended version of the sr-list command:
xe sr-list uuid=<UUID of SR> params all uuid ( RO) : <UUID of SR> name-label ( RW): temporary-sata-disk [...] allowed-operations (SRO): unplug; plug; PBD.create; update; PBD.destroy; VDI.resize; VDI.clone; scan; VDI.snapshot; VDI.mirror; VDI.create; VDI.destroy [...] VDIs (SRO): PBDs (SRO): <UUID of PBD> [...]
This shows a lot of stuff, in particular it shows a list of allowed operations and a list of VDIs and PDBs currently connected to the Storage Repository. In the case above, we can see, that there are no VDIs connected to it and one PDB. So we follow the instructions in the first link:
xe sr-list name-label=temporary-sata-disk uuid ( RO) : <UUID of SR> name-label ( RW): temporary-sata-disk name-description ( RW): host ( RO): xenserver1 type ( RO): lvm content-type ( RO): user
which gets us the UUID of the SR (OK, we already had that one)
xe pbd-list sr-uuid=<UUID of SR> uuid ( RO) : <UUID of PBD> host-uuid ( RO): 78059c4a-73f2-4975-936a-537529772d67 sr-uuid ( RO): <UUID of SR> device-config (MRO): device: /dev/sdb currently-attached ( RO): true
which gets us the UUID of the PDB (we already had that one too)
xe pbd-unplug uuid=<UUID of PBD>
followed by
xe sr-forget uuid=<UUID of SR>
After that last command, the Storage Repository vanishes from XenCenter. Also
xe sr-list
no longer lists it. So I guess, it’s safe now to
- Shut down the computer
- Remove the hard disk that was used for that Storage Repository
- Turn on the computer again
One last question: What is the difference between the xe commands sr-forget and sr-destroy? My google fu nearly left me here, until I found a link to XenServer Administrator’s Guide – Layer 8 Consulting (PDF!). There, on page 45 it says
“Destroying or forgetting a SR
You can destroy an SR, which actually deletes the contents of the SR from the physical media. Alternatively you can forget an SR, which allows you to re-attach the SR, for example, to another XenServer host, without removing any of the SR contents.”
So, there you go.