mwarr Posted February 2 Share Posted February 2 Want to unmount / disconnect a disk from a guest via powershell remove-vdi deletes it ... how to just remove it ? using Citrix hypervisor 8.2 Link to comment
0 Mark Syms Posted February 5 Share Posted February 5 You want to remove the VBD object which is the mapping object between the VDI and the VM. Also, if the guest has the drive active and mounted you may not be able to remove it until it is deactivated in the guest. Link to comment
0 Danilo Del Busso Posted February 5 Share Posted February 5 Hi mwarr! I am guessing you're referring to "detatching" a Virtual Disk from a VM. This operation will remove the association between the Virtual Disk and the chosen VM, while preserving the disk and its data. If the VBDs on the VDI you're trying to detach are currently attached you'll need to unplug them first (vbd-unplug on xe). Otherwise, you'll need to destroy all VBDs on the VDI. Wrote a little script to give you an idea. It makes use of Invoke-XenVBD Unplug and Remove-XenVBD? Note that if you instead want to simply "deactivate" the disk, you must call Invoke-XenVBD Unplug without Remove-XenVBD. This will then allow you you "reactivate" the disk by calling Invoke-XenVBD Plug. $vdiUuid = [System.guid]::New("VDI_UUID") $vmUuid = [System.guid]::New("VM_UUID") ## Check input $vdi = Get-XenVDI -Uuid $vdiUuid if ($null -eq $vdi || $vdi.Locked) { Write-Output "VDI not valid" Exit } $vm = Get-XenVM -Uuid $vmUuid if ($null -eq $vm) { Write-Output "VM not valid" Exit } $matchingVbd = $null foreach ($vbdRef in $vm.VBDs) { $vbd = Get-XenVBD -Ref $vbdRef if ($null -eq $vbd) { Write-Output "VBD $($vbdRef) not valid" Exit } if ($vbd.VDI.opaque_ref -eq $vdi.opaque_ref) { $matchingVbd = $vbd break } } if ($null -eq $matchingVbd) { Write-Output "Could not find matching VBD!" Exit } ## Detatch operation Write-Output "Detatching VDI '$($vdi.name_label)'" Write-Output "" Write-Output "Attempting to destroy VBD '$($vbd.uuid)'" if ($matchingVbd.currently_attached) { Write-Output "VBD is attached, we need to unplug it before we can destroy it" $allowedOperations = $matchingVbd.allowed_operations if ($allowedOperations -contains "unplug") { Write-Output "Unplugging '$($vbd.uuid)'" Invoke-XenVBD $matchingVbd -XenAction Unplug Write-Output "Unplugged '$($vbd.uuid)'" } else { Write-Output "Cannot unplug attached VBD!" Exit; } } Write-Output "Destroying '$($vbd.uuid)'" Remove-XenVBD $matchingVbd Write-Output "Destroyed '$($vbd.uuid)'" Write-Output "" Link to comment
0 Konstantina Chremmou Posted February 22 Share Posted February 22 If the VDI you want to remove is from a media drive: $myVbd = Get-XenVM -name "MyVm" | select -ExpandProperty VBDs | Get-XenVBD | where {$_.type -eq [XenAPI.vbd_type]::CD} Invoke-XenVBD -XenAction Eject -Ref $myVbd.opaque_ref Link to comment
Question
mwarr
Want to unmount / disconnect a disk from a guest via powershell
remove-vdi deletes it ... how to just remove it ?
using Citrix hypervisor 8.2
Link to comment
3 answers to this question
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now