1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
|
Author: Mathias Gibbens <gibmat@debian.org>
Description: Fix issues with old NVRAM (ported from Incus)
From: https://github.com/lxc/incus/commit/7f63ae9a9fd3b083a8148a69094abdd1c07111e9
diff --git a/lxd/instance/drivers/driver_qemu.go b/lxd/instance/drivers/driver_qemu.go
index 8f19feb95..d73ba9594 100644
--- a/lxd/instance/drivers/driver_qemu.go
+++ b/lxd/instance/drivers/driver_qemu.go
@@ -1210,13 +1210,21 @@ func (d *qemu) start(stateful bool, op *operationlock.InstanceOperation) error {
}
// Copy OVMF settings firmware to nvram file if needed.
- // This firmware file can be modified by the VM so it must be copied from the defaults.
- if d.architectureSupportsUEFI(d.architecture) && (!shared.PathExists(d.nvramPath()) || shared.IsTrue(d.localConfig["volatile.apply_nvram"])) {
- err = d.setupNvram()
- if err != nil {
- op.Done(err)
+ // Set up EDK2 NVRAM when on EFI.
+ if d.architectureSupportsUEFI(d.architecture) {
+ fi, err := os.Lstat(d.nvramPath())
+ if err != nil && !errors.Is(err, fs.ErrNotExist) {
return err
}
+
+ // Generate new NVRAM if missing, or if requested by the user or if the NVRAM file is of an invalid format (needs to be a valid symlink).
+ if shared.IsTrue(d.localConfig["volatile.apply_nvram"]) || fi == nil || fi.Mode()&os.ModeSymlink != os.ModeSymlink {
+ err = d.setupNvram()
+ if err != nil {
+ op.Done(err)
+ return err
+ }
+ }
}
// Clear volatile.apply_nvram if set.
|