KVM 虚拟化已经是一个工业级的虚拟化解决方案了,以前都是直接下载 VMware,然后安装其他操作系统的,今天我们来体验一下自己动手创建一台虚拟机,这样你就会知道在KVM下创建一台虚拟机,是多么简单的一件事情了,哈哈

step 1 : 首先我们需要检查一下我们的当前主机是否支持cpu虚拟化(如果出现下图,就是支持cpu虚拟化了):

KVM---利用 libvirt+qemu-kvm 创建虚拟机

step 2 : 然后我们需要安装一些必要的包:

KVM---利用 libvirt+qemu-kvm 创建虚拟机

KVM---利用 libvirt+qemu-kvm 创建虚拟机

KVM---利用 libvirt+qemu-kvm 创建虚拟机

step 3: 然后我们需要一个虚拟磁盘,相当于我们的系统盘(可以直接用 qemu-img 工具制作,具体使用方式可以用 qemu-img --help 查看,这个工具在上面的包安装过程中已被默认安装):

KVM---利用 libvirt+qemu-kvm 创建虚拟机

step 4 : 然后我们需要一个定义虚拟机配置的文件,一般用 xml 文件来描述(示例文件,配置不是很详细和充分):

<name>centos</name>
        <memory>1048576</memory>
        <currentMemory>1048576</currentMemory>
        <vcpu>2</vcpu>

        <os>
                <type arch='x86_64' machine='pc'>hvm</type>
                <boot dev='ha'/>
        </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='/home/zhangpeng/test.qcow2'/>
                        <target dev='hda' bus='ide'/>
                </disk>

                <disk type='file' device='cdrom'>
                        <source file='/home/zhangpeng/centos.iso'/>
                        <target dev='hdb' bus='ide'/>
                </disk>

                <interface type='bridge'>
                        <source bridge='default'/>
                        <mac address="00:16:3e:5d:aa:a8"/>
                </interface>

                <input type='mouse' bus='ps2'/>
                <graphics type='vnc' port='-1' autoport='yes' listen='0.0.0.0' keymap='en-us'/>
        </devices>
</domain>
          

centos_config.xml
centos_config.xml

相关文章: