美文网首页
qemu-kvm创建虚拟机

qemu-kvm创建虚拟机

作者: yanest_张岩 | 来源:发表于2015-08-08 16:46 被阅读499次

创建桥接

编辑/etc/network/interface

auto lo
iface lo inet loopback

auto eth0
iface eth0 inet manual

auto br0
iface br0 inet static
  address 192.168.50.199
  netmask 255.255.255.0
  gateway 192.168.50.1
  dns-nameservers 114.114.114.114
  bridge_ports eth0
  bridge_stp off
  bridge_waitport 0
  bridge_fd 0

创建虚拟磁盘

qemu-img create -f qcow2 ubuntu_base.img 20G

安装系统

kvm -m 1024 -drive file=ubuntu_base.img,if=virtio -cdrom /root/ubuntu-14.04.3-server-amd64.iso --nographic -vnc :0

windows安装virtio驱动

kvm -m -1024 -drive file=windows.img,if=virtio \
-cdrom windows7.iso \
-drive file=virtio-win-iso,index=3,media=cdrom \
--nographics -vnc:0

创建xml文件

<domain type="kvm">
  <name>first-ubuntu</name>
  <memory unit="MiB">1024</memory>
  <currentMemory unit="MiB">1024</currentMemory>
  <vcpu current="1">2</vcpu>
  <os>
    <type arch="x86_64" machine="pc">hvm</type>
    <!--
    <boot dev="cdrom"/>
    -->
    <boot dev="hd"/>
  </os>
  <features>
    <acpi/>
    <apic/>
    <pae/>
  </features>
  <clock offset="utc"/>
  <on_poweroff>destroy</on_poweroff>
  <on_reboot>restart</on_reboot>
  <on_crash>restart</on_crash>
  <devices>
    <emulator>/usr/bin/qemu-system-x86_64</emulator>
    <disk device="disk" type="file">
      <driver cache="none" name="qemu" type="qcow2"/>
      <source file="/vm/ubuntu_base.img"/>
      <target dev="vda"/>
    </disk>
    <!--
    <disk type='file' device='cdrom'>
      <driver name='qemu' type='raw'/>
      <source file='/tmp/ubuntu-12.04.2-server-amd64.iso'/>
      <target dev="hda"/>
      <readonly/>
    </disk>
    -->
    <input bus="ps2" type="mouse"/>
    <interface type="bridge">
      <source bridge="br0"/>
      <model type="virtio"/>
    </interface>
    <serial/>
    <console/>
    <graphics autoport="yes" listen="0.0.0.0" port="-1" tlsPort="-1" type="vnc">
      <listen address="0.0.0.0" type="address"/>
    </graphics>
    <video>
      <model heads="1" type="cirrus" vram="9126"/>
    </video>
    <memballoon model="virtio"/>
  </devices>
</domain>

用xml文件启动虚拟机

virsh create ubuntu_base.xml

相关文章

网友评论

      本文标题:qemu-kvm创建虚拟机

      本文链接:https://www.haomeiwen.com/subject/ifobqttx.html