xen.xml 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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="xenpvh">xenpvh</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. {% if vm.features.check_with_template('no-default-kernelopts', False) -%}
  48. <cmdline>{{ vm.kernelopts }}</cmdline>
  49. {% else -%}
  50. <cmdline>{{ vm.kernelopts_common }}{{ vm.kernelopts }}</cmdline>
  51. {% endif -%}
  52. {% endif %}
  53. {% endblock %}
  54. </os>
  55. <features>
  56. {% block features %}
  57. {% if vm.virt_mode != 'pv' %}
  58. <pae/>
  59. <acpi/>
  60. <apic/>
  61. <viridian/>
  62. {% endif %}
  63. {% if vm.devices['pci'].persistent() | list
  64. and vm.features.get('pci-e820-host', True) %}
  65. <xen>
  66. <e820_host state="on"/>
  67. </xen>
  68. {% endif %}
  69. {% endblock %}
  70. </features>
  71. {% block clock %}
  72. {% if vm.virt_mode == 'hvm' %}
  73. {% set timezone = vm.features.check_with_template('timezone', 'localtime').lower() %}
  74. {% if timezone == 'localtime' %}
  75. <clock offset="variable" adjustment="0" basis="localtime" />
  76. {% elif timezone.isdigit() %}
  77. <clock offset="variable" adjustment="{{ timezone }}" basis="utc" />
  78. {% else %}
  79. <clock offset="variable" adjustment="0" basis="utc" />
  80. {% endif %}
  81. {% else %}
  82. <clock offset='utc' adjustment='reset'>
  83. <timer name="tsc" mode="native"/>
  84. </clock>
  85. {% endif %}
  86. {% endblock %}
  87. {% block on %}
  88. <on_poweroff>destroy</on_poweroff>
  89. <on_reboot>destroy</on_reboot>
  90. <on_crash>destroy</on_crash>
  91. {% endblock %}
  92. <devices>
  93. {% block devices %}
  94. {% set i = 0 %}
  95. {# TODO Allow more volumes out of the box #}
  96. {% set dd = ['e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p',
  97. 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y']
  98. %}
  99. {% for device in vm.block_devices %}
  100. <disk type="block" device="{{ device.devtype }}">
  101. <driver name="phy" />
  102. <source dev="{{ device.path }}" />
  103. {% if device.name == 'root' %}
  104. <target dev="xvda" />
  105. {% elif device.name == 'private' %}
  106. <target dev="xvdb" />
  107. {% elif device.name == 'volatile' %}
  108. <target dev="xvdc" />
  109. {% elif device.name == 'kernel' %}
  110. <target dev="xvdd" />
  111. {% else %}
  112. <target dev="xvd{{dd[i]}}" />
  113. {% set i = i + 1 %}
  114. {% endif %}
  115. {% if not device.rw %}
  116. <readonly />
  117. {% endif %}
  118. {% if device.domain %}
  119. <backenddomain name="{{ device.domain }}" />
  120. {% endif %}
  121. {% if device.script %}
  122. <script path="{{ device.script }}" />
  123. {% endif %}
  124. </disk>
  125. {% endfor %}
  126. {# start external devices from xvdi #}
  127. {% set i = 4 %}
  128. {% for assignment in vm.devices.block.assignments(True) %}
  129. {% set device = assignment.device %}
  130. {% set options = assignment.options %}
  131. {% include 'libvirt/devices/block.xml' %}
  132. {% endfor %}
  133. {% if vm.netvm %}
  134. {% include 'libvirt/devices/net.xml' with context %}
  135. {% endif %}
  136. {% for assignment in vm.devices.pci.assignments(True) %}
  137. {% set device = assignment.device %}
  138. {% set options = assignment.options %}
  139. {% include 'libvirt/devices/pci.xml' %}
  140. {% endfor %}
  141. {% if vm.virt_mode == 'hvm' %}
  142. <!-- server_ip is the address of stubdomain. It hosts it's own DNS server. -->
  143. <emulator
  144. {% if vm.features.check_with_template('linux-stubdom', True) %}
  145. type="stubdom-linux"
  146. {% else %}
  147. type="stubdom"
  148. {% endif %}
  149. {% if vm.netvm and not
  150. vm.features.check_with_template('linux-stubdom', True) %}
  151. cmdline="-net lwip,client_ip={{ vm.ip -}}
  152. ,server_ip={{ vm.dns[1] -}}
  153. ,dns={{ vm.dns[0] -}}
  154. ,gw={{ vm.netvm.gateway -}}
  155. ,netmask={{ vm.netmask }}"
  156. {% endif %}
  157. {% if vm.stubdom_mem %}
  158. memory="{{ vm.stubdom_mem * 1024 -}}"
  159. {% endif %}
  160. />
  161. <input type="tablet" bus="usb"/>
  162. <video>
  163. <model type="{{ vm.features.check_with_template('video-model', 'vga') }}"/>
  164. </video>
  165. {% if vm.features.check_with_template('linux-stubdom', True) %}
  166. {# TODO only add qubes gui if gui-agent is not installed in HVM #}
  167. <graphics type="qubes"/>
  168. {% endif %}
  169. {% endif %}
  170. <console type="pty">
  171. <target type="xen" port="0"/>
  172. </console>
  173. {% endblock %}
  174. </devices>
  175. </domain>
  176. <!-- vim: set ft=jinja ts=4 sts=4 sw=4 et tw=80 : -->