命令行創建KVM虛擬機


qemu命令創建虛擬機:

qemu-img create -f qcow2 /home/ubuntu.img 20G

 
qemu-system-x86_64 -m 2048 -enable-kvm -hda /home/ubuntu.img -cdrom ./ubuntu-14.04.4-desktop-amd64.iso -boot d
 
qemu-system-x86_64 --enable-kvm -m 1024 -boot menu=on /home/ubuntu.img -vnc :10
 
 
virsh命令創建虛擬機:

1、使用dd創建虛擬機硬盤

dd if=/dev/zero of=centos.img bs=2k seek=4096k count=1

 2、新建一個xml文件,里面存放虛擬機的配置信息,有內存、cpu、硬盤位置、光驅、VNC等配置,我們先貼出一個demo

<domain type="kvm">
    <name>centos</name>  <!--虛擬機名稱-->
    <memory unit="MiB">1024</memory>   <!--最大內存,單位k-->
    <currentMemory unit="MiB">1024</currentMemory>  <!--可用內存,單位k-->
    <vcpu>2</vcpu>   <!--//虛擬cpu個數-->
    <os>
        <type arch="x86_64" machine="pc">hvm</type>
        <boot dev="hd" /> <!-- 硬盤啟動 -->
        <boot dev="cdrom" />     <!--//光盤啟動-->
    </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/libexec/qemu-kvm</emulator>
        <disk type="file" device="disk">
            <driver name="qemu" type="qcow2" />
            <source file="/var/lib/libvirt/images/test.qcow2" />        <!--目的鏡像路徑-->
            <target dev="hda" bus="ide" />
        </disk>
        <disk type="file" device="cdrom">
            <source file="/var/lib/libvirt/images/ubuntu.iso" />        <!--光盤鏡像路徑 -->
            <target dev="hdb" bus="ide" />
        </disk>
        <interface type="bridge">       <!--虛擬機網絡連接方式-->
            <source bridge="br0" />      <!--當前主機網橋的名稱-->
        </interface>
        <input type="mouse" bus="ps2" />
        <!--vnc方式登錄,端口號自動分配,自動加1,可以通過virsh vncdisplay來查詢-->
        <graphics type="vnc" port="-1" autoport="yes" listen="0.0.0.0" keymap="en-us" />
    </devices>
</domain>

3、創建虛擬機

virsh define centos.xml   ###將配置導入到虛擬機
virsh start centos    #### 啟動虛擬機


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM