xen.xml 6.8 KB

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