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