virsh创建虚拟机

使用virsh命令创建虚拟机

两个必不可少的条件:1 XML 2 *. img

xml文件格式如下:

<!--
WARNING: THIS IS AN AUTO-GENERATED FILE. CHANGES TO IT ARE LIKELY TO BE
OVERWRITTEN AND LOST. Changes to this xml configuration should be made using:
  virsh edit ubuntu
or other application using the libvirt API.
-->

<domain type='kvm'>
  <name>ubuntu08</name>
  <uuid>e331a53f-2b2b-4511-880f-af62a0ce49fc</uuid>
  <memory unit='KiB'>2097152</memory>
  <currentMemory unit='KiB'>2097152</currentMemory>
  <vcpu placement='static'>1</vcpu>
  <os>
    <type arch='x86_64' machine='pc-1.0'>hvm</type>
    <boot dev='hd'/>
  </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='/var/lib/libvirt/ubuntu.img'/>
      <target dev='hda' bus='ide'/>
      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
    </disk>
    <controller type='usb' index='0'>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
    </controller>
    <controller type='pci' index='0' model='pci-root'/>
    <controller type='ide' index='0'>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
    </controller>
    <interface type='bridge'>
      <mac address='52:54:6e:e2:ec:a5'/>
      <source bridge='br0'/>
      <model type='rtl8139'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
    </interface>
    <input type='tablet' bus='usb'/>
    <input type='mouse' bus='ps2'/>
    <graphics type='vnc' port='-1' autoport='yes' listen='0.0.0.0' passwd='123456'>
      <listen type='address' address='0.0.0.0'/>
    </graphics>
    <video>
      <model type='cirrus' vram='9216' heads='1'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
    </video>
    <memballoon model='virtio'>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
    </memballoon>
  </devices>
</domain>
创建虚拟机

virsh define ubuntu.xml

查看新建虚拟机

root@ubuntu1204:/var/www/noVNC# virsh list --all
 Id    Name                           State
----------------------------------------------------
 -     ubuntu08                       shut off

开启虚拟机

root@ubuntu1204:/usr/local/etc/libvirt/qemu# virsh start ubuntu
出现以下问题

error: Failed to start domain ubuntu
error: internal error: process exited while connecting to monitor: Unsupported cluster size: 2^1471800577kvm: -drive file=/var/lib/libvirt/images/ububtu.img,if=none,id=drive-ide0-0-0,format=qcow2: could not open disk image /var/lib/libvirt/images/ubuntu.img: Invalid argument
查看镜像格式

root@ubuntu1204:/var/lib/libvirt/images# qemu-img info ubuntu.img 
image: ubuntu.img
file format: raw
virtual size: 8.0G (8590761984 bytes)
disk size: 8.0G
可以看到ubuntu.img的格式是raw,而XML文件中描述的镜像格式是qcow2,将XML中

<driver name='qemu' type='qcow2'/>	修改为		<driver name='qemu' type='raw'/>
删除虚拟机,重新创建

root@ubuntu1204:/#virsh undefine ubuntu

 
root@ubuntu1204:/#virsh define ubuntu
 
root@ubuntu1204:/# virsh start ubuntu08
Domain ubuntu08 started
查看虚拟机vnc端口

root@ubuntu1204:/# virsh vncdisplay ubuntu
:0
使用vncviewer连接,成功进入虚拟机,创建完成











  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值