#创建硬盘
[root@idc img]# qemu-img create -f qcow2 vdb.qcow2 100G
Formatting 'vdb.qcow2', fmt=qcow2 size=107374182400 encryption=off cluster_size=65536 lazy_refcounts=off
[root@idc img]# ls
2008r2.qcow2 centos7.5.qcow2 centos7v1.5.qcow2 temp.xml vdb.img vdb.qcow2
#新建xml文件
[root@idc img]# vim temp.xml
<disk type='file' device='disk'>
<driver name='qemu' type='qcow2' cache='writeback'/>
<source file='/home/img/vdb.qcow2'/>
<target dev='vdb' bus='virtio'/>
</disk>
#查看当前虚拟机
root@idc img]# virsh list
Id Name State
----------------------------------------------------
7 centos7.5 running
19 centos7v1.5 running
#查看虚拟机centos7.5的硬盘信息
[root@idc img]# virsh domblklist centos7.5
Target Source
------------------------------------------------
vda /home/img/centos7.5.qcow2
hda -
#加载xml文件 参数 --config 是写入配置文件 --live 是热添加
[root@idc img]# virsh attach-device centos7.5 temp.xml --config --live
Device attached successfully
#查看虚拟机centos7.5的硬盘信息
[root@idc img]# virsh domblklist centos7.5
Target Source
------------------------------------------------
vda /home/img/centos7.5.qcow2
vdb /home/img/vdb.img
hda -
**************************卸载载硬盘****************
#查看虚拟机centos7.5的硬盘信息
[root@idc img]# virsh domblklist centos7.5
Target Source
------------------------------------------------
vda /home/img/centos7.5.qcow2
vdb /home/img/vdb.img
hda
#卸载第二块硬盘 参数 --config 是写入配置文件 --live 是热删除
[root@idc img]# virsh detach-disk centos7.5 vdb --config --live
Disk detached successfully
[root@idc img]# virsh domblklist centos7.5
Target Source
------------------------------------------------
vda /home/img/centos7.5.qcow2
hda -
[root@idc img]#
*********这样下次添加就变得很容易,硬盘没有直接丢失