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