第四步:从命令行创建虚拟机 就KVM而言,虚拟机的配置存储在一个域XML文件中。因而,创建虚拟机的第一步是准备好域XML文件。 下面是虚拟机的域XML文件示例。需要的话,你可以使用并定制该域XML文件。 - <domain type='kvm'>
- <name>alicename>
- <uuid>f5b8c05b-9c7a-3211-49b9-2bd635f7e2aauuid>
- <memory>1048576memory>
- <currentMemory>1048576currentMemory>
- <vcpu>1vcpu>
- <os>
- <type>hvmtype>
- <boot dev='cdrom'/>
- os>
- <features>
- <acpi/>
- features>
- <clock offset='utc'/>
- <on_poweroff>destroyon_poweroff>
- <on_reboot>restarton_reboot>
- <on_crash>destroyon_crash>
- <devices>
- <emulator>/usr/bin/kvmemulator>
- <disk type="file" device="disk">
- <driver name="qemu" type="raw"/>
- <source file="/home/dev/images/alice.img"/>
- <target dev="vda" bus="virtio"/>
- <address type="pci" domain="0x0000" bus="0x00" slot="0x04" function="0x0"/>
- disk>
- <disk type="file" device="cdrom">
- <driver name="qemu" type="raw"/>
- <source file="/home/dev/iso/ubuntu-13.10-server-amd64.iso"/>
- <target dev="hdc" bus="ide"/>
- <readonly/>
- <address type="drive" controller="0" bus="1" target="0" 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:aa:00:f0:51'/>
- <source bridge='br0'/>
- interface>
- <input type='mouse' bus='ps2'/>
- <graphics type='vnc' port='-1' autoport="yes" listen='127.0.0.1'/>
- devices>
- domain>
上面这个域XML文件定义了下面这个虚拟机。 - 1GB内存、一个虚拟处理器和一只硬驱。
- 磁盘映像:/home/dev/images/alice.img
- 从光盘驱动器启动(/home/dev/iso/ubuntu-13.10-server-amd64.iso)。
- 网络:通过br0实现桥接网络。
里面的UUID字符串可以随机生成。想获得一个随机性的UUID,你可以使用uuid命令行工具。 - $ sudo apt-get install uuid
- $ uuid
创建域XML文件的另一个方法是,转储现有虚拟机的域信息,如下所示。 - $ virsh --connect qemu:///system dumpxml alice > bob.xml

|