title: How to build libvirt box from scratch
body: <p>I'm trying to build vagrant libvirt box from scratch.</p>
  
  <p>I insttalled ubuntu 14.04 and used <a href="https://blog.engineyard.com/2014/building-a-vagrant-box" rel="nofollow noreferrer">this</a> tutorial to prepare machine for vagrant using and then I used command <code>virsh domblklist test</code> to find my image file, so i find it here <code>/var/lib/libvirt/images/test.img</code> and then copied to place where I'm going to package my vagrant box. Then I converted my raw image file to qcow2 format (beacause <a href="https://github.com/pradels/vagrant-libvirt/tree/master/example_box" rel="nofollow noreferrer">this</a> page says that only qcow2 format supported) with <code>sudo qemu-img convert -f raw -O qcow2  test.img  test.qcow2</code> command. Finally to get things done I executed <code>vagrant init test</code> and created <strong>metadata.json</strong> file with this in it </p>
  
  <pre><code>{
    "provider"     : "libvirt",
    "format"       : "qcow2",
    "virtual_size" : 8
  }
  </code></pre>
  
  <p>And then I used command <code>tar cvzf vltest.box ./metadata.json ./Vagrantfile ./box.img</code> to get things together in one box. Then I added box to vagrant with <code>vagrant box add test.img test</code>.</p>
  
  <p>Then I tried to run machine with </p>
  
  <pre><code>vagrant init test
  vagrant up --provider=libvirt
  </code></pre>
  
  <p>But it stuck here:</p>
  
  <pre><code>...
  ==&gt; default:  -- Video VRAM:        9216
  ==&gt; default:  -- Keymap:            en-us
  ==&gt; default:  -- INPUT:             type=mouse, bus=ps2
  ==&gt; default:  -- Command line : 
  ==&gt; default: Creating shared folders metadata...
  ==&gt; default: Starting domain.
  ==&gt; default: Waiting for domain to get an IP address...
  </code></pre>
  
  <p>Then I decided to open machine and that was what I saw:</p>
  
  <p><a href="https://i.stack.imgur.com/HucNI.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/HucNI.png" alt="enter image description here"></a></p>
  
  <p>Here is origin machine configurations:</p>
  
  <pre><code>&lt;domain type='kvm'&gt;
    &lt;name&gt;test&lt;/name&gt;
    &lt;uuid&gt;50c605f7-c06c-4288-bd03-f17575345171&lt;/uuid&gt;
    &lt;memory unit='KiB'&gt;1048576&lt;/memory&gt;
    &lt;currentMemory unit='KiB'&gt;1048576&lt;/currentMemory&gt;
    &lt;vcpu placement='static'&gt;1&lt;/vcpu&gt;
    &lt;os&gt;
      &lt;type arch='x86_64' machine='pc-i440fx-trusty'&gt;hvm&lt;/type&gt;
      &lt;boot dev='hd'/&gt;
    &lt;/os&gt;
    &lt;features&gt;
      &lt;acpi/&gt;
      &lt;apic/&gt;
      &lt;pae/&gt;
    &lt;/features&gt;
    &lt;clock offset='utc'/&gt;
    &lt;on_poweroff&gt;destroy&lt;/on_poweroff&gt;
    &lt;on_reboot&gt;restart&lt;/on_reboot&gt;
    &lt;on_crash&gt;restart&lt;/on_crash&gt;
    &lt;devices&gt;
      &lt;emulator&gt;/usr/bin/kvm-spice&lt;/emulator&gt;
      &lt;disk type='file' device='disk'&gt;
        &lt;driver name='qemu' type='raw'/&gt;
        &lt;source file='/var/lib/libvirt/images/test.img'/&gt;
        &lt;target dev='vda' bus='virtio'/&gt;
        &lt;address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/&gt;
      &lt;/disk&gt;
      &lt;disk type='block' device='cdrom'&gt;
        &lt;driver name='qemu' type='raw'/&gt;
        &lt;target dev='hdc' bus='ide'/&gt;
        &lt;readonly/&gt;
        &lt;address type='drive' controller='0' bus='1' target='0' unit='0'/&gt;
      &lt;/disk&gt;
      &lt;controller type='usb' index='0'&gt;
        &lt;address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/&gt;
      &lt;/controller&gt;
      &lt;controller type='pci' index='0' model='pci-root'/&gt;
      &lt;controller type='ide' index='0'&gt;
        &lt;address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/&gt;
      &lt;/controller&gt;
      &lt;interface type='network'&gt;
        &lt;mac address='52:54:00:6c:05:1b'/&gt;
        &lt;source network='default'/&gt;
        &lt;model type='virtio'/&gt;
        &lt;address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/&gt;
      &lt;/interface&gt;
      &lt;serial type='pty'&gt;
        &lt;target port='0'/&gt;
      &lt;/serial&gt;
      &lt;console type='pty'&gt;
        &lt;target type='serial' port='0'/&gt;
      &lt;/console&gt;
      &lt;input type='mouse' bus='ps2'/&gt;
      &lt;input type='keyboard' bus='ps2'/&gt;
      &lt;graphics type='vnc' port='-1' autoport='yes'/&gt;
      &lt;sound model='ich6'&gt;
        &lt;address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/&gt;
      &lt;/sound&gt;
      &lt;video&gt;
        &lt;model type='cirrus' vram='9216' heads='1'/&gt;
        &lt;address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/&gt;
      &lt;/video&gt;
      &lt;memballoon model='virtio'&gt;
        &lt;address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/&gt;
      &lt;/memballoon&gt;
    &lt;/devices&gt;
  &lt;/domain&gt;
  </code></pre>
  
  <p>Here is configuration of newly generated vagrant box:</p>
  
  <pre><code>&lt;domain type='kvm' id='8'&gt;
    &lt;name&gt;testLibvirt_default&lt;/name&gt;
    &lt;uuid&gt;00069068-f4bc-41fa-b316-870e78fbe393&lt;/uuid&gt;
    &lt;memory unit='KiB'&gt;524288&lt;/memory&gt;
    &lt;currentMemory unit='KiB'&gt;524288&lt;/currentMemory&gt;
    &lt;vcpu placement='static'&gt;1&lt;/vcpu&gt;
    &lt;resource&gt;
      &lt;partition&gt;/machine&lt;/partition&gt;
    &lt;/resource&gt;
    &lt;os&gt;
      &lt;type arch='x86_64' machine='pc-i440fx-trusty'&gt;hvm&lt;/type&gt;
      &lt;boot dev='hd'/&gt;
    &lt;/os&gt;
    &lt;features&gt;
      &lt;acpi/&gt;
      &lt;apic/&gt;
      &lt;pae/&gt;
    &lt;/features&gt;
    &lt;cpu mode='host-model'&gt;
      &lt;model fallback='allow'/&gt;
    &lt;/cpu&gt;
    &lt;clock offset='utc'/&gt;
    &lt;on_poweroff&gt;destroy&lt;/on_poweroff&gt;
    &lt;on_reboot&gt;restart&lt;/on_reboot&gt;
    &lt;on_crash&gt;destroy&lt;/on_crash&gt;
    &lt;devices&gt;
      &lt;emulator&gt;/usr/bin/kvm-spice&lt;/emulator&gt;
      &lt;disk type='file' device='disk'&gt;
        &lt;driver name='qemu' type='qcow2'/&gt;
        &lt;source file='/var/lib/libvirt/images/testLibvirt_default.img'/&gt;
        &lt;target dev='vda' bus='virtio'/&gt;
        &lt;alias name='virtio-disk0'/&gt;
        &lt;address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/&gt;
      &lt;/disk&gt;
      &lt;controller type='usb' index='0'&gt;
        &lt;alias name='usb0'/&gt;
        &lt;address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/&gt;
      &lt;/controller&gt;
      &lt;controller type='pci' index='0' model='pci-root'&gt;
        &lt;alias name='pci.0'/&gt;
      &lt;/controller&gt;
      &lt;interface type='network'&gt;
        &lt;mac address='52:54:00:91:b2:63'/&gt;
        &lt;source network='vagrant-libvirt'/&gt;
        &lt;target dev='vnet0'/&gt;
        &lt;model type='virtio'/&gt;
        &lt;alias name='net0'/&gt;
        &lt;address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/&gt;
      &lt;/interface&gt;
      &lt;serial type='pty'&gt;
        &lt;source path='/dev/pts/8'/&gt;
        &lt;target port='0'/&gt;
        &lt;alias name='serial0'/&gt;
      &lt;/serial&gt;
      &lt;console type='pty' tty='/dev/pts/8'&gt;
        &lt;source path='/dev/pts/8'/&gt;
        &lt;target type='serial' port='0'/&gt;
        &lt;alias name='serial0'/&gt;
      &lt;/console&gt;
      &lt;input type='mouse' bus='ps2'/&gt;
      &lt;input type='keyboard' bus='ps2'/&gt;
      &lt;graphics type='vnc' port='5900' autoport='yes' listen='127.0.0.1' keymap='en-us'&gt;
        &lt;listen type='address' address='127.0.0.1'/&gt;
      &lt;/graphics&gt;
      &lt;video&gt;
        &lt;model type='cirrus' vram='9216' heads='1'/&gt;
        &lt;alias name='video0'/&gt;
        &lt;address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/&gt;
      &lt;/video&gt;
      &lt;memballoon model='virtio'&gt;
        &lt;alias name='balloon0'/&gt;
        &lt;address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/&gt;
      &lt;/memballoon&gt;
    &lt;/devices&gt;
    &lt;seclabel type='dynamic' model='apparmor' relabel='yes'&gt;
      &lt;label&gt;libvirt-00069068-f4bc-41fa-b316-870e78fbe393&lt;/label&gt;
      &lt;imagelabel&gt;libvirt-00069068-f4bc-41fa-b316-870e78fbe393&lt;/imagelabel&gt;
    &lt;/seclabel&gt;
  &lt;/domain&gt;
  </code></pre>
  
  <p>Update:
  Also I tried <a href="https://www.packer.io/" rel="nofollow noreferrer">packer</a> but get the same error, when grub shows up.
  Here is my template for packer:</p>
  
  <pre><code>{
      "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"
          }
      ]
  }
  </code></pre>
  
  <p>ISO file of ubuntu 14.04 I downloaded from ubuntu site.</p>
  
  <p>So my questions are:</p>
  
  <ol>
  <li>What I did wrong and how to solve that</li>
  <li>Is there more proper way of building vagrant libvirt boxes from scratch</li>
  </ol>