### QEMU Test Setup: Starting QMP Server Source: https://www.qemu.org/docs/master/devel/writing-monitor-commands.html Start QEMU with a QMP server listening on a socket for testing monitor commands. This setup allows interaction via telnet. ```bash # qemu-system-TARGET [...] \ -chardev socket,id=qmp,port=4444,host=localhost,server=on \ -mon chardev=qmp,mode=control,pretty=on ``` -------------------------------- ### Setup and Run Guest OS Installation with blkverify Source: https://www.qemu.org/docs/master/devel/testing/blkverify.html Demonstrates setting up raw and qcow2 disk images and launching a QEMU system emulator with the blkverify protocol to test OS installation. ```bash $ ./qemu-img create raw.img 16G $ ./qemu-img create -f qcow2 test.qcow2 16G $ ./qemu-system-x86_64 -cdrom debian.iso \ -drive file=blkverify:raw.img:test.qcow2 ``` -------------------------------- ### Start QEMU with S390x CPU Topology Options Source: https://www.qemu.org/docs/master/devel/s390-cpu-topology.html Example command to start QEMU with specific S390x CPU configurations, including topology-related options like drawers, books, sockets, and cores. This sets up the environment for querying and manipulating CPU topology. ```bash qemu-system-s390x \ -enable-kvm \ -cpu z14,ctop=on \ -smp 1,drawers=3,books=3,sockets=2,cores=2,maxcpus=36 \ -device z14-s390x-cpu,core-id=19,entitlement=high \ -device z14-s390x-cpu,core-id=11,entitlement=low \ -device z14-s390x-cpu,core-id=12,entitlement=high \ ... ``` -------------------------------- ### Build and Run System Example with Uftrace Source: https://www.qemu.org/docs/master/about/emulation.html This example shows the steps to build and run a full system image with frame pointers enabled, including installing dependencies, cloning a repository, building the system, and then running it with the uftrace plugin. It also includes commands for generating and viewing the trace. ```bash # Install dependencies $ sudo apt install -y podman qemu-user-static $ git clone https://github.com/p-b-o/qemu-linux-stack $ cd qemu-linux-stack $ ./build.sh # system can be started using: $ ./run.sh /path/to/qemu-system-aarch64 # generate a uftrace for execution (collect symbols automatically) $ ./trace.sh /path/to/qemu-system-aarch64 # show output log to read timestamps $ cat uftrace.data/exec.log # generate final trace (compressed) for perfetto $ ./perfetto.sh ~/trace.gz ``` -------------------------------- ### GDB Stdio Connection Example Source: https://www.qemu.org/docs/master/system/invocation.html Example of establishing a GDB connection via stdio, allowing QEMU to be started from within GDB. ```bash (gdb) target remote | exec qemu-system-x86_64 -gdb stdio ... ``` -------------------------------- ### Full PowerNV Machine Configuration Example Source: https://www.qemu.org/docs/master/system/ppc/powernv.html A comprehensive example demonstrating the setup of multiple storage controllers, a PCIe bridge, SATA controller, disk, network device, and USB controller on a PowerNV machine. ```bash $ qemu-system-ppc64 -m 2G -machine powernv9 -smp 2,cores=2,threads=1 -accel tcg,thread=single \ -kernel ./zImage.epapr -initrd ./rootfs.cpio.xz -bios ./skiboot.lid \ -device megasas,id=scsi0,bus=pcie.0,addr=0x0 \ -drive file=./rhel7-ppc64le.qcow2,if=none,id=drive-scsi0-0-0-0,format=qcow2,cache=none \ -device scsi-hd,bus=scsi0.0,channel=0,scsi-id=0,lun=0,drive=drive-scsi0-0-0-0,id=scsi0-0-0-0,bootindex=2 \ -device pcie-pci-bridge,id=bridge1,bus=pcie.1,addr=0x0 \ -device ich9-ahci,id=sata0,bus=bridge1,addr=0x1 \ -drive file=./ubuntu-ppc64le.qcow2,if=none,id=drive0,format=qcow2,cache=none \ -device ide-hd,bus=sata0.0,unit=0,drive=drive0,id=ide,bootindex=1 \ -device e1000e,netdev=net0,mac=C0:FF:EE:00:00:02,bus=bridge1,addr=0x2 \ -netdev bridge,helper=/usr/libexec/qemu-bridge-helper,br=virbr0,id=net0 \ -device nec-usb-xhci,bus=bridge1,addr=0x7 \ -serial mon:stdio -nographic ``` -------------------------------- ### QEMU Test Setup: Connecting to QMP Server Source: https://www.qemu.org/docs/master/devel/writing-monitor-commands.html Connect to the QEMU QMP server using telnet to initiate command negotiation. This is the initial step after starting the QEMU instance with the QMP server. ```bash $ telnet localhost 4444 Trying 127.0.0.1... Connected to localhost. Escape character is '^]'. ``` -------------------------------- ### Build and Install QPL Source: https://www.qemu.org/docs/master/devel/migration/qpl-compression.html Steps to clone the QPL repository, configure the build with CMake, and install the shared library. Ensure to set the correct build type and installation prefix. ```bash $git clone --recursive https://github.com/intel/qpl.git qpl $mkdir qpl/build $cd qpl/build $cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr -DQPL_LIBRARY_TYPE=SHARED .. $sudo cmake --build . --target install ``` -------------------------------- ### QEMU System Emulation with KVM and CPU Topology Source: https://www.qemu.org/docs/master/system/s390x/cpu-topology.html Example of starting a QEMU s390x system emulator with KVM acceleration, enabling CPU topology, and defining SMP configuration with specific topology parameters. It also includes adding a host CPU with a specific core-id. ```shell $ qemu-system-s390x -accel kvm -m 2G \ -cpu gen16b,ctop=on \ -smp cpus=5,sockets=8,cores=4,maxcpus=32 \ -device host-s390x-cpu,core-id=14 \ ``` -------------------------------- ### Starting the ivshmem Server and QEMU Instances Source: https://www.qemu.org/docs/master/system/devices/ivshmem.html This demonstrates starting the ivshmem server and then launching QEMU instances with matching arguments for interrupt support. ```bash # First start the ivshmem server once and for all ivshmem-server -p pidfile -S path -m shm-name -l shm-size -n vectors # Then start your qemu instances with matching arguments qemu-system-x86_64 -device ivshmem-doorbell,vectors=vectors,chardev=id -chardev socket,path=path,id=id ``` -------------------------------- ### Start Incoming Migration using URI Source: https://www.qemu.org/docs/master/interop/qemu-qmp-ref.html Starts an incoming migration process, listening on a specified URI. QEMU must be started with '-incoming defer' for this command to work. ```json -> { "execute": "migrate-incoming", "arguments": { "uri": "tcp:0:4446" } } <- { "return": {} } ``` -------------------------------- ### Basic QMP Example Source: https://www.qemu.org/docs/master/devel/qapi-code-gen.html A simple QMP example demonstrating a request and its response. ```qmp # .. qmp-example:: # # -> { "execute": "query-name" } # <- { "return": { "name": "Fred" } } ``` -------------------------------- ### Download Precompiled Shakti SDK Examples Source: https://www.qemu.org/docs/master/system/riscv/shakti-c.html Download and unzip precompiled example applications for the Shakti SDK. ```bash $ wget -c https://gitlab.com/behindbytes/shakti-binaries/-/raw/master/sdk/shakti_sdk_qemu.zip $ unzip shakti_sdk_qemu.zip ``` -------------------------------- ### Launch QEMU for GDB Debugging Source: https://www.qemu.org/docs/master/system/gdb.html Start QEMU with options to listen for GDB connections and wait for the debugger to attach before starting the guest. ```bash qemu-system-x86_64 -s -S -kernel bzImage -drive file=rootdisk.img,format=raw -append "root=/dev/sda" ``` -------------------------------- ### Start Destination QEMU with Incoming Migration Source: https://www.qemu.org/docs/master/system/devices/net.html Starts the destination QEMU instance, configured to accept an incoming migration over TCP on a specified port. ```bash qemu-system-x86_64 [...OPTIONS...] [...VHOST USER OPTIONS...] -incoming tcp:localhost:4444 ``` -------------------------------- ### Start Docker Service Source: https://www.qemu.org/docs/master/devel/testing/main.html Starts the Docker service. Verify the installation by running 'docker ps', which should display an empty table. ```bash $ sudo systemctl start docker $ sudo docker ps ``` -------------------------------- ### QEMU filter-rewriter Usage Example (COLO) Source: https://www.qemu.org/docs/master/system/invocation.html Example configuration for using filter-redirector and filter-rewriter objects in a COLO secondary setup. ```bash usage: colo secondary: -object filter-redirector,id=f1,netdev=hn0,queue=tx,indev=red0 -object filter-redirector,id=f2,netdev=hn0,queue=rx,outdev=red1 -object filter-rewriter,id=rew0,netdev=hn0,queue=all ``` -------------------------------- ### Run UART Example with QEMU Source: https://www.qemu.org/docs/master/system/riscv/shakti-c.html Execute the UART example application on the `shakti_c` machine using QEMU, specifying the BIOS path. ```bash $ qemu-system-riscv64 -M shakti_c -nographic \ -bios path/to/shakti_sdk_qemu/loopback.shakti ``` -------------------------------- ### QEMU Action Examples Source: https://www.qemu.org/docs/master/system/invocation.html Examples demonstrating how to use the '-action' parameter to control QEMU's response to guest events like panic, reboot, and shutdown. ```bash -action panic=none ``` ```bash -action reboot=shutdown,shutdown=pause ``` ```bash -device i6300esb -action watchdog=pause ``` -------------------------------- ### Start Destination QEMU Instance Source: https://www.qemu.org/docs/master/interop/live-block-operations.html Start the QEMU instance on the destination host, configuring it with the target disk and setting up a QMP monitor for control. The '-incoming tcp:localhost:6666' option is used here for simplicity, assuming a pre-configured migration target. ```bash $ qemu-system-x86_64 -display none -no-user-config -nodefaults \ -m 512 -blockdev \ node-name=node-TargetDisk,driver=qcow2,file.driver=file,file.node-name=file,file.filename=./target-disk.qcow2 \ -device virtio-blk,drive=node-TargetDisk,id=virtio0 \ -S -monitor stdio -qmp unix:./qmp-sock2,server=on,wait=off \ -incoming tcp:localhost:6666 ``` -------------------------------- ### Remote Process Command-line Example Source: https://www.qemu.org/docs/master/system/multi-process.html Example command-line for launching QEMU in remote process mode. This is used by the orchestrator to start a QEMU instance that will act as a remote process. ```bash /usr/bin/qemu-system-x86_64 -machine x-remote -device lsi53c895a,id=lsi0 -drive id=drive_image2,file=/build/ol7-nvme-test-1.qcow2 -device scsi-hd,id=drive2,drive=drive_image2,bus=lsi0.0,scsi-id=0 -object x-remote-object,id=robj1,devid=lsi0,fd=4, ``` -------------------------------- ### Start QEMU with TPM Emulator (pSeries) Source: https://www.qemu.org/docs/master/specs/tpm.html Command line to start QEMU for a pSeries machine with the TPM emulator device communicating with swtpm. ```bash qemu-system-ppc64 -display sdl -machine pseries,accel=kvm \ -m 1024 -bios slof.bin -boot menu=on \ -nodefaults -device VGA -device pci-ohci -device usb-kbd \ -chardev socket,id=chrtpm,path=/tmp/mytpm1/swtpm-sock \ -tpmdev emulator,id=tpm0,chardev=chrtpm \ -device tpm-spapr,tpmdev=tpm0 \ -device spapr-vscsi,id=scsi0,reg=0x00002000 \ -device virtio-blk-pci,bus=pci.0,addr=0x3,drive=drive-virtio-disk0,id=virtio-disk0 \ -drive file=test.img,format=raw,if=none,id=drive-virtio-disk0 ``` -------------------------------- ### Ansible Inventory Example Source: https://www.qemu.org/docs/master/devel/testing/ci.html An example inventory file for Ansible to specify hosts for CI setup. You can also specify host-specific variables like the Python interpreter path. ```yaml fully.qualified.domain other.machine.hostname ``` -------------------------------- ### HTTP/HTTPS/FTP/FTPS Example (Live ISO) Source: https://www.qemu.org/docs/master/system/invocation.html Boots a QEMU system from a remote live ISO image using HTTP. The 'readonly' option is specified. ```bash qemu-system-x86_64 --drive media=cdrom,file=https://archives.fedoraproject.org/pub/archive/fedora/linux/releases/20/Live/x86_64/Fedora-Live-Desktop-x86_64-20-1.iso,readonly ``` -------------------------------- ### Start Source QEMU for Migration Source: https://www.qemu.org/docs/master/system/devices/net.html Starts the source QEMU instance with necessary vhost-user options and a monitor interface enabled for sending migration commands. ```bash qemu-system-x86_64 [...OPTIONS...] [...VHOST USER OPTIONS...] -monitor stdio ``` -------------------------------- ### Hot Blocks Plugin Example Source: https://www.qemu.org/docs/master/about/emulation.html Examines hot paths of execution by reporting starting PC, translation count, instruction count, and execution count for code blocks. This example uses SHA1. ```bash $ qemu-aarch64 \ -plugin contrib/plugins/libhotblocks.so -d plugin \ ./tests/tcg/aarch64-linux-user/sha1 SHA1=15dd99a1991e0b3826fede3deffc1feba42278e6 collected 903 entries in the hash table pc, tcount, icount, ecount 0x0000000041ed10, 1, 5, 66087 0x000000004002b0, 1, 4, 66087 ... ``` -------------------------------- ### Start swtpm on Host Machine Source: https://www.qemu.org/docs/master/system/arm/xenpvh.html Example command to start the swtpm (virtual TPM emulator) on the host machine. This is required for xenpvh to support TPM functionalities for a guest domain when TPM is enabled. ```bash mkdir /tmp/vtpm2 swtpm socket --tpmstate dir=/tmp/vtpm2 \ --ctrl type=unixio,path=/tmp/vtpm2/swtpm-sock & ``` -------------------------------- ### Loading Multiple Plugins with Arguments Source: https://www.qemu.org/docs/master/about/emulation.html This example shows how to run a QEMU binary with multiple TCG plugins loaded. Arguments can be passed to each plugin to modify its behavior. ```bash $QEMU $OTHER_QEMU_ARGS \ -plugin contrib/plugins/libhowvec.so,inline=on,count=hint \ -plugin contrib/plugins/libhotblocks.so ``` -------------------------------- ### Define QMP Capability and Command with Pre-configuration Source: https://www.qemu.org/docs/master/devel/qapi-code-gen.html Example showing how to declare a QMP capability and a QMP command that is available before the machine is built. ```json { 'enum': 'QMPCapability', 'data': [ 'oob' ] } { 'command': 'qmp_capabilities', 'data': { '*enable': [ 'QMPCapability' ] }, 'allow-preconfig': true } ``` -------------------------------- ### qtest_init_ext Source: https://www.qemu.org/docs/master/devel/testing/qtest.html Initializes QEMU with extended options including QEMU binary source, extra arguments, capabilities, and connection behavior. ```APIDOC ## qtest_init_ext ### Description Like qtest_init(), but use a different environment variable for the QEMU binary, allow specify capabilities and skip connecting to QEMU monitor. ### Parameters #### Path Parameters - **var** (const char *) - Optional - Environment variable from where to take the QEMU binary - **extra_args** (const char *) - Optional - Other arguments to pass to QEMU. CAUTION: these arguments are subject to word splitting and shell evaluation. - **capabilities** (QList *) - Optional - list of QMP capabilities (strings) to enable - **do_connect** (bool) - Optional - connect to qemu monitor and qtest socket. ### Return `QTestState` instance. ``` -------------------------------- ### qemu_plugin_mem_size_shift Source: https://www.qemu.org/docs/master/devel/tcg-plugins.html Gets the size of a memory access operation, represented as a power of 2. For example, 0 for a byte, 1 for 16-bit, 2 for 32-bit, etc. ```APIDOC ## qemu_plugin_mem_size_shift ### Description Get the size of a memory access operation. ### Parameters * `qemu_plugin_meminfo_t info` - Opaque memory transaction handle. ### Return Size of access in power of 2 (0=byte, 1=16bit, 2=32bit etc.). ``` -------------------------------- ### Execute QMP Command with Arguments Source: https://www.qemu.org/docs/master/devel/writing-monitor-commands.html Shows examples of executing the 'hello-world' QMP command with and without arguments. The first execution uses default values, while the second provides a custom message. ```json { "execute": "hello-world" } { "return": { } } { "execute": "hello-world", "arguments": { "message": "We love QEMU" } } { "return": { } } ``` -------------------------------- ### QEMU MIOe-3680 PCI CAN Bus Emulation Source: https://www.qemu.org/docs/master/system/devices/can.html Emulate a MIOe-3680 PCI board with a single SJA1000 CAN channel. This example shows the basic setup for this dual-channel device. ```shell -device mioe3680_pci,canbus0=canbus0 ``` -------------------------------- ### QEMU CPR Migration: Incoming URI Example Source: https://www.qemu.org/docs/master/devel/migration/CPR.html This example demonstrates setting up and executing a QEMU migration using cpr-exec mode with an incoming file URI. It shows the monitor commands to set the migration mode, specify the execution command, and initiate the migration. ```bash # qemu-kvm -monitor stdio -object memory-backend-memfd,id=ram0,size=4G -machine memory-backend=ram0 -machine aux-ram-share=on ... QEMU 10.2.50 monitor - type 'help' for more information (qemu) info status VM status: running (qemu) migrate_set_parameter mode cpr-exec (qemu) migrate_set_parameter cpr-exec-command qemu-kvm ... -incoming file:vm.state (qemu) migrate -d file:vm.state (qemu) QEMU 10.2.50 monitor - type 'help' for more information (qemu) info status VM status: running ``` -------------------------------- ### object_get_canonical_path_component Source: https://www.qemu.org/docs/master/devel/qom-api.html Gets the final component in an object's canonical path. The canonical path represents the object's position within the composition tree starting from the root. ```APIDOC ## object_get_canonical_path_component ### Description The final component in the object’s canonical path. The canonical path is the path within the composition tree starting from the root. ### Parameters - **obj** (const Object *) - the object ### Return - const char* - The final component in the object’s canonical path. `NULL` if the object doesn’t have a parent (and thus a canonical path). ``` -------------------------------- ### HTTP/HTTPS/FTP/FTPS Example (Explicit Driver Options) Source: https://www.qemu.org/docs/master/system/invocation.html Boots a QEMU system from a remote ISO using explicit driver options for HTTP. This allows specifying the URL and other parameters like 'readonly'. ```bash qemu-system-x86_64 --drive media=cdrom,file.driver=http,file.url=http://archives.fedoraproject.org/pub/fedora/linux/releases/20/Live/x86_64/Fedora-Live-Desktop-x86_64-20-1.iso,readonly ``` -------------------------------- ### QEMU PCM-3680I PCI Dual Channel CAN Bus Setup Source: https://www.qemu.org/docs/master/system/devices/can.html Emulate a PCM-3680I PCI board with two SJA1000 CAN channels. This example shows how to assign two separate CAN buses to the dual-channel device. ```shell -object can-bus,id=canbus0 -device pcm3680_pci,canbus0=canbus0,canbus1=canbus0 ``` -------------------------------- ### Basic QemuSystemTest Example Source: https://www.qemu.org/docs/master/devel/testing/functional.html A simple test case demonstrating the basic usage of QemuSystemTest to launch a VM and query its version. This can be run stand-alone or via a test runner. ```python #!/usr/bin/env python3 from qemu_test import QemuSystemTest class Version(QemuSystemTest): def test_qmp_human_info_version(self): self.vm.launch() res = self.vm.cmd('human-monitor-command', command_line='info version') self.assertRegex(res, r'^(\d+\.\d+\.\d)') if __name__ == '__main__': QemuSystemTest.main() ``` -------------------------------- ### Execute a Simple QMP Command Source: https://www.qemu.org/docs/master/devel/writing-monitor-commands.html Demonstrates how to execute the 'hello-world' QMP command from a client. This involves sending a JSON-RPC request to the QEMU monitor. ```json { "execute": "hello-world" } ``` -------------------------------- ### Example Downstream QMP Command Source: https://www.qemu.org/docs/master/interop/qmp-spec.html Demonstrates how a downstream extension to a QMP command should be prefixed. Downstream names must start with `__`, and it's recommended to use a reverse-qualified domain name prefix for uniqueness. ```qemu-monitor (qemu) __org.linux-kvm_enable_irqchip ``` -------------------------------- ### Example of qapi:module directive Source: https://www.qemu.org/docs/master/devel/qapi-domain.html The `qapi:module` directive marks the start of a QAPI module. It can have an optional content body. Subsequent QAPI directives are associated with this module, affecting their fully qualified name. ```rst .. qapi:module:: block-core Welcome to the block-core module! ``` -------------------------------- ### QEMU L2TPv3 network backend example Source: https://www.qemu.org/docs/master/system/invocation.html Sets up an L2TPv3 pseudowire for Layer 2 data transport between VMs or to a network. Requires source and destination addresses, and optionally UDP encapsulation and ports. ```bash # on 4.3.2.1 # launch QEMU instance - if your network has reorder or is very lossy add ,pincounter qemu-system-x86_64 linux.img -device e1000,netdev=n1 \ -netdev l2tpv3,id=n1,src=4.2.3.1,dst=1.2.3.4,udp=on,srcport=16384,dstport=16384,rxsession=0xffffffff,txsession=0xffffffff,counter=on ``` -------------------------------- ### qtest_qemu_args Source: https://www.qemu.org/docs/master/devel/testing/qtest.html Returns the command line arguments used to start QEMU, excluding the binary path. ```APIDOC ## qtest_qemu_args ### Description Return the command line used to start QEMU, sans binary. ### Parameters #### Path Parameters - **extra_args** (const char *) - Optional - Other arguments to pass to QEMU. ### Return `gchar *` command line arguments. ``` -------------------------------- ### Loading Xen Hypervisor and Dom0 Guest Source: https://www.qemu.org/docs/master/system/guest-loader.html Example demonstrating how to load the Xen hypervisor and its Dom0 guest using the guest-loader device. This setup involves specifying kernel, boot arguments, and memory addresses for the guest blobs. ```bash qemu-system-x86_64 -kernel ~/xen.git/xen/xen -append "dom0_mem=1G,max:1G loglvl=all guest_loglvl=all" -device guest-loader,addr=0x42000000,kernel=Image,bootargs="root=/dev/sda2 ro console=hvc0 earlyprintk=xen" -device guest-loader,addr=0x47000000,initrd=rootfs.cpio ``` -------------------------------- ### Run trace session with verbose output Source: https://www.qemu.org/docs/master/tools/qemu-trace-stap.html Run a trace session with verbose output enabled, useful for debugging the tracing environment setup. This example also shows how to specify a QEMU binary not located in the system's PATH. ```bash $ qemu-trace-stap -v run /opt/qemu/11.0.50/bin/qemu-system-x86_64 'qio*' ``` -------------------------------- ### Start QEMU with D-Bus Display Backend Source: https://www.qemu.org/docs/master/tools/qemu-vnc.html Initiates QEMU with the D-Bus display backend enabled. This is a prerequisite for attaching qemu-vnc. ```bash qemu-system-x86_64 -display dbus ... ``` -------------------------------- ### QEMU x86_64 VM with Kvaser PCI and SocketCAN Source: https://www.qemu.org/docs/master/system/devices/can.html Example of starting a QEMU x86_64 virtual machine with KVM acceleration, including a Kvaser PCI CAN device connected to the host's SocketCAN interface. Requires specific kernel and initrd. ```shell qemu-system-x86_64 -accel kvm -kernel /boot/vmlinuz-4.9.0-4-amd64 \ -initrd ramdisk.cpio \ -virtfs local,path=shareddir,security_model=none,mount_tag=shareddir \ -object can-bus,id=canbus0 \ -object can-host-socketcan,id=canhost0,if=can0,canbus=canbus0 \ -device kvaser_pci,canbus=canbus0 \ -nographic -append "console=ttyS0" ``` -------------------------------- ### Start VNC Client and Switch to Virtual Console Source: https://www.qemu.org/docs/master/system/invocation.html Launch a VNC client to connect to display :0 and then switch to virtual console 2 using Ctrl-Alt-2. ```bash vncviewer :0 ``` -------------------------------- ### Example of qapi:namespace directive Source: https://www.qemu.org/docs/master/devel/qapi-domain.html The `qapi:namespace` directive marks the start of a QAPI namespace. It does not take a content body or options. Subsequent QAPI directives are associated with this namespace, affecting their fully qualified name and influencing reference resolution. ```rst .. qapi:namespace:: QMP ``` -------------------------------- ### Running a Minimal microVM Instance Source: https://www.qemu.org/docs/master/system/i386/microvm.html This example shows how to run a microVM instance with optional legacy features disabled to reduce footprint. It leverages KVM clock and disables RTC, PIC, PIT, and ISA serial devices for a more optimized setup. ```bash $ qemu-system-x86_64 \ -M microvm,x-option-roms=off,pit=off,pic=off,isa-serial=off,rtc=off \ -enable-kvm -cpu host -m 512m -smp 2 \ -kernel vmlinux -append "console=hvc0 root=/dev/vda" \ -nodefaults -no-user-config -nographic \ -chardev stdio,id=virtiocon0 \ -device virtio-serial-device \ -device virtconsole,chardev=virtiocon0 \ -drive id=test,file=test.img,format=raw,if=none \ -device virtio-blk-device,drive=test \ -netdev tap,id=tap0,script=no,downscript=no \ -device virtio-net-device,netdev=tap0 ``` -------------------------------- ### QEMU Guest Agent Configuration Sample Source: https://www.qemu.org/docs/master/interop/qemu-ga.html A sample configuration file for qemu-ga, demonstrating key-value pairs for general settings. ```ini # qemu-ga configuration sample [general] demonize = 0 pidfile = /var/run/qemu-ga.pid verbose = 0 method = virtio-serial path = /dev/virtio-ports/org.qemu.guest_agent.0 statedir = /var/run ``` -------------------------------- ### Connect VMs using Unix Domain Socket Source: https://www.qemu.org/docs/master/system/invocation.html Configures a network backend to connect to another QEMU VM or proxy using a stream-oriented Unix domain socket. This example shows starting `passt` as a server, which binds to a Unix domain socket. ```bash # start passt server as a non privileged user passt UNIX domain socket bound at /tmp/passt_1.socket ``` -------------------------------- ### Basic Block Execution Measurement Source: https://www.qemu.org/docs/master/about/emulation.html This example demonstrates running a QEMU binary with the 'libbb.so' plugin to measure basic block execution. Results are typically shown after execution finishes. ```bash $ qemu-aarch64 -plugin tests/plugin/libbb.so \ -d plugin ./tests/tcg/aarch64-linux-user/sha1 ``` -------------------------------- ### QEMU ARM VM with Kvaser PCI and SocketCAN Source: https://www.qemu.org/docs/master/system/devices/can.html Example of starting a QEMU ARM virtual machine with a versatilepb board, including a Kvaser PCI CAN device connected to the host's SocketCAN interface. Requires specific kernel and disk image. ```shell qemu-system-arm -cpu arm1176 -m 256 -M versatilepb \ -kernel kernel-qemu-arm1176-versatilepb \ -hda rpi-wheezy-overlay \ -append "console=ttyAMA0 root=/dev/sda2 ro init=/sbin/init-overlay" \ -nographic \ -virtfs local,path=shareddir,security_model=none,mount_tag=shareddir \ -object can-bus,id=canbus0 \ -object can-host-socketcan,id=canhost0,if=can0,canbus=canbus0 \ -device kvaser_pci,canbus=canbus0,host=can0 \ ``` -------------------------------- ### Running a Basic microVM Instance Source: https://www.qemu.org/docs/master/system/i386/microvm.html This example demonstrates how to run a microVM instance with default settings, using the legacy ISA serial device as the console. It includes essential configurations for KVM, CPU, memory, kernel, and drives. ```bash $ qemu-system-x86_64 -M microvm \ -enable-kvm -cpu host -m 512m -smp 2 \ -kernel vmlinux -append "earlyprintk=ttyS0 console=ttyS0 root=/dev/vda" \ -nodefaults -no-user-config -nographic \ -serial stdio \ -drive id=test,file=test.img,format=raw,if=none \ -device virtio-blk-device,drive=test \ -netdev tap,id=tap0,script=no,downscript=no \ -device virtio-net-device,netdev=tap0 ``` -------------------------------- ### Example: Memory Backend RAM for Old Migration Source: https://www.qemu.org/docs/master/system/invocation.html Example for configuring a memory backend RAM object for migration compatibility with older QEMU versions (<5.0), disabling canonical path usage. ```bash -object memory-backend-ram,id=pc.ram,size=512M,x-use-canonical-path-for-ramblock-id=off -machine memory-backend=pc.ram -m 512M ``` -------------------------------- ### Install Podman (Fedora/RHEL) Source: https://www.qemu.org/docs/master/devel/testing/main.html Installs the Podman package using the DNF package manager. Verify the installation by running 'podman ps'. ```bash $ sudo dnf install podman $ podman ps ``` -------------------------------- ### Creating an image with a backing file in qemu-img Source: https://www.qemu.org/docs/master/about/removed-features.html Demonstrates the safer way to create an image with a backing file using `qemu-img create`. Failures to open the backing image are now treated as errors unless the `-u` option is explicitly used. ```bash qemu-img create -b bad file $size ``` -------------------------------- ### Install Bindgen CLI with Cargo Source: https://www.qemu.org/docs/master/about/build-platforms.html If bindgen is not available or an older version is present, install a newer version using cargo install. ```bash cargo install --locked bindgen-cli ``` -------------------------------- ### Start and Stop LTTng Tracing Source: https://www.qemu.org/docs/master/devel/tracing.html Start and stop the LTTng tracing session as needed. Ensure the session is created and events are enabled before starting. ```bash lttng start lttng stop ``` -------------------------------- ### Example Default Configuration File Source: https://www.qemu.org/docs/master/devel/kconfig.html A sample configuration file used to initialize Kconfig variables and set default device/subsystem states for a specific target. ```makefile # Default configuration for alpha-softmmu # Uncomment the following lines to disable these optional devices: # #CONFIG_PCI_DEVICES=n #CONFIG_TEST_DEVICES=n # Boards: ``` -------------------------------- ### Do Not Start CPU at Startup Source: https://www.qemu.org/docs/master/system/invocation.html Prevents the CPU from starting immediately upon QEMU startup. You must manually start the CPU by typing 'c' in the monitor. ```bash -S ``` -------------------------------- ### Windows 2000 Installation Hack Source: https://www.qemu.org/docs/master/system/invocation.html Use this option during Windows 2000 installation to avoid a disk full bug. It can be removed after installation as it slows down IDE transfers. ```bash -win2k-hack ``` -------------------------------- ### Launching a TDX VM with QEMU Source: https://www.qemu.org/docs/master/system/i386/tdx.html Example command line for launching a TDX VM, including essential options like tdx-guest object and split kernel-irqchip. ```shell qemu-system-x86_64 \ -accel kvm \ -cpu host \ -object tdx-guest,id=tdx0 \ -machine ...,confidential-guest-support=tdx0 \ -bios OVMF.fd \ ``` -------------------------------- ### Start Incoming Migration using RDMA Channel Source: https://www.qemu.org/docs/master/interop/qemu-qmp-ref.html Starts an incoming migration using a migration channel configured with RDMA transport. QEMU must be started with '-incoming defer'. ```json -> { "execute": "migrate-incoming", "arguments": { "channels": [ { "channel-type": "main", "addr": { "transport": "rdma", ``` -------------------------------- ### Start Incoming Migration using Exec Channel Source: https://www.qemu.org/docs/master/interop/qemu-qmp-ref.html Starts an incoming migration using a migration channel configured with an 'exec' transport. QEMU must be started with '-incoming defer'. ```json -> { "execute": "migrate-incoming", "arguments": { "channels": [ { "channel-type": "main", "addr": { "transport": "exec", "args": [ "/bin/nc", "-p", "6000", "/some/sock" ] } } ] } } <- { "return": {} } ``` -------------------------------- ### Configure and Build QEMU with Smartcard Support Source: https://www.qemu.org/docs/master/system/devices/ccid.html Configure QEMU to enable smartcard support and then build the project. ```bash ./configure --enable-smartcard && make ``` -------------------------------- ### Start Incoming Migration using Socket Channel Source: https://www.qemu.org/docs/master/interop/qemu-qmp-ref.html Starts an incoming migration using a migration channel configured with a socket transport. This requires QEMU to be started with '-incoming defer'. ```json -> { "execute": "migrate-incoming", "arguments": { "channels": [ { "channel-type": "main", "addr": { "transport": "socket", "type": "inet", "host": "10.12.34.9", "port": "1050" } } ] } } <- { "return": {} } ``` -------------------------------- ### Enable CoLo Migration and Start Migration Source: https://www.qemu.org/docs/master/system/qemu-colo.html Enable the 'x-colo' migration capability and then initiate the migration to the specified URI. This prepares the QEMU instance for live replication. ```json {"execute": "migrate-set-capabilities", "arguments":{ "capabilities": [ {"capability": "x-colo", "state": true } ] } } ``` ```json {"execute": "migrate", "arguments":{ "uri": "tcp:127.0.0.1:9998" } } ``` -------------------------------- ### Start QEMU with vhost-user device Source: https://www.qemu.org/docs/master/system/devices/virtio/vhost-user.html This command starts a QEMU instance with a vhost-user device. It specifies the memory size, a socket character device for communication with the daemon, the vhost-user device itself, and a shared memory backend. ```bash $ qemu-system-x86_64 \ -m 4096 \ -chardev socket,id=ba1,path=/var/run/foo.sock \ -device vhost-user-foo,chardev=ba1,$OTHER_ARGS \ -object memory-backend-memfd,id=mem,size=4G,share=on \ -numa node,memdev=mem \ ... ``` -------------------------------- ### Unsupported Asymmetrical Topology Example Source: https://www.qemu.org/docs/master/specs/ppc-spapr-numa.html An example of a NUMA topology that is not supported due to asymmetry. ```text 0 1 0 10 40 1 20 10 ``` -------------------------------- ### Definition Documentation Example Source: https://www.qemu.org/docs/master/devel/qapi-code-gen.html Example of documenting a QAPI definition with name, description, and arguments. ```qapi # @BlockStats: # # Statistics of a virtual block device or a block backing device. # # @device: If the stats are for a virtual block device, the name ```