13.8. Removing virtual machine storage by using the command line
If you no longer require a virtual disk attached to a virtual machine (VM), or if you want to free up host storage resources, you can use the command line to do any of the following:
- Detach the virtual disk from the VM.
- Delete the virtual disk and its content.
- Deactivate the storage pool related to the virtual disk.
- Delete the storage pool related to the virtual disk.
Procedure
To detach a virtual disk from a VM, use the
virsh detach-diskcommand.Optional: List all storage devices attached to the VM:
# *virsh domblklist --details <vm-name> Type Device Target Source ----------------------------------------------------------------------------- file disk hda /home/VirtualMachines/vm-name.qcow2 file cdrom hdb - file disk vdc /home/VirtualMachines/test-disk2.qcow2Use the
targetparameter to detach the disk. For example, to detach the disk connected to asvdcto thetestguestVM, use the following command:# virsh detach-disk testguest vdc --persistent
To delete the disk, do one of the following:
If the disk is managed as a storage volume, use the
virsh vol-deletecommand. For example, to delete volumetest-disk2associated with storage poolRHEL-storage-pool:# virsh vol-delete --pool RHEL-storage-pool test-disk2If the disk is purely file-based, remove the file.
# rm /home/VirtualMachines/test-disk2.qcow2
To deactivate a storage pool, use the
virsh pool-destroycommand.When you deactivate a storage pool, no new volumes can be created in that pool. However, any VMs that have volumes in that pool will continue to run. This is useful, for example, if you want to limit the number of volumes that can be created in a pool to increase system performance.
# virsh pool-destroy RHEL-storage-pool Pool RHEL-storage-pool destroyedTo completely remove a storage pool, delete its definition by using the
virsh pool-undefinecommand.# virsh pool-undefine RHEL-storage-pool Pool RHEL-storage-pool has been undefined
Verification
To confirm that your changes to VM storage have been successful, inspect the current state of virtual storage on your host.
For instructions, see Viewing virtual machine storage information by using the command line.