title: How to boot up from CDROM(ISO image) to install the guest OS using virsh
body: <p>UPDATE on Oct. 4th, 2017: See my answer below. The credit goes to DanielB as I wouldn't have solved the problem without Daniel's help, so I'll accept his answer instead of my own.</p>
  
  <hr>
  
  <p>I'm a novice in libvirt as well as system administration so excuse me if I'm asking stupid questions, though I've tried to do as much homework as possible beforehand.</p>
  
  <p><strong>My question is</strong>: How to boot up from CDROM to install the guest OS right after creating a VM using virsh?</p>
  
  <p>I'm working on Ubuntu Desktop 14.04, virsh 1.2.2.</p>
  
  <p>When I used 'virt-install' and passed the ISO file path as its '--cdrom' argument, I could successfully bring up the virt-viewer window which allowed me to go through the guest OS installation.</p>
  
  <p>As I know I can also create a VM using an XML definition, I dumped the XML definition of the VM which I created using 'virt-install'. I then expected that the 'virt-viewer' window would be brought up automatically when I started the VM so I could install the guest OS. But it didn't.</p>
  
  <p>Below is the XML definition of my VM.</p>
  
  <p>If I enable the loader line, as I marked as "suspicious" below, I would get an error message of "error: internal error: cannot load AppArmor profile 'libvirt-1092d51d-3b66-46a2-bf9b-71e13dc91799'". I did that because I was trying the example given in <a href="http://libvirt.org/formatdomain.html#elementsOSBIOS" rel="nofollow noreferrer">libvirt's document here</a>.</p>
  
  <p>However, if I disable the "loader" line, and ran <code>virsh create def_domain_test.xml</code>, the domain can be created successfully and is shown as 'running', but <strong>the virt-viewer window is not brought up, so I can't install the guest OS on the VM</strong>.</p>
  
  <p><strong>Could anyone help me on that?</strong> I don't understand why 'virt-install' can bring up the virt-viewer but my XML definition can't. I probably mis-configured the domain XML definition but I couldn't figure out which specific part I was wrong even if I'd tried to read as much documentation as possible.</p>
  
  <p>Feel free to ask for more details if needed.</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;!-- Let's call this file 'def_domain_test.xml' --&gt;
  &lt;domain type='kvm'&gt;
    &lt;name&gt;vm_c2&lt;/name&gt;
    &lt;memory unit='KiB'&gt;2097152&lt;/memory&gt;
    &lt;currentMemory unit='KiB'&gt;2097152&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;!-- Next line is suspicious! --&gt;
      &lt;!-- &lt;loader readonly='yes' secure='no' type='rom'&gt;/usr/lib/xen-4.4/boot/hvmloader&lt;/loader&gt; --&gt;
      &lt;boot dev='cdrom'/&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;!-- Here is the hard drive that doesn't have OS installed. --&gt;
      &lt;disk type='file' device='disk'&gt;
        &lt;driver name='qemu' type='raw'/&gt;
        &lt;source file='/home/me/me/testing/vm/pool/mvs_vol_c2'/&gt;
        &lt;target dev='hda' bus='ide'/&gt;
        &lt;address type='drive' controller='0' bus='0' target='0' unit='0'/&gt;
      &lt;/disk&gt;
  
      &lt;!-- Here is the Ubuntu ISO. --&gt;
      &lt;disk type='file' device='cdrom'&gt;
        &lt;driver name='qemu' type='raw'/&gt;
        &lt;source file='/home/me/me/testing/vm/ubuntu-14.04.5-server-amd64.iso'/&gt;
        &lt;target dev='hdc' bus='ide'/&gt;
        &lt;readonly/&gt;
        &lt;alias name='ide0-1-0'/&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;source network='default'/&gt;
        &lt;model type='rtl8139'/&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;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='0x04' function='0x0'/&gt;
      &lt;/memballoon&gt;
    &lt;/devices&gt;
  &lt;/domain&gt;
  </code></pre>