Merge pull request #754 from 0x450x6c/use-qcow-in-interactive-vm

Switch to qcow in the interactive VM to avoid hangs when using large image size.
This commit is contained in:
lassulus 2024-09-03 15:56:58 +02:00 committed by GitHub
commit 85538a44de
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 8 additions and 6 deletions

View file

@ -30,6 +30,7 @@ let
disko.devices = cfg_.disko.devices; disko.devices = cfg_.disko.devices;
}; };
testMode = true; testMode = true;
imageFormat = "qcow2";
}; };
rootDisk = { rootDisk = {
name = "root"; name = "root";
@ -79,8 +80,8 @@ in
trap 'rm -rf "$tmp"' EXIT trap 'rm -rf "$tmp"' EXIT
${lib.concatMapStringsSep "\n" (disk: '' ${lib.concatMapStringsSep "\n" (disk: ''
${pkgs.qemu}/bin/qemu-img create -f qcow2 \ ${pkgs.qemu}/bin/qemu-img create -f qcow2 \
-b ${diskoImages}/${disk.name}.raw \ -b ${diskoImages}/${disk.name}.qcow2 \
-F raw "$tmp"/${disk.name}.qcow2 -F qcow2 "$tmp"/${disk.name}.qcow2
'') disks} '') disks}
set +f set +f
${vm}/bin/run-*-vm ${vm}/bin/run-*-vm

View file

@ -8,6 +8,7 @@
, copyNixStore ? true , copyNixStore ? true
, testMode ? false , testMode ? false
, extraConfig ? { } , extraConfig ? { }
, imageFormat ? "raw"
}: }:
let let
vmTools = pkgs.vmTools.override { vmTools = pkgs.vmTools.override {
@ -39,7 +40,7 @@ let
findutils findutils
] ++ nixosConfig.config.disko.extraDependencies; ] ++ nixosConfig.config.disko.extraDependencies;
preVM = '' preVM = ''
${lib.concatMapStringsSep "\n" (disk: "truncate -s ${disk.imageSize} ${disk.name}.raw") (lib.attrValues nixosConfig.config.disko.devices.disk)} ${lib.concatMapStringsSep "\n" (disk: "${pkgs.qemu}/bin/qemu-img create -f ${imageFormat} ${disk.name}.${imageFormat} ${disk.imageSize}") (lib.attrValues nixosConfig.config.disko.devices.disk)}
# This makes disko work, when canTouchEfiVariables is set to true. # This makes disko work, when canTouchEfiVariables is set to true.
# Technically these boot entries will no be persisted this way, but # Technically these boot entries will no be persisted this way, but
# in most cases this is OK, because we can rely on the standard location for UEFI executables. # in most cases this is OK, because we can rely on the standard location for UEFI executables.
@ -48,7 +49,7 @@ let
postVM = '' postVM = ''
# shellcheck disable=SC2154 # shellcheck disable=SC2154
mkdir -p "$out" mkdir -p "$out"
${lib.concatMapStringsSep "\n" (disk: "mv ${disk.name}.raw \"$out\"/${disk.name}.raw") (lib.attrValues nixosConfig.config.disko.devices.disk)} ${lib.concatMapStringsSep "\n" (disk: "mv ${disk.name}.${imageFormat} \"$out\"/${disk.name}.${imageFormat}") (lib.attrValues nixosConfig.config.disko.devices.disk)}
${extraPostVM} ${extraPostVM}
''; '';
@ -96,7 +97,7 @@ let
"-drive if=pflash,format=raw,unit=1,file=efivars.fd" "-drive if=pflash,format=raw,unit=1,file=efivars.fd"
] ++ builtins.map ] ++ builtins.map
(disk: (disk:
"-drive file=${disk.name}.raw,if=virtio,cache=unsafe,werror=report,format=raw" "-drive file=${disk.name}.${imageFormat},if=virtio,cache=unsafe,werror=report,format=${imageFormat}"
) )
(lib.attrValues nixosConfig.config.disko.devices.disk)); (lib.attrValues nixosConfig.config.disko.devices.disk));
in in

View file

@ -20,7 +20,7 @@
type = lib.types.strMatching "[0-9]+[KMGTP]?"; type = lib.types.strMatching "[0-9]+[KMGTP]?";
description = '' description = ''
size of the image if the makeDiskImages function from diksoLib is used. size of the image if the makeDiskImages function from diksoLib is used.
is used as an argument to truncate -s is used as an argument to "qemu-img create ..."
''; '';
default = "2G"; default = "2G";
}; };