qemu-vm: split EFI NVRAM into CODE and VARS
This commit is contained in:
parent
90bf7332e1
commit
d7e3312ab1
@ -99,6 +99,10 @@ let
|
|||||||
addDeviceNames =
|
addDeviceNames =
|
||||||
imap1 (idx: drive: drive // { device = driveDeviceName idx; });
|
imap1 (idx: drive: drive // { device = driveDeviceName idx; });
|
||||||
|
|
||||||
|
efiPrefix = "${pkgs.OVMF.fd}/FV/OVMF";
|
||||||
|
efiFirmware = "${efiPrefix}_CODE.fd";
|
||||||
|
efiVars = "${efiPrefix}_VARS.fd";
|
||||||
|
|
||||||
# Shell script to start the VM.
|
# Shell script to start the VM.
|
||||||
startVM =
|
startVM =
|
||||||
''
|
''
|
||||||
@ -125,9 +129,9 @@ let
|
|||||||
${qemu}/bin/qemu-img create -f qcow2 -b ${bootDisk}/disk.img $TMPDIR/disk.img || exit 1
|
${qemu}/bin/qemu-img create -f qcow2 -b ${bootDisk}/disk.img $TMPDIR/disk.img || exit 1
|
||||||
|
|
||||||
${if cfg.useEFIBoot then ''
|
${if cfg.useEFIBoot then ''
|
||||||
# VM needs a writable flash BIOS.
|
# VM needs writable EFI vars
|
||||||
cp ${bootDisk}/bios.bin $TMPDIR || exit 1
|
cp ${bootDisk}/EFI_VARS.fd $TMPDIR || exit 1
|
||||||
chmod 0644 $TMPDIR/bios.bin || exit 1
|
chmod 0644 $TMPDIR/EFI_VARS.fd || exit 1
|
||||||
'' else ''
|
'' else ''
|
||||||
''}
|
''}
|
||||||
'' else ''
|
'' else ''
|
||||||
@ -172,18 +176,19 @@ let
|
|||||||
''
|
''
|
||||||
mkdir $out
|
mkdir $out
|
||||||
diskImage=$out/disk.img
|
diskImage=$out/disk.img
|
||||||
bootFlash=$out/bios.bin
|
|
||||||
${qemu}/bin/qemu-img create -f qcow2 $diskImage "40M"
|
${qemu}/bin/qemu-img create -f qcow2 $diskImage "40M"
|
||||||
${if cfg.useEFIBoot then ''
|
${if cfg.useEFIBoot then ''
|
||||||
cp ${pkgs.OVMF-CSM.fd}/FV/OVMF.fd $bootFlash
|
efiVars=$out/EFI_VARS.fd
|
||||||
chmod 0644 $bootFlash
|
cp ${efiVars} $efiVars
|
||||||
|
chmod 0644 $efiVars
|
||||||
'' else ''
|
'' else ''
|
||||||
''}
|
''}
|
||||||
'';
|
'';
|
||||||
buildInputs = [ pkgs.utillinux ];
|
buildInputs = [ pkgs.utillinux ];
|
||||||
QEMU_OPTS = if cfg.useEFIBoot
|
QEMU_OPTS = "-nographic -serial stdio -monitor none"
|
||||||
then "-pflash $out/bios.bin -nographic -serial pty"
|
+ lib.optionalString cfg.useEFIBoot (
|
||||||
else "-nographic -serial pty";
|
" -drive if=pflash,format=raw,unit=0,readonly=on,file=${efiFirmware}"
|
||||||
|
+ " -drive if=pflash,format=raw,unit=1,file=$efiVars");
|
||||||
}
|
}
|
||||||
''
|
''
|
||||||
# Create a /boot EFI partition with 40M and arbitrary but fixed GUIDs for reproducibility
|
# Create a /boot EFI partition with 40M and arbitrary but fixed GUIDs for reproducibility
|
||||||
@ -560,7 +565,8 @@ in
|
|||||||
''-append "$(cat ${config.system.build.toplevel}/kernel-params) init=${config.system.build.toplevel}/init regInfo=${regInfo}/registration ${consoles} $QEMU_KERNEL_PARAMS"''
|
''-append "$(cat ${config.system.build.toplevel}/kernel-params) init=${config.system.build.toplevel}/init regInfo=${regInfo}/registration ${consoles} $QEMU_KERNEL_PARAMS"''
|
||||||
])
|
])
|
||||||
(mkIf cfg.useEFIBoot [
|
(mkIf cfg.useEFIBoot [
|
||||||
"-pflash $TMPDIR/bios.bin"
|
"-drive if=pflash,format=raw,unit=0,readonly,file=${efiFirmware}"
|
||||||
|
"-drive if=pflash,format=raw,unit=1,file=$TMPDIR/EFI_VARS.fd"
|
||||||
])
|
])
|
||||||
(mkIf (cfg.bios != null) [
|
(mkIf (cfg.bios != null) [
|
||||||
"-bios ${cfg.bios}/bios.bin"
|
"-bios ${cfg.bios}/bios.bin"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user