xen.xml 6.7 KB

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