Skip to content

Commit 9067560

Browse files
jovialmarkgoddard
andcommitted
Add efi support
Add support for booting VMs in EFI mode. Currently secure boot is not supported. If using with the stackhpc.libvirt-host role, set libvirt_host_enable_efi_support to true to install required packages. Co-Authored-By: Mark Goddard <[email protected]>
1 parent 19fa75b commit 9067560

File tree

7 files changed

+34
-1
lines changed

7 files changed

+34
-1
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,8 @@ Role Variables
166166
- `autostart`: Whether to start the VM when the host starts up. Default is
167167
`true`.
168168

169+
- `boot_firmware`: Can be one of: `bios`, or `efi`. Defaults to `bios`.
170+
169171
- `xml_file`: Optionally supply a modified XML template. Base customisation
170172
off the default `vm.xml.j2` template so as to include the expected jinja
171173
expressions the role uses.
@@ -226,7 +228,7 @@ Example Playbook
226228
- type: 'block'
227229
format: 'raw'
228230
dev: '/dev/sda'
229-
231+
230232
interfaces:
231233
- network: 'br-datacentre'
232234

defaults/main.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ libvirt_vms:
8686
# XML template file to source domain definition
8787
xml_file: vm.xml.j2
8888

89+
# May be one of: bios, or efi.
90+
boot_firmware: bios
91+
8992
# Variables to add to the enviroment that is used to execute virsh commands
9093
libvirt_vm_virsh_default_env: "{{ { 'LIBVIRT_DEFAULT_URI': libvirt_vm_uri } if libvirt_vm_uri else {} }}"
9194

tasks/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
autostart: "{{ vm.autostart | default(true) }}"
4646
enable_vnc: "{{ vm.enable_vnc | default(false) }}"
4747
enable_spice: "{{ vm.enable_spice | default(false) }}"
48+
boot_firmware: "{{ vm.boot_firmware | default('bios', true) | lower }}"
4849
with_items: "{{ libvirt_vms }}"
4950
loop_control:
5051
loop_var: vm

templates/vm.xml.j2

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@
2222
<boot dev='cdrom'/>
2323
<boot dev='network'/>
2424
<bios useserial='yes'/>
25+
{% if boot_firmware == "efi" %}
26+
{# NOTE: pflash requires qemu 1.6 or newer. There are alternatives for older versions, but
27+
they do not work with secure boot. See OVMF readme for an overview #}
28+
<loader readonly='yes' type='pflash'>{{ libvirt_vm_ovmf_efi_firmware_path }}</loader>
29+
<nvram template='{{ libvirt_vm_ovmf_efi_variable_store_path }}'/>
30+
{% endif %}
2531
</os>
2632
<features>
2733
<acpi/>

vars/Archlinux.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,10 @@ libvirt_vm_script_env: >-
1010
1111
# Archlinux qemu comes with kvm support compiled in
1212
libvirt_vm_emulator: /usr/bin/qemu-system-x86_64
13+
14+
# Path to template OVMF efi variable store. A copy will be created
15+
# for each VM created.
16+
libvirt_vm_ovmf_efi_variable_store_path: /usr/share/OVMF/OVMF_VARS.fd
17+
18+
# Path to OVMF efi firmware
19+
libvirt_vm_ovmf_efi_firmware_path: /usr/share/OVMF/OVMF_CODE.fd

vars/Debian.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,10 @@ libvirt_vm_script_env_debian:
1010

1111
libvirt_vm_script_env: >-
1212
{{ libvirt_vm_script_env_debian | combine(libvirt_vm_virsh_default_env) }}
13+
14+
# Path to template OVMF efi variable store. A copy will be created
15+
# for each VM created.
16+
libvirt_vm_ovmf_efi_variable_store_path: /usr/share/OVMF/OVMF_VARS.fd
17+
18+
# Path to OVMF efi firmware
19+
libvirt_vm_ovmf_efi_firmware_path: /usr/share/OVMF/OVMF_CODE.fd

vars/RedHat.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,10 @@ libvirt_vm_script_env_redhat:
1010

1111
libvirt_vm_script_env: >-
1212
{{ libvirt_vm_script_env_redhat | combine(libvirt_vm_virsh_default_env) }}
13+
14+
# Path to template OVMF efi variable store. A copy will be created
15+
# for each VM created.
16+
libvirt_vm_ovmf_efi_variable_store_path: /usr/share/edk2/OVMF/OVMF_VARS.fd
17+
18+
# Path to OVMF efi firmware
19+
libvirt_vm_ovmf_efi_firmware_path: /usr/share/edk2/OVMF/OVMF_CODE.fd

0 commit comments

Comments
 (0)