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

  1. To detach a virtual disk from a VM, use the virsh detach-disk command.

    1. 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.qcow2
    2. Use the target parameter to detach the disk. For example, to detach the disk connected to as vdc to the testguest VM, use the following command:

      # virsh detach-disk testguest vdc --persistent
  2. To delete the disk, do one of the following:

    1. If the disk is managed as a storage volume, use the virsh vol-delete command. For example, to delete volume test-disk2 associated with storage pool RHEL-storage-pool:

      # virsh vol-delete --pool RHEL-storage-pool test-disk2
    2. If the disk is purely file-based, remove the file.

      # rm /home/VirtualMachines/test-disk2.qcow2
  3. To deactivate a storage pool, use the virsh pool-destroy command.

    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 destroyed
  4. To completely remove a storage pool, delete its definition by using the virsh pool-undefine command.

    # virsh pool-undefine RHEL-storage-pool
    
    Pool RHEL-storage-pool has been undefined

Verification

Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2026 Red Hat
返回顶部