Format the qcow2 image with ext4

The image needs to be available to the guest with a partition table and
a partition with a label named "nixos" so the stage1 can mount it. By
enabling the virtualisation.diskImage option we now have a persistent
root filesystem, including /home.
This commit is contained in:
Rodrigo Arias 2024-01-25 15:34:09 +01:00
parent 6a8eadb037
commit 483ad2944b
3 changed files with 7 additions and 3 deletions

View File

@ -8,7 +8,11 @@ CDIR=$(readlink -f "$PWD")
NIX_DISK_IMAGE=$(readlink -f "${NIX_DISK_IMAGE:-./nixos-riscv.qcow2}")
if ! test -e "$NIX_DISK_IMAGE"; then
qemu-img create -f qcow2 "$NIX_DISK_IMAGE" 1024M
size=1024M
qemu-img create -f raw "$NIX_DISK_IMAGE.raw" "$size"
mkfs.ext4 -L nixos "$NIX_DISK_IMAGE.raw"
qemu-img convert -f raw -O qcow2 "$NIX_DISK_IMAGE.raw" "$NIX_DISK_IMAGE"
rm "$NIX_DISK_IMAGE.raw"
fi
echo "NIX_DISK_IMAGE = $NIX_DISK_IMAGE"

View File

@ -39,7 +39,7 @@
toplevel = nixosconf.config.system.build.toplevel;
in pkgs.mkShell {
pname = "qemu-shell";
buildInputs = with pkgs; [ qemu ];
buildInputs = with pkgs; [ qemu e2fsprogs ];
# Here we tell the run script where to find the system
NIXOS_SYSTEM_TOPLEVEL = toplevel;
OPENSBI = syspkgs.opensbi-uboot;

2
vm.nix
View File

@ -24,7 +24,7 @@
};
};
virtualisation.diskImage = null;
#virtualisation.diskImage = null;
# FIXME: Broken as rustc injects compressed instructions.
# For now we disable it.