KVM宿主机上虚拟机动态添加新磁盘

 

(1)KVM宿主机查看运行的虚拟机

       $ virsh list --all

 

 

(2)将qcow2的磁盘移动到/var/lib/libvirt/images/,比如为centos.qcow2

 

 

(3)进入/etc/libvirt/qemu/目录查看centos7.5虚拟机的xml文件

 

  查看disk配置信息

 

 

(4)在/root目录下,编辑test.xml文件

  内容为要新添加的centos.qcow2磁盘的配置信息,如下:

<disk type='file' device='disk'>
      <driver name='qemu' type='qcow2' cache='none'/>
      <source file='/var/lib/libvirt/images/centos.qcow2'/>
      <target dev='vdb' bus='virtio'/>
</disk>

  

(5)将该磁盘绑定到虚拟机

  $ virsh attach-device centos7.5 test.xml

 

 

(6)登录到虚拟机查看磁盘是否绑定到虚拟机

       $ lsblk

 

 

(7)将vdb1挂载在/mnt下查看磁盘数据并进行相应的操作

       $ moun /dev/vdb1 /mnt

 

 

(8)数据修改完成进行umount,然后再宿主机上将该磁盘从虚拟机解绑

  $ virsh detach-device centos7.5 test.xml

 

 

 

 

 

posted @ 2019-04-25 21:39  陈LI  阅读(518)  评论(0编辑  收藏  举报