05、KVM虚拟机的组成介绍
命令行安装虚拟机,需要借助第一次用图形化安装的系统作为模板,来进行复制和修改。那么我们到底要复制什么?修改什么呢?因此我们必须先来了解一下虚拟机的组成。一、虚拟机的组成部分在这里我们以上一节图形化安装的centos7-01为例。1、虚拟机配置文件下面的xml文件就是我们的centos7-01虚拟机配置文件[root@kvmserver kvmdata]# cd /etc/libvirt/qemu/
·
命令行安装虚拟机,需要借助第一次用图形化安装的系统作为模板,来进行复制和修改。那么我们到底要复制什么?修改什么呢?因此我们必须先来了解一下虚拟机的组成。
一、虚拟机的组成部分
在这里我们以上一节图形化安装的centos7-01为例。
1、虚拟机配置文件
下面的xml文件就是我们的centos7-01虚拟机配置文件
[root@kvmserver kvmdata]# cd /etc/libvirt/qemu/
[root@kvmserver qemu]# ll
总用量 8
-rw------- 1 root root 4609 9月 17 13:44 centos7.0-01.xml
drwx------. 3 root root 42 5月 13 00:30 networks
2、虚拟机的磁盘镜像文件
上一节课说了因为我的宿主机安装时,var分区只有3G,所以我自定义的存储池,在根下的kvmdata
目录内。我们看到的以.qcow2
的文件就是centos7-01的磁盘镜像文件。
[root@kvmserver ~]# cd /kvmdata/
[root@kvmserver kvmdata]# ll
总用量 1633616
-rw------- 1 root root 21478375424 9月 17 14:55 centos7.0-01.qcow2
因此我们可以得出:
虚拟机的组成由:配置文件+磁盘镜像文件
那如果我们以centos7-01为模板,创建centos7-02,是不是修改这两个文件就可以呢?其实没必要两个都修改,我们只需要修改配置文件就可以了。磁盘镜像文件是无法修改的。要修改配置文件,就必须先了解配置文件的结构。
二、虚拟机配置文件
1、配置文件预览
以下代码中加有注释的,是可以改的,其他不需要修改
<!--
WARNING: THIS IS AN AUTO-GENERATED FILE. CHANGES TO IT ARE LIKELY TO BE
OVERWRITTEN AND LOST. Changes to this xml configuration should be made using:
virsh edit centos7.0-02
or other application using the libvirt API.
-->
<domain type='kvm'>
<name>centos7.0-02</name> #名字
<uuid>784bcd3a-d59c-4f60-a52f-6674fc6ae33e</uuid> #UID
<memory unit='KiB'>1048576</memory> #内存
<currentMemory unit='KiB'>1048576</currentMemory>
<vcpu placement='static'>1</vcpu> #cpu数量
<os>
<type arch='x86_64' machine='pc-i440fx-rhel7.0.0'>hvm</type>
<boot dev='hd'/>
</os>
<features>
<acpi/>
<apic/>
</features>
<cpu mode='custom' match='exact' check='partial'>
<model fallback='allow'>Broadwell-noTSX</model>
</cpu>
<clock offset='utc'>
<timer name='rtc' tickpolicy='catchup'/>
<timer name='pit' tickpolicy='delay'/>
<timer name='hpet' present='no'/>
</clock>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash>
<pm>
<suspend-to-mem enabled='no'/>
<suspend-to-disk enabled='no'/>
</pm>
<devices>
<emulator>/usr/libexec/qemu-kvm</emulator>
<disk type='file' device='disk'>
<driver name='qemu' type='qcow2'/>
<source file='/kvmdata/centos7.0-02.qcow2'/>
<target dev='vda' bus='virtio'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'/>
</disk>
<disk type='file' device='cdrom'>
<driver name='qemu' type='raw'/>
<target dev='hda' bus='ide'/>
<readonly/>
<address type='drive' controller='0' bus='0' target='0' unit='0'/>
</disk>
<controller type='usb' index='0' model='ich9-ehci1'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x7'/>
</controller>
<controller type='usb' index='0' model='ich9-uhci1'>
<master startport='0'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0' multifunction='on'/>
</controller>
<controller type='usb' index='0' model='ich9-uhci2'>
<master startport='2'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x1'/>
</controller>
<controller type='usb' index='0' model='ich9-uhci3'>
<master startport='4'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x2'/>
</controller>
<controller type='pci' index='0' model='pci-root'/>
<controller type='ide' index='0'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
</controller>
<controller type='virtio-serial' index='0'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/>
</controller>
<interface type='network'>
<mac address='52:54:00:35:d5:3b'/> #MAC码
<source network='default'/>
<model type='virtio'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
</interface>
<serial type='pty'>
<target type='isa-serial' port='0'>
<model name='isa-serial'/>
</target>
</serial>
<console type='pty'>
<target type='serial' port='0'/>
</console>
<channel type='unix'>
<target type='virtio' name='org.qemu.guest_agent.0'/>
<address type='virtio-serial' controller='0' bus='0' port='1'/>
</channel>
<channel type='spicevmc'>
<target type='virtio' name='com.redhat.spice.0'/>
<address type='virtio-serial' controller='0' bus='0' port='2'/>
</channel>
<input type='tablet' bus='usb'>
<address type='usb' bus='0' port='1'/>
</input>
<input type='mouse' bus='ps2'/>
<input type='keyboard' bus='ps2'/>
<graphics type='spice' autoport='yes'>
<listen type='address'/>
<image compression='off'/>
</graphics>
<sound model='ich6'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
</sound>
<video>
<model type='qxl' ram='65536' vram='65536' vgamem='16384' heads='1' primary='yes'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
</video>
<redirdev bus='usb' type='spicevmc'>
<address type='usb' bus='0' port='2'/>
</redirdev>
<redirdev bus='usb' type='spicevmc'>
<address type='usb' bus='0' port='3'/>
</redirdev>
<memballoon model='virtio'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x08' function='0x0'/>
</memballoon>
<rng model='virtio'>
<backend model='random'>/dev/urandom</backend>
<address type='pci' domain='0x0000' bus='0x00' slot='0x09' function='0x0'/>
</rng>
</devices>
</domain>
2、必须修改的地方
UID、name、MAC 这三个是必须要更改的。否则会冲突
3、可选修改的
cpu、内存
更多推荐
已为社区贡献21条内容
所有评论(0)