


Detailed explanation of the configuration xml code in the KVM virtual machine
In RHEL6, the XML file used to boot from disk
Here is dcs01.xml as an example:
<domain type='kvm'> <name>dcs01</name> <uuid>e5fff551-bbe1-e748-c8e4-8ecb3bffb902</uuid> <memory>1048576</memory> <currentMemory>1048576</currentMemory> <vcpu>1</vcpu> <os> <type arch='x86_64' machine='rhel6.0.0'>hvm</type> <boot dev='hd'/> </os> <features> <acpi/> <apic/> <pae/> </features> <clock offset='localtime'/> <on_poweroff>destroy</on_poweroff> <on_reboot>restart</on_reboot> <on_crash>restart</on_crash> <devices> <emulator>/usr/libexec/qemu-kvm</emulator> <disk type='file' device='disk'> <driver name='qemu' type='raw' cache='none'/> <source file='/home/kvm/images/dcs01.img'/> <target dev='hda' bus='ide'/> <address type='drive' controller='0' bus='0' unit='0'/> </disk> <disk type='file' device='cdrom'> <driver name='qemu' type='raw'/> <target dev='hdc' bus='ide'/> <readonly/> <address type='drive' controller='0' bus='1' unit='0'/> </disk> <controller type='ide' index='0'> <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/> </controller> <interface type='bridge'> <mac address='52:54:00:ad:75:98'/> <source bridge='br0'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/> </interface> <input type='tablet' bus='usb'/> <input type='mouse' bus='ps2'/> <graphics type='vnc' port='-1' autoport='yes'/> <video> <model type='vga' vram='9216' heads='1'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/> </video> <memballoon model='virtio'> <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/> </memballoon> </devices> </domain>
Comments are as follows:
1. Kvm guest definition starts
<domain type='kvm'>
2. Short name of guest. It consists of letters and numbers and cannot contain spaces
<name>dcs01</name>
3. uuid, generated by the command line tool uuidgen.
<uuid>e5fff551-bbe1-e748-c8e4-8ecb3bffb902</uuid>
4. The maximum memory that the guest can use without rebooting the guest, in KB.
<memory>1048576</memory>
5. The memory when the guest starts can be passed Use virsh setmem to adjust the memory, but it cannot be larger than the maximum usable memory.
<currentMemory>1048576</currentMemory>
6. Assigned virtual cpu
<vcpu>1</vcpu>
7. Related OS
architecture: i686, x86_64
machine: host operating system
boot: Specify the boot device. You can repeat multiple lines and specify different values as a boot device list.
<os> <type arch='x86_64' machine='rhel6.0.0'>hvm</type> <boot dev='hd'/> </os>
8. Processor features
<features> <acpi/> <apic/> <pae/> </features>
9. Clock. Use local time: localtime
<clock offset='localtime'/>
10. Define the default actions when power off, reboot, or crash in the kvm environment are destroy and restart respectively. Other allowed actions include: preserve, rename-restart.
destroy: Stop the virtual machine. Equivalent to turning off the power.
restartRestart the virtual machine.
<on_poweroff>destroy</on_poweroff> <on_reboot>restart</on_reboot> <on_crash>restart</on_crash>
11. Start of device definition
<devices>
12. Simulation element, the writing method here is used for guest
<emulator>/usr/libexec/qemu-kvm</emulator>
13. File used for kvm storage. In this example, it appears as an IDE device in the guest.
Use the qemu-img command to create this file. The default directory of kvm image is: /var/lib/libvirt/images/
<disk type='file' device='disk'> <driver name='qemu' type='raw' cache='none'/> <source file='/home/kvm/images/dcs01.img'/> <target dev='hda' bus='ide'/> <address type='drive' controller='0' bus='0' unit='0'/> </disk>
Supplement: Multiple disks can be defined.
Use virtio:
Use an ordinary driver, that is, when both the hard disk and the network card adopt the default configuration, the network card works under the simulated rtl 8139 network card, and the speed is 100M full duplex. After using the virtio driver, the network card works in 1000M mode.
Use an ordinary driver, that is, when both the hard disk and the network card adopt the default configuration, the hard disk is in IDE mode. After using the virtio driver, the hard disk works in SCSI mode.
<disk type='file' device='disk'> <driver name='qemu' type='raw'/> <source file='/usr/local/kvm/vmsample/disk.os'/> <target dev='vda' bus='virtio'/> </disk>
CD-ROM device:
<disk type='file' device='cdrom'> <driver name='qemu' type='raw'/> <target dev='hdc' bus='ide'/> <readonly/> <address type='drive' controller='0' bus='1' unit='0'/> </disk>
14. Use the bridge type. Make sure each kvm guest's mac address is unique. A tun device will be created with the name vnetx (x is 0,1,2...)
<interface type='bridge'> <mac address='52:54:00:ad:75:98'/> <source bridge='br0'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/> </interface>
Supplement:
Use the default virtual network instead of the bridge, that is, the guest is in NAT mode. You can also omit the mac address element, so the mac address will be automatically generated.
<interface type='network'> <source network='default'/> <mac address="3B:6E:01:69:3A:11"/> </interface>
The address 192.168.122.x/24 is assigned by default, and can also be specified manually. The gateway is 192.168.122.1
Use virtio:
Use an ordinary driver, that is, when the hard disk and network card are both configured in the default configuration, the network card works under the simulated rtl 8139 network card, with a speed of 100M. duplex. After using the virtio driver, the network card works in 1000M mode.
<interface type='bridge'> <source bridge='br1'/> <model type='virtio' /> </interface>
15. Input device
<input type='tablet' bus='usb'/> <input type='mouse' bus='ps2'/>
16. Define the graphics device that interacts with guset. In this example, the vnc protocol is used. The address of listen is the address of host. prot is -1, which means the port number is automatically assigned. Use the following command to find the port number:
virsh vncdisplay
It is not set here
<graphics type='vnc' port='-1' autoport='yes'/>
17 , Device definition ends
</devices>
18. KVM definition ends
</domain>
centos_x86_6.4
b9dcdd92-9b9b-14d6-3938-1982a9746a12
2097152
2097152
1
hvm
destroy
restart
restart
/bin/qemu-kvm
<disk type='file' device='disk'> <driver name='qemu' type='qcow2'/>
#The destination mirror path in this example, Shown as IDE device in guest.
<source file='/home/template_make/centos_x86_6.4.img'> <seclabel model='selinux' relabel='no'/> </source> <target dev='hda' bus='ide'/> <alias name='ide0-0-0'/> <address type='drive' controller='0' bus='0' target='0' unit='0'/> </disk> <disk type='file' device='cdrom'> <driver name='qemu' type='raw'/> <source file='/home/template_make/CentOS-6.4-x86_64-bin-DVD1.iso'/> <target dev='hdc' bus='ide'/> <readonly/> <alias name='ide0-1-0'/> <address type='drive' controller='0' bus='1' target='0' unit='0'/> </disk> <controller type='usb' index='0'> <alias name='usb0'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/> </controller> <controller type='ide' index='0'> <alias name='ide0'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/> </controller> <interface type='bridge'>
#Virtual machine network connection method
<mac address='52:54:00:78:f9:5a'/> <source bridge='br0'/> <target dev='vnet27'/>
## Use virtio: Use an ordinary driver, that is, when both the hard disk and the network card adopt the default configuration, the hard disk is in ide mode, and the network card works under the simulated rtl 8139 network card, with a speed of 100M full duplex . After using the virtio driver, the network card works in 1000M mode, and the hard disk works in SCSI mode.
<model type='virtio'/> <alias name='net0'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/> </interface> <input type='mouse' bus='ps2'/>
#Log in with vnc, the port number is automatically assigned. You can query [vncdisplay domainId] through virsh vncdisplay
</devices> </domain> unconfined_u:object_r:svirt_image_t:s0:c362,c396
The above is the detailed content of Detailed explanation of the configuration xml code in the KVM virtual machine. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Can XML files be opened with PPT? XML, Extensible Markup Language (Extensible Markup Language), is a universal markup language that is widely used in data exchange and data storage. Compared with HTML, XML is more flexible and can define its own tags and data structures, making the storage and exchange of data more convenient and unified. PPT, or PowerPoint, is a software developed by Microsoft for creating presentations. It provides a comprehensive way of

Using Python to merge and deduplicate XML data XML (eXtensibleMarkupLanguage) is a markup language used to store and transmit data. When processing XML data, sometimes we need to merge multiple XML files into one, or remove duplicate data. This article will introduce how to use Python to implement XML data merging and deduplication, and give corresponding code examples. 1. XML data merging When we have multiple XML files, we need to merge them

Convert XML data in Python to CSV format XML (ExtensibleMarkupLanguage) is an extensible markup language commonly used for data storage and transmission. CSV (CommaSeparatedValues) is a comma-delimited text file format commonly used for data import and export. When processing data, sometimes it is necessary to convert XML data to CSV format for easy analysis and processing. Python is a powerful

Implementing filtering and sorting of XML data using Python Introduction: XML is a commonly used data exchange format that stores data in the form of tags and attributes. When processing XML data, we often need to filter and sort the data. Python provides many useful tools and libraries to process XML data. This article will introduce how to use Python to filter and sort XML data. Reading the XML file Before we begin, we need to read the XML file. Python has many XML processing libraries,

Importing XML data into the database using PHP Introduction: During development, we often need to import external data into the database for further processing and analysis. As a commonly used data exchange format, XML is often used to store and transmit structured data. This article will introduce how to use PHP to import XML data into a database. Step 1: Parse the XML file First, we need to parse the XML file and extract the required data. PHP provides several ways to parse XML, the most commonly used of which is using Simple

Python implements conversion between XML and JSON Introduction: In the daily development process, we often need to convert data between different formats. XML and JSON are common data exchange formats. In Python, we can use various libraries to convert between XML and JSON. This article will introduce several commonly used methods, with code examples. 1. To convert XML to JSON in Python, we can use the xml.etree.ElementTree module

Handling Errors and Exceptions in XML Using Python XML is a commonly used data format used to store and represent structured data. When we use Python to process XML, sometimes we may encounter some errors and exceptions. In this article, I will introduce how to use Python to handle errors and exceptions in XML, and provide some sample code for reference. Use try-except statement to catch XML parsing errors When we use Python to parse XML, sometimes we may encounter some

Python parses special characters and escape sequences in XML XML (eXtensibleMarkupLanguage) is a commonly used data exchange format used to transfer and store data between different systems. When processing XML files, you often encounter situations that contain special characters and escape sequences, which may cause parsing errors or misinterpretation of the data. Therefore, when parsing XML files using Python, we need to understand how to handle these special characters and escape sequences. 1. Special characters and
