发现libvirt/images下有个qcow2文件挺大,于是想用virsh安全删掉。
列出虚拟机
开始没用sudo,结果啥都没有,明明记得之前搞过俩呢。
sudo virsh list --all
Id Name State
----------------------------------------------------
- vm1 shut off
- vm2 shut off
检查虚拟机配置
sudo virsh dumpxml vm1 | grep 'source file'
<source file='/var/lib/libvirt/images/cirros-0.5.1-x86_64-disk.img'/>
<source file='/var/lib/libvirt/images/vm1.qcow2'/> #要删这个
编辑配置
确保该虚拟机未运行。删除配置中挂载vm1.qcow2
的段落。
sudo virsh edit vm1
# 删除这段
<disk type='file' device='disk'>
<driver name='qemu' type='qcow2'/>
<source file='/var/lib/libvirt/images/vm1.qcow2'/>
<target dev='hda' bus='ide'/>
<address type='drive' controller='0' bus='0' target='0' unit='1'/>
</disk>
删除文件
sudo rm /var/lib/libvirt/images/vm1.qcow2
搞定。