diff --git a/content/qemu/index.md b/content/qemu/index.md index dfdb703..fcd324c 100644 --- a/content/qemu/index.md +++ b/content/qemu/index.md @@ -3,52 +3,117 @@ title = 'QEMU' icon = 'clanbomber' +++ -QEMU is an emulator for -various CPUs. It works on Linux, Windows, FreeBSD and Mac OS X. It's possible -to run grml with QEMU. Notice that it's much slower than running it native -due to the emulation mode. +[QEMU](https://www.qemu.org/) is an emulator for various CPUs. +It works on Linux, Windows, FreeBSD and Mac OS X. +It's possible to run Grml with QEMU. +Note that it is slower than running it native due to the emulation mode. ## Using QEMU with acceleration -grml >=0.5 provides the accelerator module for QEMU namend 'kqemu'. Just run the following commands to use it: +On modern Linux distributions, including Grml, the kernel comes with an acceleration module, called `KVM`. +To use this, load the `kvm.ko` kernel module, and give yourself rights:
-apt-get update ; apt-get install qemu # install qemu
-modprobe kqemu                        # load the kernel module
-mknod /dev/kqemu c 250 0              # create the device
-chmod 666 /dev/kqemu /dev/net/tun     # adjust permissions
+apt update && apt install qemu-system        # install qemu
+modprobe kvm                                 # load the kernel module
 
-To see if kqemu is enabled and working correctly, use the QEMU monitor command (press ctrl-alt-2): 'info kqemu' +If you are not logged in locally (just SSH does not count), your user also must be in the `kvm` group: +
+adduser $USER kvm                            # add your user to kvm group
+# now login again or try: newgrp kvm
+
+ + +To see if kvm is enabled and working correctly, use the QEMU monitor command (press ctrl-alt-2): 'info kvm' + +## Usage examples + +In all examples below you can add `-nographic -vga none` to get the first serial console on your terminal. +This might work better on arm64, where the Linux kernel by default expects a serial console, and less good on amd64. + +The example use `-m 2048` for 2GB (2048MB) of virtual memory (RAM). +They do not pass any CPU core counts, so you get one virtualized CPU core. +Use `-smp 2` to enable 2 CPU cores, for example. + +### Boot Grml ISO on arm64 (aarch64) + +This assumes the firmware shall be UEFI EDK2 ("TianoCore"). +This is the best supported QEMU target on arm64. + +This also assumes that your host is actually arm64 and has KVM support. + +
+apt update && apt install qemu-system qemu-system-gui qemu-efi-aarch64
+cp /usr/share/AAVMF/AAVMF_VARS.fd efi_vars.fd
+qemu-system-aarch64 \
+    -machine type=virt,gic-version=max,accel=kvm:tcg \
+    -cpu max \
+    -m 2048 \
+    -drive if=pflash,format=raw,unit=0,file.filename=/usr/share/AAVMF/AAVMF_CODE.no-secboot.fd,file.locking=off,readonly=on \
+    -drive if=pflash,unit=1,file=efi_vars.fd \
+    -monitor unix:qemu-monitor-socket,server,nowait \
+    -cdrom ~/grml-full-{{< param current_release.version >}}-arm64.iso
+
+ +To access the QEMU monitor, you can use socat on a separate terminal: + +
+apt update && apt install socat
+socat -,echo=0,icanon=0 unix-connect:qemu-monitor-socket
+
-## Problems with Qemu +From there you can run commands like `info kvm` or `quit`. -### Black / blank screen +### Boot Grml ISO on amd64 (64-bit PC), UEFI -You get a black/blank screen when booting grml in qemu? Try booting with "grml vga=normal". +This assumes the firmware shall be UEFI EDK2 ("TianoCore"). +This also assumes that your host is amd64 and has KVM support. + +We picked machine `q35` (over `i440fx`) as it is a more modern (mostly legacy-free) x86 machine. + +QEMU monitor will be available on stdout. + +
+apt update && apt install qemu-system qemu-system-gui ovmf
+cp /usr/share/OVMF/OVMF_VARS_4M.fd efi_vars.fd
+qemu-system-x86_64 \
+    -machine type=q35,accel=kvm:tcg \
+    -cpu max \
+    -m 2048 \
+    -drive if=pflash,format=raw,unit=0,file.filename=/usr/share/OVMF/OVMF_CODE_4M.fd,file.locking=off,readonly=on \
+    -drive if=pflash,unit=1,file="efi_vars.fd \
+    -monitor stdio \
+    -cdrom ~/grml-full-{{< param current_release.version >}}-amd64.iso
+
-## Running QEMU with grml on Linux +### Boot Grml ISO on amd64 (64-bit PC), Legacy BIOS -Install qemu (apt-get install qemu) and start it e.g. via: +This will boot using legacy BIOS firmware, usually SeaBIOS.
-qemu -m 256 -cdrom /dev/hdc          # if running from CD-ROM
-qemu -m 256 -cdrom /path/to/grml.iso # if running from harddisk
+apt update && apt install qemu-system qemu-system-gui seabios
+qemu-system-x86_64 \
+    -machine type=q35,accel=kvm:tcg \
+    -cpu max \
+    -m 2048 \
+    -monitor stdio \
+    -cdrom ~/grml-full-{{< param current_release.version >}}-amd64.iso
 
-## Running QEMU with grml on Windows +## Running Grml under QEMU on Windows screenshot 1 First of all download QEMU for Windows. -Download the grml-iso and put the QEMU files in the same directory as the grml-iso. +Download a Grml ISO and put the QEMU files in the same directory as the Grml ISO. Now create a startup file, call it for example grml-qemu.bat:
 REM Start qemu on windows.
 @ECHO OFF
-START qemu.exe -L . -m 256 -hdc harddisk -cdrom grml_0.6.iso
+START qemu.exe -L . -m 2048 -hdc harddisk -cdrom grml-full-{{< param current_release.version >}}-amd64.iso
 CLS
 EXIT