QEMU: Difference between revisions

Onny (talk | contribs)
Emulate different architectures
Onny (talk | contribs)
 
(3 intermediate revisions by 2 users not shown)
Line 2: Line 2:


== Setup ==
== Setup ==
 
To install the main QEMU program system-wide, add the following to your <code>configuration.nix</code>:<syntaxhighlight lang=nix>
<syntaxhighlight lang=nix>
   environment = {
   environment = {
     systemPackages = [ pkgs.qemu ];
     systemPackages = [ pkgs.qemu ];
   };
   };
</syntaxhighlight>
</syntaxhighlight>
{{Evaluate}}


=== Quick EMU ===
=== Quick EMU ===
Line 22: Line 23:
== Configuration ==
== Configuration ==


=== Booting UEFI ===
=== UEFI firmware support ===
To boot UEFI systems using QEMU, the UEFI firmware replacing the BIOS implementation needs to be provided while starting QEMU.
To enable UEFI firmware support in Virt-Manager, Libvirt, Gnome-Boxes etc. add following snippet to your system configuration and apply it<syntaxhighlight lang="nix">
 
systemd.tmpfiles.rules = [ "L+ /var/lib/qemu/firmware - - - - ${pkgs.qemu}/share/qemu/firmware" ];
The following installs a script, that always starts QEMU with OVMF firmware implementing UEFI support.
</syntaxhighlight>


<syntaxhighlight lang=nix>
=== Run binaries of different architecture ===
environment = {
Following configuration will enable the emulation of different architectures. For example to run aarch64 and riscv64 binaries on an native x86_64 host, add following part to your system configuration, apply it and reboot your system.<syntaxhighlight lang="nix">
  systemPackages = [
boot.binfmt.emulatedSystems = [
    (pkgs.writeShellScriptBin "qemu-system-x86_64-uefi" ''
  "aarch64-linux"
      qemu-system-x86_64 \
  "riscv64-linux"
        -bios ${pkgs.OVMF.fd}/FV/OVMF.fd \
];
        "$@"
    '')
  ];
};
</syntaxhighlight>
</syntaxhighlight>
qcow-efi images generated from [https://github.com/nix-community/nixos-generators nixos-generators] require more RAM than the default 128MB.  Failing to provide enough RAM results in grub reporting "error: start_image() returned 0x800000000000009." or systemd-boot reporting "Failed to execute NixOS: Out of resources".


== Tips and tricks ==
== Tips and tricks ==
Line 80: Line 75:
}
}


</syntaxhighlight>
</syntaxhighlight>Alternatively a different iso file can be specified in the drive-parameter, for example for Ubuntu Server ARM64.
[[Category:Virtualization]]
[[Category:Virtualization]]