Linux实战教学笔记54:开源虚拟化KVM(二)管理虚拟存储 (14)

212.png-33kB

选择硬件添加

213.png-59.7kB

添加虚拟磁盘

214.png-36.5kB

进入运行中的虚拟机的交互界面

215.png-20.3kB

216.png-21.2kB

(2)通过XML文件添加新的设备

#创建一个disk类型的xml文档 [root@localhost ~]# cat /tmp/disks.xml <disk type=\'file\' device=\'disk\'> #文件类型 <driver name=\'qemu\' type=\'qcow2\' cache=\'none\'/> #磁盘类型 <source file=\'/vm/test1.qcow2\'/> #虚拟卷位置 <target dev=\'vdb\'/> #虚拟卷挂载名称 </disk> #查看virsh domblklist命令的帮助 [root@localhost ~]# virsh domblklist --help NAME domblklist - 列出所有域块 SYNOPSIS domblklist <domain> [--inactive] [--details] DESCRIPTION 获取域块设备小结 OPTIONS [--domain] <string> 域名,id 或 uuid --inactive 获取不活跃而不是运行的配置 --details type 和 device 值的附加显示 #查看虚拟机的磁盘挂载情况 [root@localhost ~]# virsh list --all Id 名称 状态 ---------------------------------------------------- 1 centos6.5 running #一个正在运行的虚拟机 - Base_CentOS7 关闭 - centos6.5-2 关闭 - centos6.5-3 关闭 - crm 关闭 - erp 关闭 - hr 关闭 - LNMP 关闭 - oa 关闭 - vm2 关闭 [root@localhost ~]# virsh domblklist centos6.5 #查看虚拟机的磁盘设备挂载情况 目标 源 ------------------------------------------------ vda /var/lib/libvirt/images/centos6.5.qcow2 hda /iso/CentOS-6.5-x86_64-bin-DVD1.iso #将磁盘类型的xml文档加入到虚拟机 [root@localhost ~]# virsh attach-device --help #查看命令帮助 NAME attach-device - 从一个XML文件附加装置 SYNOPSIS attach-device <domain> <file> [--persistent] [--config] [--live] [--current] DESCRIPTION 从一个XML文件附加装置. OPTIONS [--domain] <string> 域名,id 或 uuid [--file] <string> XML 文件 --persistent 让实时更改持久 #虚拟机永久生效 --config 影响下一次引导 #挂载的磁盘重启虚拟机生效 --live 影响运行的域 --current 影响当前域 [root@localhost ~]# virsh attach-device centos6.5 /tmp/disks.xml --persistent #将xml文件添加进虚拟机 成功附加设备 [root@localhost ~]# virsh domblklist centos6.5 目标 源 ------------------------------------------------ vda /var/lib/libvirt/images/centos6.5.qcow2 vdb /vm/test1.qcow2 #存储卷添加成功 hda /iso/CentOS-6.5-x86_64-bin-DVD1.iso

通过virt-manager查看磁盘已经添加成功,如下图:

217.png-54.9kB

(3)通过参数添加新的磁盘设备

#克隆一个存储卷 [root@localhost ~]# virsh vol-clone test1.qcow2 test2.qcow2 --pool VM 使用 test2.qcow2 克隆的卷 test1.qcow2 [root@localhost ~]# ll /vm/test2.qcow2 -rw------- 1 qemu qemu 1245184 5月 18 22:00 /vm/test2.qcow2 #挂载一个存储卷到虚拟机 [root@localhost ~]# virsh attach-disk centos6.5 --source=http://www.likecs.com/vm/test2.qcow2 --target=vdc 成功附加磁盘 [root@localhost ~]# virsh domblklist centos6.5 目标 源 ------------------------------------------------ vda /var/lib/libvirt/images/centos6.5.qcow2 vdb /vm/test1.qcow2 vdc /vm/test2.qcow2 #挂载成功 hda /iso/CentOS-6.5-x86_64-bin-DVD1.iso

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zzjxzx.html