使用virsh命令创建虚拟机
两个必不可少的条件:1 XML 2 *. img
xml文件格式如下:
<!--
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 ubuntu
or other application using the libvirt API.
-->
<domain type='kvm'>
<name>ubuntu08</name>
<uuid>e331a53f-2b2b-4511-880f-af62a0ce49fc</uuid>
<memory unit='KiB'>2097152</memory>
<currentMemory unit='KiB'>2097152</currentMemory>
<vcpu placement='static'>1</vcpu>
<os>
<type arch='x86_64' machine='pc-1.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>destroy</on_crash>
<devices>
<emulator>/usr/bin/kvm</emulator>
<disk type='file' device='disk'>
<driver name='qemu' type='qcow2'/>
<source file='/var/lib/libvirt/ubuntu.img'/>
<target dev='hda' bus='ide'/>
<address type='drive' controller='0' bus='0' target='0' unit='0'/>
</disk>
<controller type='usb' index='0'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x01' 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>
<interface type='bridge'>
<mac address='52:54:6e:e2:ec:a5'/>
<source bridge='br0'/>
<model type='rtl8139'/>
<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' listen='0.0.0.0' passwd='123456'>
<listen type='address' address='0.0.0.0'/>
</graphics>
<video>
<model type='cirrus' 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>
创建虚拟机
virsh define ubuntu.xml
查看新建虚拟机
root@ubuntu1204:/var/www/noVNC# virsh list --all
Id Name State
----------------------------------------------------
- ubuntu08 shut off
开启虚拟机
root@ubuntu1204:/usr/local/etc/libvirt/qemu# virsh start ubuntu
出现以下问题
error: Failed to start domain ubuntu
error: internal error: process exited while connecting to monitor: Unsupported cluster size: 2^1471800577kvm: -drive file=/var/lib/libvirt/images/ububtu.img,if=none,id=drive-ide0-0-0,format=qcow2: could not open disk image /var/lib/libvirt/images/ubuntu.img: Invalid argument
查看镜像格式
root@ubuntu1204:/var/lib/libvirt/images# qemu-img info ubuntu.img
image: ubuntu.img
file format: raw
virtual size: 8.0G (8590761984 bytes)
disk size: 8.0G
可以看到ubuntu.img的格式是raw,而XML文件中描述的镜像格式是qcow2,将XML中
<driver name='qemu' type='qcow2'/> 修改为 <driver name='qemu' type='raw'/>
删除虚拟机,重新创建
root@ubuntu1204:/#virsh undefine ubuntu
root@ubuntu1204:/#virsh define ubuntu
root@ubuntu1204:/# virsh start ubuntu08
Domain ubuntu08 started
查看虚拟机vnc端口
root@ubuntu1204:/# virsh vncdisplay ubuntu
:0
使用vncviewer连接,成功进入虚拟机,创建完成