使用virsh创建虚拟机

第一步,创建一个虚拟机的硬盘,将来来存放虚拟操作系统的.这个虚拟硬盘是利用文件系统来进行模拟的.

qemu-img create -f qcow2  -o preallocation=full /var/lib/libvirt/images/test.qcow2 15G  

第二步,新建一个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>

创建虚拟机 :

virsh define centos.xml   ###将配置导入到虚拟机
virsh start centos    #### 启动虚拟机

 

 

 

 

 

 

转载于:https://my.oschina.net/jaakan/blog/820257

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值