zoukankan      html  css  js  c++  java
  • 命令行创建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    #### 启动虚拟机
  • 相关阅读:
    Linux下查看tomcat版本
    React跳转路由传参3种方法和区别
    pc端布局方案
    vue针对搜索引擎做SEO优化
    vue-cli3配置vue.config.js持续更新
    MySQL连接语法(多表查询)
    MySQL约束和外键约束
    MySQL数据库查询
    MySQL数据库入门
    jQuery用法和bootstrap框架
  • 原文地址:https://www.cnblogs.com/scu-cjx/p/6879010.html
Copyright © 2011-2022 走看看