如何从头开始构建libvirt框

时间:2016-02-19 22:25:53

标签: vagrant virtual-machine libvirt packer virsh

我试图从零开始建造流浪的libvirt盒子。

我指示ubuntu 14.04并使用this教程为使用流浪汉准备机器然后我使用命令virsh domblklist test来查找我的图像文件,所以我在这里找到它/var/lib/libvirt/images/test.img然后复制放在我打包我的流浪盒的地方。然后我使用sudo qemu-img convert -f raw -O qcow2 test.img test.qcow2命令将我的原始图像文件转换为qcow2格式(因为this页面表示只支持qcow2格式)。最后,为了完成工作,我执行了vagrant init test并在其中创建了 metadata.json 文件

{
  "provider"     : "libvirt",
  "format"       : "qcow2",
  "virtual_size" : 8
}

然后我使用命令tar cvzf vltest.box ./metadata.json ./Vagrantfile ./box.img将一起放在一起。然后我用vagrant box add test.img test向流氓添加了框。

然后我尝试用

运行机器
vagrant init test
vagrant up --provider=libvirt

但它坚持到这里:

...
==> default:  -- Video VRAM:        9216
==> default:  -- Keymap:            en-us
==> default:  -- INPUT:             type=mouse, bus=ps2
==> default:  -- Command line : 
==> default: Creating shared folders metadata...
==> default: Starting domain.
==> default: Waiting for domain to get an IP address...

然后我决定打开机器,这就是我所看到的:

enter image description here

这是原始机器配置:

<domain type='kvm'>
  <name>test</name>
  <uuid>50c605f7-c06c-4288-bd03-f17575345171</uuid>
  <memory unit='KiB'>1048576</memory>
  <currentMemory unit='KiB'>1048576</currentMemory>
  <vcpu placement='static'>1</vcpu>
  <os>
    <type arch='x86_64' machine='pc-i440fx-trusty'>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/bin/kvm-spice</emulator>
    <disk type='file' device='disk'>
      <driver name='qemu' type='raw'/>
      <source file='/var/lib/libvirt/images/test.img'/>
      <target dev='vda' bus='virtio'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
    </disk>
    <disk type='block' device='cdrom'>
      <driver name='qemu' type='raw'/>
      <target dev='hdc' bus='ide'/>
      <readonly/>
      <address type='drive' controller='0' bus='1' 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='network'>
      <mac address='52:54:00:6c:05:1b'/>
      <source network='default'/>
      <model type='virtio'/>
      <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'/>
    <input type='keyboard' 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='0x06' function='0x0'/>
    </memballoon>
  </devices>
</domain>

这是新生成的流浪盒的配置:

<domain type='kvm' id='8'>
  <name>testLibvirt_default</name>
  <uuid>00069068-f4bc-41fa-b316-870e78fbe393</uuid>
  <memory unit='KiB'>524288</memory>
  <currentMemory unit='KiB'>524288</currentMemory>
  <vcpu placement='static'>1</vcpu>
  <resource>
    <partition>/machine</partition>
  </resource>
  <os>
    <type arch='x86_64' machine='pc-i440fx-trusty'>hvm</type>
    <boot dev='hd'/>
  </os>
  <features>
    <acpi/>
    <apic/>
    <pae/>
  </features>
  <cpu mode='host-model'>
    <model fallback='allow'/>
  </cpu>
  <clock offset='utc'/>
  <on_poweroff>destroy</on_poweroff>
  <on_reboot>restart</on_reboot>
  <on_crash>destroy</on_crash>
  <devices>
    <emulator>/usr/bin/kvm-spice</emulator>
    <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2'/>
      <source file='/var/lib/libvirt/images/testLibvirt_default.img'/>
      <target dev='vda' bus='virtio'/>
      <alias name='virtio-disk0'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
    </disk>
    <controller type='usb' index='0'>
      <alias name='usb0'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
    </controller>
    <controller type='pci' index='0' model='pci-root'>
      <alias name='pci.0'/>
    </controller>
    <interface type='network'>
      <mac address='52:54:00:91:b2:63'/>
      <source network='vagrant-libvirt'/>
      <target dev='vnet0'/>
      <model type='virtio'/>
      <alias name='net0'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
    </interface>
    <serial type='pty'>
      <source path='/dev/pts/8'/>
      <target port='0'/>
      <alias name='serial0'/>
    </serial>
    <console type='pty' tty='/dev/pts/8'>
      <source path='/dev/pts/8'/>
      <target type='serial' port='0'/>
      <alias name='serial0'/>
    </console>
    <input type='mouse' bus='ps2'/>
    <input type='keyboard' bus='ps2'/>
    <graphics type='vnc' port='5900' autoport='yes' listen='127.0.0.1' keymap='en-us'>
      <listen type='address' address='127.0.0.1'/>
    </graphics>
    <video>
      <model type='cirrus' vram='9216' heads='1'/>
      <alias name='video0'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
    </video>
    <memballoon model='virtio'>
      <alias name='balloon0'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
    </memballoon>
  </devices>
  <seclabel type='dynamic' model='apparmor' relabel='yes'>
    <label>libvirt-00069068-f4bc-41fa-b316-870e78fbe393</label>
    <imagelabel>libvirt-00069068-f4bc-41fa-b316-870e78fbe393</imagelabel>
  </seclabel>
</domain>

更新: 此外,我尝试了packer,但是当grub显示时会出现同样的错误。 这是我的包装工模板:

{
    "builders":
    [
      {
        "type": "qemu",
        "iso_url": "/home/galiaf95/Downloads/ubuntu-14.04.3-desktop-amd64.iso",
        "iso_checksum": "cab6dd5ee6d649ed1b24e807c877c0ae",
        "iso_checksum_type": "md5",
        "output_directory": "output_centos_tdhtest",
        "shutdown_command": "shutdown -P now",
        "disk_size": 8000,
        "format": "qcow2",
        "headless": false,
        "accelerator": "kvm",
        "http_port_min": 10082,
        "http_port_max": 10089,
        "ssh_host_port_min": 2222,
        "ssh_host_port_max": 2229,
        "ssh_username": "vagrant",
        "ssh_password": "vagrant",
        "ssh_port": 22,
        "ssh_wait_timeout": "7200s",
        "vm_name": "tdhtest",
        "net_device": "virtio-net",
        "disk_interface": "virtio"
      }
    ],
    "post-processors": [
        {
            "keep_input_artifact": false,
            "output": "box/ubuntu-1404-server.box",
            "type": "vagrant"
        }
    ]
}

我从ubuntu网站下载的ubuntu 14.04的ISO文件。

所以我的问题是:

  1. 我做错了什么以及如何解决
  2. 是否有更合适的方法从头开始建造流浪者的libvirt盒子

1 个答案:

答案 0 :(得分:0)

  

我做错了什么以及如何解决

无法帮助我

  

是否有更合适的方式   从头开始建造流浪者的libvirt盒子

我建议使用packer作为[v 0.7.2]( https://www.polibyte.com/blog/packer_supports_vagrant-libvirt)packer支持vagrant-libvirt