xen.xml 7.3 KB

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