虚拟机的构成:
COW技术原理:
创建虚拟机磁盘
上传cirros.qcow2到虚拟机
通过qemu-img创建虚拟机磁盘
命令格式:qemu-img 子命令 子命令参数 虚拟机磁盘文件 大小
[root@ecs ~]# cp cirros.qcow2 /var/lib/libvirt/images/
[root@ecs ~]# cd /var/lib/libvirt/images/
[root@ecs ~]# qemu-img create -f qcow2 -b cirros.qcow2 vmhost.img 20G # cirros.qcow2 是后端盘
[root@ecs ~]# qemu-img info vmhost.img #查看信息 实际的文件大小只有1M左右 像气球一样
虚拟机配置文件
官方文档地址 https://libvirt.org/format.html
拷贝 node_base.xml 到虚拟机中
[root@ecs ~]# cp node_base.xml /etc/libvirt/qemu/vmhost.xml
[root@ecs ~]# vim /etc/libvirt/qemu/vmhost.xml
02: <name>vmhost</name>
03: <memory unit='KB'>1024000</memory>
04: <currentMemory unit='KB'>1024000</currentMemory>
05: <vcpu placement='static'>2</vcpu>
26: <source file='/var/lib/libvirt/images/vmhost.img'/> # 磁盘文件路径
30: <source bridge='vbr'/>
创建虚拟机
[root@ecs ~]# virsh define /etc/libvirt/qemu/vmhost.xml
Domain vmhost defined from /etc/libvirt/qemu/vmhost.xml
[root@ecs ~]# virsh list --all
Id Name State
----------------------------------------------------
- vmhost shut off
[root@ecs ~]# virsh start vmhost
Domain vmhost started
[root@ecs ~]# virsh console vmhost # 两次回车
Connected to domain vmhost
Escape character is ^]
login as 'cirros' user. default password: 'gocubsgo'. use 'sudo' for root.
cirros login:
退出使用 ctrl + ]