QEMU: Difference between revisions
m Link to libvirt |
→Emulate different architecture: Adjusted the build to not rely on reaily set up binfmt/remote builders anymore. Fixed some other problems I had during experiments. Still I was unable to actually see the started VM in virt-man or similar or connect to it, additional info needed! |
||
| Line 53: | Line 53: | ||
outputs = { self, nixpkgs }: | outputs = { self, nixpkgs }: | ||
let | let | ||
# Put your actual system of your machine here. In VM terms it is the "HOST" | |||
buildPlatform = "x86_64-linux"; | |||
# Put the system you want to emulate here. In VM terms it is the "GUEST" | |||
hostPlatform = "aarch64-linux"; | |||
pkgs = import nixpkgs { system = buildPlatform; }; | |||
vmConfig = (pkgs.nixos { | |||
imports = [ "${nixpkgs}/nixos/modules/installer/cd-dvd/installation-cd-base.nix" ]; | imports = [ "${nixpkgs}/nixos/modules/installer/cd-dvd/installation-cd-base.nix" ]; | ||
}).config.system.build.isoImage; | nixpkgs = { inherit buildPlatform hostPlatform; }; | ||
}); | |||
vmIso = vmConfig.config.system.build.isoImage; | |||
vmPkgs = vmConfig.pkgs; | |||
vmScript = pkgs. | vmScript = pkgs.writeShellScriptBin "run-nixos-vm" '' | ||
${pkgs.qemu}/bin/qemu-system-aarch64 \ | ${pkgs.qemu}/bin/qemu-system-aarch64 \ | ||
-machine virt,gic-version=max \ | -machine virt,gic-version=max \ | ||
| Line 67: | Line 74: | ||
-m 2G \ | -m 2G \ | ||
-smp 4 \ | -smp 4 \ | ||
-drive file=$(echo ${ | -drive file=$(echo ${vmIso}/iso/*.iso),format=raw,readonly=on \ | ||
-nographic \ | -nographic \ | ||
-bios ${ | -bios ${vmPkgs.OVMF.fd}/FV/OVMF.fd | ||
''; | ''; | ||
in { | in { | ||
packages.x86_64-linux.default = vmScript; | |||
}; | }; | ||
} | } | ||
</syntaxhighlight>Alternatively a different iso file can be specified in the drive-parameter, for example for Ubuntu Server ARM64. | |||
</syntaxhighlight> | |||
Alternatively a different iso file can be specified in the drive-parameter, for example for Ubuntu Server ARM64. | |||
Make sure to adjust the 2 toplevel variables to set up the cross compilation correctly. If your target is not AARCH64, you have to use the correct qemu binay in the start script. | |||
[[Category:Virtualization]] | [[Category:Virtualization]] | ||