[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#898340: virt-qemu: Add a shortcut for booting EFI disk images

Package: autopkgtest
Version: 5.3.1
Severity: wishlist
Tags: patch

Some Debian derivatives strongly prefer EFI bootloaders (SteamOS and
Apertis are examples), some "legacy-free" disk image preparation tools
like mkosi can only use EFI boot, and in distributions that support
both BIOS and EFI it is useful to be able to exercise both code paths.

qemu can be provided with EFI boot capabilities by plugging in OVMF
(x86) or AAVMF (arm/aarch64) firmware, both from src:edk2, as an emulated
parallel flash device. The syntax isn't completely obvious, so I think
it would be useful for autopkgtest-virt-qemu to have a shortcut for
this. The attached patch adds an --efi option which tries to guess from
the qemu_command which EFI firmware we want.

I'll send a merge request when I have a bug number.


-- System Information:
Debian Release: buster/sid
  APT prefers unstable-debug
  APT policy: (500, 'unstable-debug'), (500, 'buildd-unstable'), (500, 'unstable'), (500, 'testing'), (500, 'stable'), (1, 'experimental-debug'), (1, 'buildd-experimental'), (1, 'experimental')
Architecture: amd64 (x86_64)
Foreign Architectures: i386

Kernel: Linux 4.16.0-1-amd64 (SMP w/4 CPU cores)
Locale: LANG=en_GB.utf8, LC_CTYPE=en_GB.utf8 (charmap=UTF-8), LANGUAGE=en_GB:en (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
Init: systemd (via /run/systemd/system)
LSM: AppArmor: enabled

Versions of packages autopkgtest depends on:
ii  apt-utils       1.6.1
ii  libdpkg-perl
ii  procps          2:3.3.14-1+b1
ii  python3         3.6.5-3
ii  python3-debian  0.1.32

Versions of packages autopkgtest recommends:
ii  autodep8  0.12

Versions of packages autopkgtest suggests:
pn  lxc          <none>
pn  lxd-client   <none>
ii  qemu-system  1:2.12+dfsg-1
ii  qemu-utils   1:2.12+dfsg-1
ii  schroot      1.6.10-4

-- no debconf information
>From f42b6dea2a384101e56cc706d2dee041acca5cd7 Mon Sep 17 00:00:00 2001
From: Simon McVittie <smcv@collabora.com>
Date: Wed, 9 May 2018 19:04:28 +0100
Subject: [PATCH] qemu: Add a shortcut for running tests on an EFI-booted image

Some Debian derivatives, notably SteamOS, and some image-preparation
tools, notably mkosi, prefer EFI.

Signed-off-by: Simon McVittie <smcv@collabora.com>
 debian/control               | 10 +++++++++-
 virt/autopkgtest-virt-qemu   | 26 ++++++++++++++++++++++++++
 virt/autopkgtest-virt-qemu.1 |  8 ++++++++
 3 files changed, 43 insertions(+), 1 deletion(-)

diff --git a/debian/control b/debian/control
index eed730e..74fda0e 100644
--- a/debian/control
+++ b/debian/control
@@ -25,7 +25,15 @@ Depends: python3,
 Recommends: autodep8
-Suggests: schroot, lxc, lxd-client, qemu-system, qemu-utils
+ lxc,
+ lxd-client,
+ ovmf,
+ qemu-efi-aarch64,
+ qemu-efi-arm,
+ qemu-system,
+ qemu-utils,
+ schroot,
 Breaks: debci (<< 1.7~)
 Description: automatic as-installed testing for Debian packages
  autopkgtest runs tests on binary packages.  The tests are run on the
diff --git a/virt/autopkgtest-virt-qemu b/virt/autopkgtest-virt-qemu
index ae5bfc2..416c4c8 100755
--- a/virt/autopkgtest-virt-qemu
+++ b/virt/autopkgtest-virt-qemu
@@ -90,6 +90,8 @@ def parse_args():
                         help='Pass through arguments to QEMU command.')
     parser.add_argument('--baseimage', action='store_true', default=False,
                         help='Provide a read-only copy of the base image at /dev/baseimage')
+    parser.add_argument('--efi', action='store_true', default=False,
+                        help='Use OVMF or AAVMF to boot virtual machine using EFI (default: BIOS)')
     parser.add_argument('image', nargs='+',
                         help='disk image to add to the VM (in order)')
@@ -545,6 +547,30 @@ def hook_open():
             'local,id=autopkgtest,path=%s,security_model=none,mount_tag=autopkgtest' % shareddir,
             '-drive', 'file=%s,cache=unsafe,if=virtio,index=0' % overlay]
+    if args.efi:
+        code = None
+        data = None
+        if 'qemu-system-x86_64' in args.qemu_command or \
+                'qemu-system-i386' in args.qemu_command:
+            code = '/usr/share/OVMF/OVMF_CODE.fd'
+            data = '/usr/share/OVMF/OVMF_VARS.fd'
+        elif 'qemu-system-aarch64' in args.qemu_command:
+            code = '/usr/share/AAVMF/AAVMF_CODE.fd'
+            data = '/usr/share/AAVMF/AAVMF_VARS.fd'
+        elif 'qemu-system-arm' in args.qemu_command:
+            code = '/usr/share/AAVMF/AAVMF32_CODE.fd'
+            data = '/usr/share/AAVMF/AAVMF32_VARS.fd'
+        else:
+            VirtSubproc.bomb('Unknown architecture for EFI boot')
+        shutil.copy(data, '%s/efivars.fd' % workdir)
+        argv.append('-drive')
+        argv.append('if=pflash,format=raw,read-only,file=' + code)
+        argv.append('-drive')
+        argv.append('if=pflash,format=raw,file=%s/efivars.fd' % workdir)
     for i, image in enumerate(args.image[1:]):
         argv.append('file=%s,if=virtio,index=%i,readonly' % (image, i + 1))
diff --git a/virt/autopkgtest-virt-qemu.1 b/virt/autopkgtest-virt-qemu.1
index cdfe190..2137725 100644
--- a/virt/autopkgtest-virt-qemu.1
+++ b/virt/autopkgtest-virt-qemu.1
@@ -109,6 +109,14 @@ will not be accessible between calling
 .B autopkgtest-reboot-prepare
 and the next boot, thus make sure to stop accessing it before.
+.B  \-\-efi
+Configure QEMU with OVMF or AAVMF firmware images suitable for booting
+an x86, ARM or ARM64 virtual machine using EFI. This requires the
+ovmf, qemu-efi-arm or qemu-efi-aarch64 package. The correct firmware
+image is guessed from the
+.BR --qemu-command .
 .BI "--qemu-options=" arguments
 Pass through arguments to QEMU command; e. g. --qemu-options='-readconfig qemu.cfg'

Reply to: