xen.xml 7.0 KB

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