libvirt[未完待续]

简介

qcow2介绍

xml配置文件介绍

在安装好虚拟机后,虽然我们后加了2个网卡,但是由于xml中这里还是定义了1个。所以如果把img镜像和xml文件拿去创建新的虚拟机,这里仍然还是只会创建一个网卡。

    <interface type='bridge'>
      <mac address='52:54:00:9b:71:9d'/>
      <source bridge='br0'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
    </interface>

创建虚拟机

  1. 创建磁盘
qemu-img create -f qcow2 app.img 128G
  1. 我出问题的安装
    第一种安装方法,界面式的。也就是选择从镜像加载系统,创建磁盘的时候选择上刚刚创建的磁盘。但是这种方式有时会提示磁盘空间不足。
    譬如我在下面这种情况下就遇到了:
    a. home目录很大
    b. libvirt用的/var/libvirt已经基本用光
    这时候新加载就会出问题。

  2. 从脚本安装
    libvirt由一个img镜像,和一个xml配置文件构成。
    前面我们手工创建了镜像,这里手工做一个配置文件就好了。

<domain type='kvm'>
  <name>app</name>
  <memory unit='KiB'>10485760</memory>
  <currentMemory unit='KiB'>10485760</currentMemory>
  <vcpu placement='static'>8</vcpu>
  <os>
    <type arch='x86_64' machine='pc'>hvm</type>
    <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/libexec/qemu-kvm</emulator>
    <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2' cache='none'/>
      <source file='/home/vm/app.img'/>
      <target dev='hda' bus='ide'/>
    </disk>

    <disk type='file' device='cdrom'>
      <source file='/CentOS-6.5-x86_64-bin-DVD1.iso'/>
      <target dev='hdb' bus='ide'/>
    </disk>
    <controller type='usb' index='0'>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
    </controller>
    <controller type='ide' index='0'>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
    </controller>
    <interface type='bridge'>
      <mac address='52:54:00:9b:71:9d'/>
      <source bridge='br0'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
    </interface>
    <serial type='pty'>
      <target port='0'/>
    </serial>
    <console type='pty'>
      <target type='serial' port='0'/>
    </console>
    <input type='mouse' bus='ps2'/>
    <graphics type='vnc' port='-1' autoport='yes'/>
    <sound model='ich6'>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
    </sound>
    <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>

主要修改了下面这些:

...
<type arch='x86_64' machine='pc'>hvm</type>
...
<driver name='qemu' type='qcow2' cache='none'/>
<source file='/home/vm/ads.app.img'/>
...
<disk type='file' device='cdrom'>
      <source file='/CentOS-6.5-x86_64-bin-DVD1.iso'/>
      <target dev='hdb' bus='ide'/>
    </disk>
...

脚本安装完成后,执行如下命令,将镜像加载进virtual manager
virsh define ads.app.xml

在virtual manager页面,上电正常安装linux即可

装完后,把iso那个镜像去掉,未来就可以把这个小镜像拷贝复制出去

常用命令

brctl show
virsh define xxx.xml
virsh start xxx
virsh destroy xxx
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值