xen.xml 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. <domain type="xen">
  2. {% block basic %}
  3. <name>{{ vm.name }}</name>
  4. <uuid>{{ vm.uuid }}</uuid>
  5. {% if ((vm.virt_mode == 'hvm' and vm.devices['pci'].persistent() | list)
  6. or vm.maxmem == 0) -%}
  7. <memory unit="MiB">{{ vm.memory }}</memory>
  8. {% else -%}
  9. <memory unit="MiB">{{ vm.maxmem }}</memory>
  10. {% endif -%}
  11. <currentMemory unit="MiB">{{ vm.memory }}</currentMemory>
  12. <vcpu placement="static">{{ vm.vcpus }}</vcpu>
  13. {% endblock %}
  14. {% block cpu %}
  15. {% if vm.virt_mode != 'pv' %}
  16. <cpu mode='host-passthrough'>
  17. <!-- disable nested HVM -->
  18. <feature name='vmx' policy='disable'/>
  19. <feature name='svm' policy='disable'/>
  20. <!-- disable SMAP inside VM, because of Linux bug -->
  21. <feature name='smap' policy='disable'/>
  22. </cpu>
  23. {% endif %}
  24. {% endblock %}
  25. <os>
  26. {% block os %}
  27. {% if vm.virt_mode == 'hvm' %}
  28. <type arch="x86_64" machine="xenfv">hvm</type>
  29. <!--
  30. For the libxl backend libvirt switches between OVMF (UEFI)
  31. and SeaBIOS based on the loader type. This has nothing to
  32. do with the hvmloader binary.
  33. -->
  34. <loader type="{{ "pflash" if vm.features.check_with_template('uefi', False) else "rom" }}">hvmloader</loader>
  35. <boot dev="cdrom" />
  36. <boot dev="hd" />
  37. {% else %}
  38. {% if vm.virt_mode == 'pvh' %}
  39. <type arch="x86_64" machine="xenfv">pvh</type>
  40. {% else %}
  41. <type arch="x86_64" machine="xenpv">linux</type>
  42. {% endif %}
  43. <kernel>{{ vm.storage.kernels_dir }}/vmlinuz</kernel>
  44. <initrd>{{ vm.storage.kernels_dir }}/initramfs</initrd>
  45. {% endif %}
  46. {% if vm.kernel %}
  47. <cmdline>root=/dev/mapper/dmroot ro nomodeset console=hvc0 rd_NO_PLYMOUTH rd.plymouth.enable=0 plymouth.enable=0 {{ vm.kernelopts }}</cmdline>
  48. {% endif %}
  49. {% endblock %}
  50. </os>
  51. <features>
  52. {% block features %}
  53. {% if vm.virt_mode != 'pv' %}
  54. <pae/>
  55. <acpi/>
  56. <apic/>
  57. <viridian/>
  58. {% endif %}
  59. {% if vm.devices['pci'].persistent() | list
  60. and vm.features.get('pci-e820-host', True) %}
  61. <xen>
  62. <e820_host state="on"/>
  63. </xen>
  64. {% endif %}
  65. {% endblock %}
  66. </features>
  67. {% block clock %}
  68. {% if vm.virt_mode == 'hvm' %}
  69. {% set timezone = vm.features.check_with_template('timezone', 'localtime').lower() %}
  70. {% if timezone == 'localtime' %}
  71. <clock offset="variable" adjustment="0" basis="localtime" />
  72. {% elif timezone.isdigit() %}
  73. <clock offset="variable" adjustment="{{ timezone }}" basis="UTC" />
  74. {% else %}
  75. <clock offset="variable" adjustment="0" basis="UTC" />
  76. {% endif %}
  77. {% else %}
  78. <clock offset='utc' adjustment='reset'>
  79. <timer name="tsc" mode="native"/>
  80. </clock>
  81. {% endif %}
  82. {% endblock %}
  83. {% block on %}
  84. <on_poweroff>destroy</on_poweroff>
  85. <on_reboot>destroy</on_reboot>
  86. <on_crash>destroy</on_crash>
  87. {% endblock %}
  88. <devices>
  89. {% block devices %}
  90. {% set i = 0 %}
  91. {# TODO Allow more volumes out of the box #}
  92. {% set dd = ['e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p',
  93. 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y']
  94. %}
  95. {% for device in vm.block_devices %}
  96. <disk type="block" device="{{ device.devtype }}">
  97. <driver name="phy" />
  98. <source dev="{{ device.path }}" />
  99. {% if device.name == 'root' %}
  100. <target dev="xvda" />
  101. {% elif device.name == 'private' %}
  102. <target dev="xvdb" />
  103. {% elif device.name == 'volatile' %}
  104. <target dev="xvdc" />
  105. {% elif device.name == 'kernel' %}
  106. <target dev="xvdd" />
  107. {% else %}
  108. <target dev="xvd{{dd[i]}}" />
  109. {% set i = i + 1 %}
  110. {% endif %}
  111. {% if not device.rw %}
  112. <readonly />
  113. {% endif %}
  114. {% if device.domain %}
  115. <backenddomain name="{{ device.domain }}" />
  116. {% endif %}
  117. {% if device.script %}
  118. <script path="{{ device.script }}" />
  119. {% endif %}
  120. </disk>
  121. {% endfor %}
  122. {# start external devices from xvdi #}
  123. {% set i = 4 %}
  124. {% for assignment in vm.devices.block.assignments(True) %}
  125. {% set device = assignment.device %}
  126. {% set options = assignment.options %}
  127. {% include 'libvirt/devices/block.xml' %}
  128. {% endfor %}
  129. {% if vm.netvm %}
  130. {% include 'libvirt/devices/net.xml' with context %}
  131. {% endif %}
  132. {% for assignment in vm.devices.pci.assignments(True) %}
  133. {% set device = assignment.device %}
  134. {% set options = assignment.options %}
  135. {% include 'libvirt/devices/pci.xml' %}
  136. {% endfor %}
  137. {% if vm.virt_mode == 'hvm' %}
  138. <!-- server_ip is the address of stubdomain. It hosts it's own DNS server. -->
  139. <emulator
  140. {% if vm.features.check_with_template('linux-stubdom', True) %}
  141. type="stubdom-linux"
  142. {% else %}
  143. type="stubdom"
  144. {% endif %}
  145. {% if vm.netvm and not
  146. vm.features.check_with_template('linux-stubdom', True) %}
  147. cmdline="-net lwip,client_ip={{ vm.ip -}}
  148. ,server_ip={{ vm.dns[1] -}}
  149. ,dns={{ vm.netvm.gateway -}}
  150. ,gw={{ vm.netvm.gateway -}}
  151. ,netmask={{ vm.netmask }}"
  152. {% endif %}
  153. {% if vm.stubdom_mem %}
  154. memory="{{ vm.stubdom_mem * 1024 -}}"
  155. {% endif %}
  156. />
  157. <input type="tablet" bus="usb"/>
  158. <video>
  159. <model type="{{ vm.features.check_with_template('video-model', 'vga') }}"/>
  160. </video>
  161. {% if vm.features.check_with_template('linux-stubdom', True) %}
  162. {# TODO only add qubes gui if gui-agent is not installed in HVM #}
  163. <graphics type="qubes"/>
  164. {% endif %}
  165. {% else %}
  166. <console type="pty">
  167. <target type="xen" port="0"/>
  168. </console>
  169. {% endif %}
  170. {% endblock %}
  171. </devices>
  172. </domain>
  173. <!-- vim: set ft=jinja ts=4 sts=4 sw=4 et tw=80 : -->