QEMU(1)

πŸ“¦
version 11.1.0 Β· 3 versions
, in centos-stream 10

🌸 QEMU(1) 🌸

ok so this is the QEMU manual page, bestie β€” like, the whole qemu / qemu-kvm user documentation situation. buckle up, it's a long one πŸ’…


✨ NAME ✨

qemu β€” QEMU User Documentation 🫢


✨ SYNOPSIS ✨

qemu-kvm [options] [disk_image]

✨ DESCRIPTION ✨

so the QEMU PC System emulator simulates all of these peripherals, and honestly the list is giving museum of vintage hardware:

  • i440FX host PCI bridge and PIIX3 PCI to ISA bridge
  • Cirrus CLGD 5446 PCI VGA card or dummy VGA card with Bochs VESA extensions (hardware level, including all non standard modes).
  • PS/2 mouse and keyboard
  • 2 PCI IDE interfaces with hard disk and CD-ROM support
  • Floppy disk
  • PCI and ISA network adapters
  • Serial ports
  • IPMI BMC, either an internal or external one
  • Creative SoundBlaster 16 sound card
  • ENSONIQ AudioPCI ES1370 sound card
  • Intel 82801AA AC97 Audio compatible sound card
  • Intel HD Audio Controller and HDA codec
  • Adlib (OPL2) - Yamaha YM3812 compatible chip
  • Gravis Ultrasound GF1 sound card
  • CS4231A compatible sound card
  • PC speaker
  • PCI UHCI, OHCI, EHCI or XHCI USB controller and a virtual USB-1.1 hub.

SMP is supported with a large number of virtual CPUs (upper limit is configuration dependent). πŸ”₯

QEMU uses the PC BIOS from the Seabios project and the Plex86/Bochs LGPL VGA BIOS.

QEMU uses YM3812 emulation by Tatsuyuki Satoh.

QEMU uses GUS emulation (GUSEMU32 http://www.deinmeister.de/gusemu/) by Tibor "TS" SchΓΌtz.

πŸ’€ heads up bestie: by default, GUS shares IRQ(7) with parallel ports, so QEMU must be told to not have parallel ports to have working GUS.
qemu-kvm dos.img -device gus -parallel none

Alternatively:

qemu-kvm dos.img -device gus,irq=5

Or some other unclaimed IRQ. pick your fighter ✨

CS4231A is the chip used in Windows Sound System and GUSMAX products

The PC speaker audio device can be configured using the pcspk-audiodev machine property, i.e.

qemu-kvm some.img -audiodev <backend>,id=<name> -machine pcspk-audiodev=<name>

πŸŽ€ Machine-specific options πŸŽ€

It supports the following machine-specific options:

  • x-south-bridge=PIIX3|piix4-isa (Experimental option to select a particular south bridge. Default: PIIX3) β€” lowkey experimental, so don't come for me if it's weird πŸ™ˆ

✨ OPTIONS ✨

disk_image is a raw hard disk image for IDE hard disk 0. Some targets do not need a disk image. (iykyk)

When dealing with options parameters as arbitrary strings containing commas, such as in "file=my,file" and "string=a,b", it's necessary to double the commas. For instance, "-fw_cfg name=z,string=a,,b" will be parsed as "-fw_cfg name=z,string=a,b". no cap, the double comma thing is real 🫠

πŸ’– Standard options πŸ’–

  • -h β€” Display help and exit
  • -version β€” Display version information and exit
  • -machine [type=]name[,prop=value[,...]] β€” Select the emulated machine by name. Use -machine help to list available machines.

For architectures which aim to support live migration compatibility across releases, each release will introduce a new versioned machine type. For example, the 2.8.0 release introduced machine types "pc-i440fx-2.8" and "pc-q35-2.8" for the x86_64/i686 architectures.

To allow live migration of guests from QEMU version 2.8.0, to QEMU version 2.9.0, the 2.9.0 version must support the "pc-i440fx-2.8" and "pc-q35-2.8" machines too. To allow users live migrating VMs to skip multiple intermediate releases when upgrading, new releases of QEMU will support machine types from many previous versions. ✨

Supported machine properties are:

  • accel=accels1[:accels2[:...]] β€” This is used to enable an accelerator. Depending on the target architecture, kvm, xen, hvf, nitro, nvmm, whpx, mshv or tcg can be available. By default, tcg is used. If there is more than one accelerator specified, the next one is used if the previous one fails to initialize.
  • vmport=on|off|auto β€” Enables emulation of VMWare IO port, for vmmouse etc. auto says to select the value based on accel and i8042. For accel=xen or i8042=off the default is off, otherwise the default is on.
  • dump-guest-core=on|off β€” Include guest memory in a core dump. The default is on.
  • mem-merge=on|off β€” Enables or disables memory merge support. This feature, when supported by the host, de-duplicates identical memory pages among VMs instances (enabled by default).
  • aes-key-wrap=on|off β€” Enables or disables AES key wrapping support on s390-ccw hosts. This feature controls whether AES wrapping keys will be created to allow execution of AES cryptographic functions. The default is on.
  • dea-key-wrap=on|off β€” Enables or disables DEA key wrapping support on s390-ccw hosts. This feature controls whether DEA wrapping keys will be created to allow execution of DEA cryptographic functions. The default is on.
  • nvdimm=on|off β€” Enables or disables NVDIMM support. The default is off.
  • confidential-guest-support=<id> β€” confidential guest support object to use. The default is none.
  • memory-encryption=<id> β€” The alias of confidential-guest-support. Recommend to use confidential-guest-support. (like, the alias is cute but use the real one bestie 🫢)
  • hmat=on|off β€” Enables or disables ACPI Heterogeneous Memory Attribute Table (HMAT) support. The default is off.
  • spcr=on|off β€” Enables or disables ACPI Serial Port Console Redirection Table (SPCR) support. The default is on.
  • aux-ram-share=on|off β€” Allocate auxiliary guest RAM as an anonymous file that is shareable with an external process. This option applies to memory allocated as a side effect of creating various devices. It does not apply to memory-backend-objects, whether explicitly specified on the command line, or implicitly created by the -m command line option. The default is off.

To use the cpr-transfer migration mode, you must set aux-ram-share=on.

  • memory-backend='id' β€” An alternative to legacy -mem-path and mem-prealloc options. Allows to use a memory backend as main RAM.

For example:

-object memory-backend-file,id=pc.ram,size=512M,mem-path=/hugetlbfs,prealloc=on,share=on
-machine memory-backend=pc.ram
-m 512M

Migration compatibility note:

  • as backend id one shall use value of 'default-ram-id', advertised by machine type (available via query-machines QMP command), if migration to/from old QEMU (<5.0) is expected.
  • for machine types 4.0 and older, user shall use x-use-canonical-path-for-ramblock-id=off backend option if migration to/from old QEMU (<5.0) is expected.

For example:

-object memory-backend-ram,id=pc.ram,size=512M,x-use-canonical-path-for-ramblock-id=off
-machine memory-backend=pc.ram
-m 512M
  • cxl-fmw.0.targets.0=firsttarget,cxl-fmw.0.targets.1=secondtarget,cxl-fmw.0.size=size[,cxl-fmw.0.interleave-granularity=granularity] β€” Define a CXL Fixed Memory Window (CFMW).

Described in the CXL 2.0 ECN: CEDT CFMWS & QTG _DSM.

They are regions of Host Physical Addresses (HPA) on a system which may be interleaved across one or more CXL host bridges. The system software will assign particular devices into these windows and configure the downstream Host-managed Device Memory (HDM) decoders in root ports, switch ports and devices appropriately to meet the interleave requirements before enabling the memory devices. πŸ¦‹

targets.X=target provides the mapping to CXL host bridges which may be identified by the id provided in the -device entry. Multiple entries are needed to specify all the targets when the fixed memory window represents interleaved memory. X is the target index from 0.

size=size sets the size of the CFMW. This must be a multiple of 256MiB. The region will be aligned to 256MiB but the location is platform and configuration dependent.

interleave-granularity=granularity sets the granularity of interleave. Default 256 (bytes). Only 256, 512, 1k, 2k, 4k, 8k and 16k granularities supported.

Example:

-machine cxl-fmw.0.targets.0=cxl.0,cxl-fmw.0.targets.1=cxl.1,cxl-fmw.0.size=128G,cxl-fmw.0.interleave-granularity=512
  • sgx-epc.0.memdev=<memid>,sgx-epc.0.node=<numaid> β€” Define an SGX EPC section.
  • smp-cache.0.cache=cachename,smp-cache.0.topology=topologylevel β€” Define cache properties for SMP system.

cache=cachename specifies the cache that the properties will be applied on. This field is the combination of cache level and cache type. It supports l1d (L1 data cache), l1i (L1 instruction cache), l2 (L2 unified cache) and l3 (L3 unified cache).

topology=topologylevel sets the cache topology level. It accepts CPU topology levels including core, module, cluster, die, socket, book, drawer and a special value default. If default is set, then the cache topology will follow the architecture's default cache topology model. If another topology level is set, the cache will be shared at corresponding CPU topology level. For example, topology=core makes the cache shared by all threads within a core. The omitting cache will default to using the default level.

The default cache topology model for an i386 PC machine is as follows: l1d, l1i, and l2 caches are per core, while the l3 cache is per die. ✨

Example:

-machine smp-cache.0.cache=l1d,smp-cache.0.topology=core,smp-cache.1.cache=l1i,smp-cache.1.topology=core
  • -M β€” as -machine. (literally the same thing, just shorter πŸ’…)
  • -cpu model β€” Select CPU model (-cpu help for list and additional feature selection)

  • -accel name[,prop=value[,...]] β€” this is your "bestie, please go fast" switch πŸ’¨. It turns on an accelerator. Depending on the target architecture, kvm, xen, hvf, nitro, nvmm, whpx, mshv or tcg can be available. By default, tcg is used. And if there's more than one accelerator specified? Then the next one gets used if the previous one fails to initialize. So it's a little fallback chain, cute.
    • igd-passthru=on|off β€” when Xen is in use, this controls whether Intel integrated graphics devices can be passed through to the guest (default=off). off by default, so flip it on only if you actually mean it ✨
    • kernel-irqchip=on|off|split β€” controls KVM in-kernel irqchip support. The default is full acceleration of the interrupt controllers. On x86, split irqchip reduces the kernel attack surface, at a performance cost for non-MSI interrupts. Fully disabling the in-kernel irqchip? not recommended except for debugging purposes, periodt.
    • kvm-shadow-mem=size β€” defines the size of the KVM shadow MMU.
    • one-insn-per-tb=on|off β€” makes the TCG accelerator put only one guest instruction into each translation block. Heads up: this slows down emulation a lot, but it can be useful in some situations, like when you're trying to analyse the logs produced by the -d option. Little microscope mode πŸ”¬
    • split-wx=on|off β€” controls the use of split w^x mapping for the TCG code generation buffer. Some operating systems require this to be enabled, and in such a case this will default on. On other operating systems it defaults off, but you can enable it for testing or debugging. Slay for security testing πŸ›‘οΈ
    • tb-size=n β€” controls the size (in MiB) of the TCG translation block cache.
    • thread=single|multi β€” controls number of TCG threads. When TCG is multi-threaded there'll be one thread per vCPU, therefore taking advantage of additional host cores. Default is to enable multi-threading where both the back-end and front-ends support it and no incompatible TCG features have been enabled (e.g. icount/replay). more cores = more better, usually 🧚
    • dirty-ring-size=n β€” when the KVM accelerator is used, this controls the size of the per-vCPU dirty page ring buffer (number of entries for each vCPU). It should be a value that's a power of two, and it should be 1024 or bigger (but still less than the maximum value that the kernel supports). 4096 could be a good initial value if you have no idea which is the best πŸ‘‘ Set this value to 0 to disable the feature. By default this feature is disabled (dirty-ring-size=0). When enabled, KVM will instead record dirty pages in a bitmap.
    • eager-split-size=n β€” okay so KVM implements dirty page logging at the PAGE_SIZE granularity, and enabling dirty-logging on a huge-page requires breaking it into PAGE_SIZE pages in the first place. KVM on ARM does this splitting lazily by default. There are performance benefits in doing huge-page split eagerly, especially in situations where TLBI costs associated with break-before-make sequences are considerable and also if guest workloads are read intensive. The size here specifies how many pages to break at a time and needs to be a valid block size, which is 1GiB/2MiB/4KiB, 32MiB/16KiB and 512MiB/64KiB for 4KiB/16KiB/64KiB PAGE_SIZE respectively. Be wary of specifying a higher size β€” it'll have an impact on the memory. By default this feature is disabled (eager-split-size=0).
    • notify-vmexit=run|internal-error|disable,notify-window=n β€” enables or disables notify VM exit support on x86 host and specifies the corresponding notify window to trigger the VM exit if enabled. The run option enables the feature β€” it does nothing and continues if the exit happens. The internal-error option enables the feature and raises an internal error 😭 The disable option doesn't enable the feature. This feature can mitigate the CPU stuck issue due to event windows not opening up for a specified amount of time (i.e. notify-window). Default: notify-vmexit=run,notify-window=0.
    • device=path β€” sets the path to the KVM device node. Defaults to /dev/kvm. This option can be used to pass the KVM device to use via a file descriptor by setting the value to /dev/fdset/NN.
    • hyperv=on|off|auto β€” for the WHPX backend, determines whether to enable Hyper-V enlightenments. On x86_64, Hyper-V enlightenments are on by default. On AArch64, they're off by default. arch-dependent defaults, iykyk πŸ’…
  • -smp β€” the "how many little guys do we spawn" option πŸ‘―β€β™€οΈ Full shape:
-smp [[cpus=]n][,maxcpus=maxcpus][,drawers=drawers][,books=books][,sockets=sockets][,dies=dies][,clusters=clusters][,modules=modules][,cores=cores][,threads=threads]

Simulate a SMP system with n CPUs initially present on the machine type board. On boards supporting CPU hotplug, the optional maxcpus parameter can be set to enable further CPUs to be added at runtime 🫢 When both parameters are omitted, the maximum number of CPUs will be calculated from the provided topology members and the initial CPU count will match the maximum number. When only one of them is given, then the omitted one will be set to its counterpart's value. Both parameters may be specified, but the maximum number of CPUs must be equal to or greater than the initial CPU count. Product of the CPU topology hierarchy must be equal to the maximum number of CPUs. Both parameters are subject to an upper limit determined by the specific machine type chosen.

To control reporting of CPU topology information, values of the topology parameters can be specified. Machines may only support a subset of the parameters, and different machines may have different subsets supported which vary depending on capacity of the corresponding CPU targets. So for a particular machine type board, an expected topology hierarchy can be defined through the supported sub-option. Unsupported parameters can also be provided in addition to the sub-option, but their values must be set as 1 in the purpose of correct parsing. Weird little rule but okay, we respect it πŸ™ˆ

Either the initial CPU count, or at least one of the topology parameters must be specified. The specified parameters must be greater than zero β€” explicit configuration like "cpus=0" is not allowed, no cap πŸ’€ Values for any omitted parameters will be computed from those which are given.

For example, the following sub-option defines a CPU topology hierarchy (2 sockets totally on the machine, 2 cores per socket, 2 threads per core) for a machine that only supports sockets/cores/threads. Some members of the option can be omitted but their values will be automatically computed:

-smp 8,sockets=2,cores=2,threads=2,maxcpus=8

The following sub-option defines a CPU topology hierarchy (2 sockets totally on the machine, 2 dies per socket, 2 modules per die, 2 cores per module, 2 threads per core) for PC machines which support sockets/dies/modules/cores/threads. Some members of the option can be omitted but their values will be automatically computed:

-smp 32,sockets=2,dies=2,modules=2,cores=2,threads=2,maxcpus=32

The following sub-option defines a CPU topology hierarchy (2 sockets totally on the machine, 2 clusters per socket, 2 cores per cluster, 2 threads per core) for ARM virt machines which support sockets/clusters/cores/threads. Some members of the option can be omitted but their values will be automatically computed:

-smp 16,sockets=2,clusters=2,cores=2,threads=2,maxcpus=16

Historically, preference was given to the coarsest topology parameters when computing missing values (ie sockets preferred over cores, which were preferred over threads), however, this behaviour is considered liable to change ⚠️ Prior to 6.2 the preference was sockets over cores over threads. Since 6.2 the preference is cores over sockets over threads.

For example, the following option defines a machine board with 2 sockets of 1 core before 6.2 and 1 socket of 2 cores after 6.2:

-smp 2
Note: the cluster topology will only be generated in ACPI and exposed to guest if it's explicitly specified in -smp. No sneaky auto-clusters, bestie πŸŽ€

  • -numa β€” the whole NUMA family 🌈 Six whole shapes, keep up:
-numa node[,mem=size][,cpus=firstcpu[-lastcpu]][,nodeid=node][,initiator=initiator]
-numa node[,memdev=id][,cpus=firstcpu[-lastcpu]][,nodeid=node][,initiator=initiator]
-numa dist,src=source,dst=destination,val=distance
-numa cpu,node-id=node[,socket-id=x][,core-id=y][,thread-id=z]
-numa hmat-lb,initiator=node,target=node,hierarchy=hierarchy,data-type=type[,latency=lat][,bandwidth=bw]
-numa hmat-cache,node-id=node,size=size,level=level[,associativity=str][,policy=str][,line=size]

Define a NUMA node and assign RAM and VCPUs to it ✨ Set the NUMA distance from a source node to a destination node. Set the ACPI Heterogeneous Memory Attributes for the given nodes.

Legacy VCPU assignment uses the cpus option, where firstcpu and lastcpu are CPU indexes. Each cpus option represents a contiguous range of CPU indexes (or a single VCPU if lastcpu is omitted). A non-contiguous set of VCPUs can be represented by providing multiple cpus options. If cpus is omitted on all nodes, VCPUs are automatically split between them. Auto-split, how thoughtful 🧚

For example, the following option assigns VCPUs 0, 1, 2 and 5 to a NUMA node:

-numa node,cpus=0-2,cpus=5

So the 'cpu' option is like, the new alternative to the 'cpus' option β€” it uses 'socket-id|core-id|thread-id' properties to assign CPU objects to a node, using the topology layout properties of CPU. The set of properties is machine specific and depends on the machine type / 'smp' options you're using. You can query them with the 'hotpluggable-cpus' monitor command. And the 'node-id' property specifies which node the CPU object gets assigned to β€” and it's required for the node to be declared with the 'node' option before you use it with the 'cpu' option. fr fr πŸ’…

For example:

-M pc \
-smp 1,sockets=2,maxcpus=2 \
-numa node,nodeid=0 -numa node,nodeid=1 \
-numa cpu,node-id=0,socket-id=0 -numa cpu,node-id=1,socket-id=1

Okay next: the 'memdev' option assigns RAM from a given memory backend device to a node. And bestie, it is recommended to use 'memdev' over the legacy 'mem' option β€” because 'memdev' gives you better performance and more control over the backend's RAM (e.g. the 'prealloc' parameter of -memory-backend-ram lets you do memory preallocation). Obsessed 🫢

For compatibility reasons, the legacy 'mem' option is supported in 5.0 and older machine types. Note that 'mem' and 'memdev' are mutually exclusive β€” if one node uses 'memdev', the rest of the nodes have to use 'memdev' too, and vice versa. No mixing, periodt βœ‹

Users must specify memory for all NUMA nodes via 'memdev' (or legacy 'mem' if available). And heads up: in QEMU 5.2, the support for -numa node without memory specified was removed. 😭

'initiator' is an additional option that points to an initiator NUMA node that has the best performance (the lowest latency or largest bandwidth) to this NUMA node. Note that this option can only be set when the machine property 'hmat' is set to 'on'.

The following example creates a machine with 2 NUMA nodes: node 0 has CPU, node 1 has only memory, and its initiator is node 0. Note that because node 0 has CPU, by default the initiator of node 0 is itself and must be itself.

-machine hmat=on \
-m 2G,slots=2,maxmem=4G \
-object memory-backend-ram,size=1G,id=m0 \
-object memory-backend-ram,size=1G,id=m1 \
-numa node,nodeid=0,memdev=m0 \
-numa node,nodeid=1,memdev=m1,initiator=0 \
-smp 2,sockets=2,maxcpus=2  \
-numa cpu,node-id=0,socket-id=0 \
-numa cpu,node-id=0,socket-id=1

So, the distance stuff: source and destination are NUMA node IDs. distance is the NUMA distance from source to destination. The distance from a node to itself is always 10. If any pair of nodes is given a distance, then all pairs must be given distances. Although β€” when distances are only given in one direction for each pair of nodes, then the distances in the opposite directions are assumed to be the same. If, however, an asymmetrical pair of distances is given for even one node pair, then all node pairs must be provided distance values for both directions, even when they are symmetrical. And when a node is unreachable from another node, set the pair's distance to 255. πŸ’€

Note that the -numa option doesn't allocate any of the specified resources β€” it just assigns existing resources to NUMA nodes. Which means you still have to use the -m and -smp options to allocate RAM and VCPUs respectively. Don't forget, bestie πŸ™ˆ

Use 'hmat-lb' to set System Locality Latency and Bandwidth Information between initiator and target NUMA nodes in the ACPI Heterogeneous Attribute Memory Table (HMAT). An initiator NUMA node can create memory requests β€” usually it has one or more processors. The target NUMA node contains addressable memory.

In the 'hmat-lb' option, node are NUMA node IDs. hierarchy is the memory hierarchy of the target NUMA node: if hierarchy is 'memory', the structure represents the memory performance; if hierarchy is 'first-level|second-level|third-level', this structure represents aggregated performance of memory side caches for each domain. The type of 'data-type' is the type of data represented by this structure instance: if 'hierarchy' is 'memory', 'data-type' is 'access|read|write' latency or 'access|read|write' bandwidth of the target memory; if 'hierarchy' is 'first-level|second-level|third-level', 'data-type' is 'access|read|write' hit latency or 'access|read|write' hit bandwidth of the target memory side cache. ✨

lat is the latency value in nanoseconds. bw is the bandwidth value β€” the possible value and units are NUM[M|G|T], meaning the bandwidth value is NUM bytes per second (or MiB/s, GiB/s or TiB/s depending on the used suffix). Note that if the latency or bandwidth value is 0, that means the corresponding latency or bandwidth information is not provided.

In the 'hmat-cache' option, node-id is the NUMA-id of the memory it belongs to. size is the size of the memory side cache in bytes. level is the cache level described in this structure β€” note that cache level 0 should not be used with the 'hmat-cache' option. associativity is the cache associativity, possible values being 'none/direct(direct-mapped)/complex(complex cache indexing)'. policy is the write policy. line is the cache Line size in bytes. πŸŽ€

For example β€” the following options describe 2 NUMA nodes. Node 0 has 2 cpus and a ram, node 1 has only a ram. The processors in node 0 access memory in node 0 with access-latency 5 nanoseconds, access-bandwidth is 200 MiB/s; the processors in NUMA node 0 access memory in NUMA node 1 with access-latency 10 nanoseconds, access-bandwidth is 100 MiB/s. And for memory side cache information, NUMA node 0 and 1 both have 1 level memory cache, size is 10KiB, policy is write-back, the cache Line size is 8 bytes:

-machine hmat=on \
-m 2G \
-object memory-backend-ram,size=1G,id=m0 \
-object memory-backend-ram,size=1G,id=m1 \
-smp 2,sockets=2,maxcpus=2 \
-numa node,nodeid=0,memdev=m0 \
-numa node,nodeid=1,memdev=m1,initiator=0 \
-numa cpu,node-id=0,socket-id=0 \
-numa cpu,node-id=0,socket-id=1 \
-numa hmat-lb,initiator=0,target=0,hierarchy=memory,data-type=access-latency,latency=5 \
-numa hmat-lb,initiator=0,target=0,hierarchy=memory,data-type=access-bandwidth,bandwidth=200M \
-numa hmat-lb,initiator=0,target=1,hierarchy=memory,data-type=access-latency,latency=10 \
-numa hmat-lb,initiator=0,target=1,hierarchy=memory,data-type=access-bandwidth,bandwidth=100M \
-numa hmat-cache,node-id=0,size=10K,level=1,associativity=direct,policy=write-back,line=8 \
-numa hmat-cache,node-id=1,size=10K,level=1,associativity=direct,policy=write-back,line=8

🌸 -add-fd fd=fd,set=set[,opaque=opaque]

Add a file descriptor to an fd set. Valid options are:

  • fd=fd β€” this option defines the file descriptor of which a duplicate is added to the fd set. The file descriptor cannot be stdin, stdout, or stderr. 🚫
  • set=set β€” this option defines the ID of the fd set to add the file descriptor to.
  • opaque=opaque β€” this option defines a free-form string that can be used to describe the fd.

You can open an image using pre-opened file descriptors from an fd set, like so:

qemu-kvm \
 -add-fd fd=3,set=2,opaque="rdwr:/path/to/file" \
 -add-fd fd=4,set=2,opaque="rdonly:/path/to/file" \
 -drive file=/dev/fdset/2,index=0,media=disk

πŸ¦‹ -set group.id.arg=value

Set parameter arg for item id of type group.

πŸ’… -global driver.prop=value

πŸ’… -global driver=driver,property=property,value=value

Set the default value of driver's property prop to value, e.g.:

qemu-kvm -global ide-hd.physical_block_size=4096 disk-image.img

In particular, you can use this to set driver properties for devices which are created automatically by the machine model. To create a device which is not created automatically and set properties on it, use -device instead.

-global driver.prop=value is shorthand for -global driver=driver,property=prop,value=value. And the longhand syntax works even when driver contains a dot. πŸ’–


πŸŽ€ -boot [order=drives][,once=drives][,menu=on|off][,splash=sp_name][,splash-time=sp_time][,reboot-timeout=rb_timeout][,strict=on|off]

Specify the boot order drives as a string of drive letters. Valid drive letters depend on the target architecture. The x86 PC uses: a, b (floppy 1 and 2), c (first hard disk), d (first CD-ROM), n-p (Etherboot from network adapter 1-4) β€” and hard disk boot is the default. To apply a particular boot order only on the first startup, specify it via once. Note that the order or once parameter should not be used together with the bootindex property of devices, since the firmware implementations normally don't support both at the same time. 😭

Interactive boot menus/prompts can be enabled via menu=on, as far as firmware/BIOS supports them. The default is non-interactive boot.

A splash picture could be passed to the bios, letting the user show it as a logo, when the option splash=sp_name is given and menu=on β€” if firmware/BIOS supports them. Currently Seabios for X86 systems support it. Limitation: the splash file could be a jpeg file or a BMP file in 24 BPP format (true color). The resolution should be supported by the SVGA mode, so the recommended is 320x240, 640x480, 800x640. 🌈

A timeout could be passed to the bios β€” the guest will pause for rb_timeout ms when boot failed, then reboot. If rb_timeout is '-1', the guest will not reboot, and qemu passes '-1' to the bios by default. Currently Seabios for X86 systems support it.

Do strict boot via strict=on, as far as firmware/BIOS supports it. This only has an effect when boot priority is changed by bootindex options. The default is non-strict boot.

# try to boot from network first, then from hard disk
qemu-kvm -boot order=nc
# boot from CD-ROM first, switch back to default order after reboot
qemu-kvm -boot once=d
# boot with a splash picture for 5 seconds.
qemu-kvm -boot menu=on,splash=/root/boot.bmp,splash-time=5000
⚠️ Note: the legacy format -boot drives is still supported, but bestie, its use is discouraged β€” it may be yeeted from future versions. 😭 Consider this your warning.
  • -m [size=]megs[,slots=n,maxmem=size] β€” sets the guest's startup RAM to megs megabytes. Default is 128 MiB. You can optionally slap a M or G suffix on there to mean megabytes or gigabytes respectively. The optional slots + maxmem pair lets you set how many hotpluggable memory slots exist and the max amount of memory. Heads up: maxmem must be aligned to the page size. πŸ’…

For example, this command line sets guest startup RAM to 1GiB, makes 3 slots for hotplugging extra memory, and caps the max memory the guest can reach at 4GiB:

qemu-kvm -m 1G,slots=3,maxmem=4G

If you don't specify slots and maxmem, memory hotplug just won't be enabled and the guest startup RAM will never increase. Simple as that. ✨

  • -mem-path path β€” allocates guest RAM from a temporarily created file in path.
  • -mem-prealloc β€” preallocates memory when you're using -mem-path. 🫢
  • -k language β€” picks the keyboard layout language (like fr for French). You only need this where it's not easy to grab raw PC keycodes (think Macs, some X11 servers, or a VNC or curses display). On PC/Linux or PC/Windows hosts you normally don't need it at all, ngl.

The available layouts are:

ar  de-ch  es  fo     fr-ca  hu  ja  mk     no  pt-br  sv
da  en-gb  et  fr     fr-ch  is  lt  nl     pl  ru     th
de  en-us  fi  fr-be  hr     it  lv  nl-be  pt  sl     tr

The default is en-us. πŸŽ€

  • -audio [driver=]driver[,model=value][,prop=value[,...]] β€” okay so if you specify the model option, -audio is basically a shortcut for configuring both the guest audio hardware and the host audio backend in one go. You set the guest hardware model with model=modelname. Use model=help to list the available device types. πŸ‘‘

These two examples do exactly the same thing β€” they're here to show how -audio can shorten your command line:

qemu-kvm -audiodev pa,id=pa -device sb16,audiodev=pa
qemu-kvm -audio pa,model=sb16

If you don't specify the model option, -audio instead configures a default audio backend that gets used whenever the audiodev property isn't set on a device or machine. In particular, -audio none guarantees no audio is produced, even for machines with embedded sound hardware. πŸ¦‹

In both cases, the driver option is the same as with the corresponding -audiodev option below. Use driver=help to list the available drivers.

  • -audiodev [driver=]driver,id=id[,prop=value[,...]] β€” adds a new audio backend driver identified by id.

If no audio backend is specified, QEMU will attempt to select a default one. Lowkey the -display option may influence which backend gets picked. πŸ‘€

There are global and driver-specific properties. Some values can be set differently for input and output β€” those are marked with in|out.. You set the input's property with in.prop and the output's with out.prop. For example:

-audiodev alsa,id=example,in.frequency=44110,out.frequency=8000
-audiodev alsa,id=example,out.channels=1 # leaves in.channels unspecified
NOTE: parameter validation is known to be incomplete 😬 β€” in many cases specifying an invalid option causes QEMU to print an error message and just keep emulating without sound.

The valid global options are:

  • id=identifier β€” identifies the audio backend.
  • timer-period=period β€” sets the timer period used by the audio subsystem, in microseconds. Default is 10000 (10 ms).
  • in|out.mixing-engine=on|off β€” use QEMU's mixing engine to mix all streams inside QEMU and convert audio formats when the backend doesn't support them. When it's off, fixed-settings must be off too. Note that disabling this means the selected backend must support multiple streams and the audio formats used by the virtual cards β€” otherwise you get no sound, periodt. Not recommended to disable it unless you want 5.1 or 7.1 audio, since the mixing engine only supports mono and stereo. Default is on.
  • in|out.fixed-settings=on|off β€” use fixed settings for host audio. When off, it changes based on how the guest opens the sound card. In that case you must not specify frequency, channels or format. Default is on.
  • in|out.frequency=frequency β€” the frequency to use when using fixed-settings. Default is 44100Hz.
  • in|out.channels=channels β€” the number of channels to use when using fixed-settings. Default is 2 (stereo).
  • in|out.format=format β€” the sample format to use when using fixed-settings. Valid values are: s8, s16, s32, u8, u16, u32, f32. Default is s16.
  • in|out.voices=voices β€” the number of voices to use. Default is 1.
  • in|out.buffer-length=usecs β€” sets the size of the buffer in microseconds.
  • -audiodev none,id=id[,prop=value[,...]] β€” creates a dummy backend that discards all outputs. This backend has no backend-specific properties. πŸš«πŸ”Š
  • -audiodev alsa,id=id[,prop=value[,...]] β€” creates a backend using the ALSA. This backend is only available on Linux. 🐧

ALSA-specific options are:

  • in|out.dev=device β€” the ALSA device to use for input and/or output. Default is default.
  • in|out.period-length=usecs β€” sets the period length in microseconds.
  • in|out.try-poll=on|off β€” attempt to use poll mode with the device. Default is off.
  • threshold=threshold β€” threshold (in microseconds) for when playback starts. Default is 0.
  • -audiodev coreaudio,id=id[,prop=value[,...]] β€” creates a backend using Apple's Core Audio. Only available on Mac OS, and only supports playback. 🍎

Core Audio-specific options are:

  • in|out.buffer-count=count β€” sets the count of the buffers.
  • -audiodev dbus,id=id[,prop=value[,...]] β€” creates a D-Bus backend. It must be associated with the display (as -display dbus,audiodev=id). (Since 7.0) 🌈

D-Bus-specific options are:

  • nsamples β€” number of samples per read/write (defaults to 480, 10ms at 48kHz) (Since 10.0)
  • -audiodev dsound,id=id[,prop=value[,...]] β€” creates a backend using Microsoft's DirectSound. Only available on Windows, and only supports playback. πŸͺŸ

DirectSound-specific options are:

  • latency=usecs β€” adds an extra usecs microseconds of latency to playback. Default is 10000 (10 ms).
  • -audiodev oss,id=id[,prop=value[,...]] β€” creates a backend using OSS. Available on most Unix-like systems. 🐚

OSS-specific options are:

  • in|out.dev=device β€” the file name of the OSS device to use. Default is /dev/dsp.
  • in|out.buffer-count=count β€” sets the count of the buffers.
  • in|out.try-poll=on|off β€” attempt to use poll mode with the device. Default is on.
  • try-mmap=on|off β€” try using memory-mapped device access. Default is off.
  • exclusive=on|off β€” open the device in exclusive mode (vmix won't work in this case). Default is off.
  • dsp-policy=policy β€” sets the timing policy (between 0 and 10, where a smaller number means smaller latency but higher CPU usage). Use -1 to use the buffer sizes specified by buffer and buffer-count. This option is ignored if you don't have OSS 4. Default is 5.
  • -audiodev pa,id=id[,prop=value[,...]] β€” creates a backend using PulseAudio. Available on most systems. πŸ’œ

PulseAudio-specific options are:

  • server=server β€” the PulseAudio server to connect to.
  • in|out.name=sink β€” use the specified source/sink for recording/playback.
  • in|out.latency=usecs β€” desired latency in microseconds. The PulseAudio server will try to honor this value, but actual latencies may be lower or higher. πŸ™ƒ
  • -audiodev pipewire,id=id[,prop=value[,...]] β€” creates a backend using PipeWire. Available on most systems. 🧚

PipeWire-specific options are:

  • in|out.latency=usecs β€” desired latency in microseconds.
  • in|out.name=sink β€” use the specified source/sink for recording/playback.
  • in|out.stream-name β€” the name of the PipeWire stream.
  • -audiodev sdl,id=id[,prop=value[,...]] β€” creates a backend using SDL. Available on most systems, but you should use your platform's native backend if you can. πŸ’…

SDL-specific options are:

  • in|out.buffer-count=count β€” sets the count of the buffers.
  • -audiodev sndio,id=id[,prop=value[,...]] β€” creates a backend using SNDIO. Available on OpenBSD and most other Unix-like systems. 🐑

Sndio-specific options are:

  • in|out.dev=device β€” the sndio device to use for input and/or output. Default is default.
  • in|out.latency=usecs β€” sets the desired period length in microseconds.
  • -audiodev spice,id=id[,prop=value[,...]] β€” creates a backend that sends audio through SPICE. This backend requires -spice and is automatically selected in that case, so usually you can just ignore this option. It has no backend-specific properties. ✨
  • -audiodev wav,id=id[,prop=value[,...]] β€” creates a backend that writes audio to a WAV file. 🎧

Backend-specific options are:

  • path=path β€” write recorded audio into the specified file. Default is qemu.wav.
  • -device driver[,prop=value[,...]] β€” okay so this is how you add a device driver. prop=value sets driver properties, and valid properties depend on the driver. Need help? run -device help and -device driver,help to see possible drivers and properties. ✨

Some drivers are:

  • -device ipmi-bmc-sim,id=id[,prop=value[,...]] β€” add an IPMI BMC. This is a simulation of a hardware management interface processor that normally sits on a system. It provides a watchdog and the ability to reset and power control the system. You need to connect this to an IPMI interface to make it useful. πŸ’…

The IPMI slave address to use for the BMC. The default is 0x20. This address is the BMC's address on the I2C network of management controllers. If you don't know what this means, it is safe to ignore it.

  • id=id β€” the BMC id for interfaces to use this device.
  • slave_addr=val β€” define the slave address to use for the BMC. The default is 0x20.
  • sdrfile=file β€” file containing raw Sensor Data Records (SDR) data. The default is none.
  • fruareasize=val β€” size of a Field Replaceable Unit (FRU) area. The default is 1024.
  • frudatafile=file β€” file containing raw Field Replaceable Unit (FRU) inventory data. The default is none.
  • guid=uuid β€” value for the GUID for the BMC, in standard UUID format. If this is set, the "Get GUID" command to the BMC will return it. Otherwise "Get GUID" will return an error.
  • lan.channel=val β€” channel number of the fake LAN channel. It can be 0 or any integer from 0x1 to 0xb inclusive. If set to 0, the LAN channel is disabled; otherwise the LAN channel is enabled at the specified channel number. The default is 0.
  • lan.ipaddr=addr β€” the ipv4 address of the BMC LAN channel.
  • lan.ipsrc=val β€” the ipv4 address source of the BMC LAN channel. It can be 0 (unspecified source), 1 (static address), 2 (DHCP), 3 (BIOS or system software), or 4 (other source). The default is 0.
  • lan.macaddr=mac β€” the mac address of the BMC LAN channel.
  • lan.netmask=mask β€” the ipv4 subnet mask for the BMC LAN channel.
  • lan.defgw_ipaddr=addr β€” the default gateway ipv4 address for the BMC LAN channel.
  • lan.defgw_macaddr=mac β€” the default gateway mac address for the BMC LAN channel.
  • -device ipmi-bmc-extern,id=id,chardev=id[,slave_addr=val] β€” add a connection to an external IPMI BMC simulator. Instead of locally emulating the BMC like the item above, you connect out to an external entity that provides the IPMI services. 🫢

A connection is made to an external BMC simulator. If you do this, it is strongly recommended that you use the reconnect-ms= chardev option to reconnect to the simulator if the connection is lost.

⚠️ Security tea: if this is not used carefully, it can be a security issue, as the interface has the ability to send resets, NMIs, and power off the VM. It's best if QEMU makes a connection to an external simulator running on a secure port on localhost, so neither the simulator nor QEMU is exposed to any outside network.

See the lanserv/README.vm file in the OpenIPMI library for more details on the external interface.

  • -device isa-ipmi-kcs,bmc=id[,ioport=val][,irq=val] β€” add a KCS IPMI interface on the ISA bus. This also adds corresponding ACPI and SMBIOS entries, if appropriate. ✨
    • bmc=id β€” the BMC to connect to, one of ipmi-bmc-sim or ipmi-bmc-extern above.
    • ioport=val β€” define the I/O address of the interface. The default is 0xca0 for KCS.
    • irq=val β€” define the interrupt to use. The default is 5. To disable interrupts, set this to 0.
  • -device isa-ipmi-bt,bmc=id[,ioport=val][,irq=val] β€” like the KCS interface, but defines a BT interface. The default port is 0xe4 and the default interrupt is 5. πŸŽ€
  • -device pci-ipmi-kcs,bmc=id β€” add a KCS IPMI interface on the PCI bus.
    • bmc=id β€” the BMC to connect to, one of ipmi-bmc-sim or ipmi-bmc-extern above.
  • -device pci-ipmi-bt,bmc=id β€” like the KCS interface, but defines a BT interface on the PCI bus. πŸ’…
  • -device intel-iommu[,option=...] β€” this is only supported by -machine q35, which will enable Intel VT-d emulation within the guest. It supports the options below: πŸ”₯
    • intremap=on|off (default: auto) β€” enables the interrupt remapping feature. It's required to enable complete x2apic. Currently it only supports kvm kernel-irqchip modes off or split, while full kernel-irqchip is not yet supported. The default value is "auto", which will be decided by the mode of kernel-irqchip.
    • caching-mode=on|off (default: off) β€” enables caching mode for the VT-d emulated device. When caching-mode is enabled, each guest DMA buffer mapping will generate an IOTLB invalidation from the guest IOMMU driver to the vIOMMU device in a synchronous way. It is required for -device vfio-pci to work with the VT-d device, because host-assigned devices need the DMA mapping set up on the host before guest DMA starts.
    • device-iotlb=on|off (default: off) β€” enables device-iotlb capability for the emulated VT-d device. So far virtio/vhost should be the only real user for this parameter, paired with ats=on configured for the device.
    • aw-bits=39|48 (default: 39) β€” this decides the address width of the IOVA address space. The address space has 39 bits width for 3-level IOMMU page tables, and 48 bits for 4-level IOMMU page tables.

Please also refer to the wiki page for general scenarios of VT-d emulation in QEMU: https://wiki.qemu.org/Features/VT-d.

  • -device virtio-iommu-pci[,option=...] β€” this is only supported by -machine q35 (x86_64) and -machine virt (ARM). It supports the options below: 🌸
    • granule=val β€” possible values are 4k, 8k, 16k, 64k and host; default: host. This decides the default granule to be exposed by the virtio-iommu. If host, the granule matches the host page size.
    • aw-bits=val β€” val between 32 and 64, default depends on machine. This decides the address width of the IOVA address space.
  • -device arm-smmuv3,primary-bus=id[,option=...] β€” this is only supported by -machine virt (ARM). πŸ¦‹
    • primary-bus=id β€” accepts either the default root complex (pcie.0) or a pxb-pcie based root complex.
    • accel=on|off (default: off) β€” enables the guest to leverage host SMMUv3 features for acceleration. Enabling accel configures the host SMMUv3 in nested mode to support vfio-pci passthrough.

The following options will be set to auto by default if not manually set. When accel=on and these properties are set to auto, the value is derived from the host SMMUv3 capabilities via IOMMU_GET_HW_INFO. With accel=on, this requires at least one cold-plugged vfio-pci device; if none is present at machine init, QEMU will abort.

If accel=off, auto values resolve to the non-accel defaults given below.

  • ril=on|off|auto (default: auto) β€” support for Range Invalidation, which allows the SMMUv3 driver to invalidate TLB entries for a range of IOVAs at once instead of issuing separate commands to invalidate each page. Must match with host SMMUv3 Range Invalidation support.
    • With accel=off, auto is resolved to 'on'.
  • ats=on|off|auto (default: auto) β€” support for Address Translation Services, which enables PCIe devices to cache address translations in their local TLB and reduce latency. Host SMMUv3 must support ATS in order to enable this feature for the vIOMMU.
    • With accel=off, auto is resolved to 'off'.
  • oas=val|auto (supported values are 44 and 48; default: auto) β€” sets the Output Address Size in bits. The value set here must be less than or equal to the host SMMUv3's supported OAS, so that the intermediate physical addresses (IPA) consumed by host SMMU for stage-2 translation do not exceed the host's max supported IPA size.
    • With accel=off, auto is resolved to 44.
  • ssidsize=val|auto (val between 0 and 20; default: auto) β€” sets the Substream ID size in bits. When set to a non-zero value, PASID capability is advertised to the vIOMMU and accelerated use cases such as Shared Virtual Addressing (SVA) are supported.
    • With accel=off, auto is resolved to 0.
  • cmdqv=on|off|auto (default: auto) β€” enable hardware Command Queue Virtualization (CMDQV) for the SMMUv3 command queue. Currently only the NVIDIA Tegra241 CMDQV implementation is supported.
    • With accel=on, auto means the value is automatically derived from the host SMMU.
    • With accel=off, auto is resolved to 'off'.
  • -device amd-iommu[,option=...] β€” enables emulation of an AMD-Vi I/O Memory Management Unit (IOMMU). Only available with -machine q35, it supports the following options: πŸ’œ
    • dma-remap=on|off (default: off) β€” support for DMA address translation and access permission checking for guests attaching passthrough devices to paging domains, using the AMD v1 I/O Page Table format. This enables -device vfio-pci,... to work correctly with a guest using the DMA remapping feature of the vIOMMU.
  • intremap=on|off (default: auto) β€” this is the generic x86 IOMMU glow-up that the amd-iommu device serves πŸ’… it turns on interrupt remapping for guests, which is also lowkey required to enable x2apic support. rn it's only available with kernel-irqchip=off|split, and it auto-enables when either of those modes is in use, then disables itself when kernel-irqchip=on. it's giving automatic bestie behavior ✨
  • xtsup=on|off (default: off) β€” makes the interrupt remapping table support x2apic mode, so the guest can use the 128-bit IRTE format with a 32-bit destination field. required if you wanna route interrupts to vCPUs with APIC IDs bigger than 0xff. no cap, that's a big ID 🫢

-name name β€” sets the name of the guest, bestie πŸŽ€ this name shows up in the SDL window caption and is also used for the VNC server. it can optionally set the top visible process name on Linux too. and on Linux you can also enable naming of individual threads to help with debugging. iconic multitasking behavior πŸ’…

-uuid uuid β€” sets the system UUID. simple as that, periodt ✨

🧊 Block device options 🧊

okay so the QEMU block device handling options have a long history and have gone through several iterations as the feature set and complexity of the block layer have grown 😭 many online guides to QEMU reference older and deprecated options, which is lowkey confusing af.

the most explicit way to describe disks is to use a combo of -device for the hardware device and -blockdev for the backend. the device defines what the guest sees, and the backend describes how QEMU handles the data. it's the only guaranteed stable interface for describing block devices, so it's the recommended one for management tools and scripting. main character energy fr fr πŸ‘‘

the -drive option combines the device and backend into a single command line option, which is more human friendly. but there's no interface stability guarantee, although some older board models still need updating to work with the modern blockdev forms. it's giving legacy vibes ngl πŸ™ˆ

older options like -hda are basically macros that expand into -drive options for various drive interfaces. the original forms bake in a lot of assumptions from back when QEMU was emulating a legacy PC, so they're not recommended for modern configurations. we don't stan legacy assumptions here πŸ’€

  • -fda file
  • -fdb file β€” use file as floppy disk 0/1 image (see the Disk Images chapter in the System Emulation Users Guide). cute and retro πŸŽ€
  • -hda file
  • -hdb file
  • -hdc file
  • -hdd file β€” use file as hard disk 0, 1, 2 or 3 image on the default bus of the emulated machine. this is for example the IDE bus on most x86 machines, but it can also be SCSI, virtio or something else on other target architectures. see also the Disk Images chapter in the System Emulation Users Guide. classic bus behavior ✨
  • -cdrom file β€” use file as CD-ROM image on the default bus of the emulated machine (which is IDE1 master on x86, so you literally cannot use -hdc and -cdrom at the same time there 😭). on systems that support it, you can use the host CD-ROM by using /dev/cdrom as the filename. cute πŸ’Ώ
  • -blockdev option[,option[,option[,...]]] β€” define a new block driver node. some options apply to all block drivers, others are only accepted for a specific block driver. see below for the generic options and options for the most common block drivers. this is the big one, bestie πŸ‘‘

options that expect a reference to another node (e.g. file) can be given in two ways. either you specify the node name of an already existing node (file=node-name), or you define a new node inline by adding options for the referenced node after a dot (file.filename=path,file.aio=native). it's giving choose-your-own-adventure πŸ¦‹

a block driver node created with -blockdev can be used for a guest device by specifying its node name for the drive property in a -device argument that defines a block device. slay ✨

valid options for any block driver node:

  • driver β€” specifies the block driver to use for the given node.
  • node-name β€” defines the name of the block driver node by which it will be referenced later. the name must be unique, i.e. it must not match the name of a different block driver node, or (if you use -drive as well) the ID of a drive. if no node name is specified, it's automatically generated. the generated node name is not intended to be predictable and changes between QEMU invocations. for the top level, an explicit node name must be specified. no slacking on top-level names, bestie πŸ’…
  • read-only β€” open the node read-only. guest write attempts will fail. note that some block drivers support only read-only access, either generally or in certain configurations. in this case, the default value read-only=off doesn't work and the option must be specified explicitly. rude but valid πŸ™ˆ
  • auto-read-only β€” if auto-read-only=on is set, QEMU may fall back to read-only usage even when read-only=off is requested, or even switch between modes as needed, e.g. depending on whether the image file is writable or whether a writing user is attached to the node. flexible queen 🌸
  • force-share β€” override the image locking system of QEMU by forcing the node to utilize weaker shared access for permissions where it would normally request exclusive access. when there's the potential for multiple instances to have the same file open (whether this invocation of QEMU is the first or the second instance), both instances must permit shared access for the second instance to succeed at opening the file. enabling force-share=on requires read-only=on. sharing is caring but read the fine print 🫢
  • cache.direct β€” the host page cache can be avoided with cache.direct=on. this will attempt to do disk IO directly to the guest's memory. QEMU may still perform an internal copy of the data. direct is giving efficient ✨
  • cache.no-flush β€” in case you don't care about data integrity over host failures, you can use cache.no-flush=on. this option tells QEMU that it never needs to write any data to the disk but can instead keep things in cache. if anything goes wrong, like your host losing power, the disk storage getting disconnected accidentally, etc. your image will most probably be rendered unusable. πŸ˜­πŸ’€ bestie please be careful with this one, fr fr
  • discard=discard β€” discard is one of "ignore" (or "off") or "unmap" (or "on") and controls whether discard (also known as trim or unmap) requests are ignored or passed to the filesystem. some machine types may not support discard requests. know your limits ig πŸ’…
  • detect-zeroes=detect-zeroes β€” detect-zeroes is "off", "on" or "unmap" and enables the automatic conversion of plain zero writes by the OS to driver specific optimized zero write commands. you may even choose "unmap" if discard is set to "unmap" to allow a zero write to be converted to an unmap operation. optimized zero writes are so iconic ✨

πŸ—‚οΈ Driver-specific options for file πŸ—‚οΈ

this is the protocol-level block driver for accessing regular files.

  • filename β€” the path to the image file in the local filesystem.
  • aio β€” specifies the AIO backend (threads/native/io_uring, default: threads).
  • locking β€” specifies whether the image file is protected with Linux OFD / POSIX locks. the default is to use the Linux Open File Descriptor API if available, otherwise no lock is applied. (auto/on/off, default: auto).

example:

-blockdev driver=file,node-name=disk,filename=disk.img

🧱 Driver-specific options for raw 🧱

this is the image format block driver for raw images. it's usually stacked on top of a protocol level block driver such as file.

  • file β€” reference to or definition of the data source block driver node (e.g. a file driver node).

example 1:

-blockdev driver=file,node-name=disk_file,filename=disk.img
-blockdev driver=raw,node-name=disk,file=disk_file

example 2:

-blockdev driver=raw,node-name=disk,file.driver=file,file.filename=disk.img

🧚 Driver-specific options for qcow2 🧚

this is the image format block driver for qcow2 images. it's usually stacked on top of a protocol level block driver such as file.

  • file β€” reference to or definition of the data source block driver node (e.g. a file driver node).
  • backing β€” reference to or definition of the backing file block device (default is taken from the image file). it's allowed to pass null here in order to disable the default backing file. bold move but ok πŸ’…
  • lazy-refcounts β€” whether to enable the lazy refcounts feature (on/off; default is taken from the image file).
  • cache-size β€” the maximum total size of the L2 table and refcount block caches in bytes (default: the sum of l2-cache-size and refcount-cache-size). big cache energy 🌸

l2-cache-size ✨

The max size of the L2 table cache, in bytes fr. Default goes like this: if cache-size isn't specified, it's 32M on Linux platforms and 8M on non-Linux platforms. Otherwise it's as large as possible inside the cache-size, while still permitting the requested or the minimal refcount cache size. πŸ’…

refcount-cache-size πŸŽ€

The max size of the refcount block cache, in bytes. Default is 4 times the cluster size; or, if cache-size is specified, it's the part of it that isn't used for the L2 cache. πŸ¦‹

cache-clean-interval 🧚

Cleans unused entries in the L2 and refcount caches. The interval is in seconds, bestie. Default is 600 on supporting platforms, and 0 on other platforms. Setting it to 0 disables the feature entirely β€” no cap. 🌸

pass-discard-request πŸ”₯

Whether discard requests to the qcow2 device should get forwarded to the data source (on/off; default: on if discard=unmap is specified, off otherwise). πŸ‘‘

pass-discard-snapshot 🌈

Whether discard requests for the data source should be issued when a snapshot operation (like deleting a snapshot, iykyk) frees clusters in the qcow2 file (on/off; default: on). ✨

pass-discard-other πŸ’œ

Whether discard requests for the data source should be issued on other occasions where a cluster gets freed (on/off; default: off). πŸ™ˆ

discard-no-unref πŸ’€

When enabled, data clusters stay preallocated when they're no longer used β€” like, because they got discarded or converted to zero clusters. As usual, whether the old data is discarded or kept on the protocol level (i.e. in the image file) depends on the setting of the pass-discard-request option.

Keeping the clusters preallocated prevents qcow2 fragmentation that would otherwise be caused by freeing and re-allocating them later. And ngl, besides potential performance degradation, that kind of fragmentation can lead to increased allocation of clusters past the end of the image file β€” resulting in image files whose file length can grow much larger than their guest disk size would suggest. 😭 So if image file length is of concern (e.g. when storing qcow2 images directly on block devices), you should seriously consider enabling this option. 🫢

overlap-check ⭐

Which overlap checks to perform for writes to the image (none/constant/cached/all; default: cached). For details or finer granularity control, refer to the QAPI documentation of blockdev-add. πŸ“š

Example 1: 🌟

-blockdev driver=file,node-name=my_file,filename=/tmp/disk.qcow2
-blockdev driver=qcow2,node-name=hda,file=my_file,overlap-check=none,cache-size=16777216

Example 2: πŸ’–

-blockdev driver=qcow2,node-name=disk,file.driver=http,file.filename=http://example.com/image.qcow2

Driver-specific options for other drivers 🌸

Please refer to the QAPI documentation of the blockdev-add QMP command. That's it, that's the whole vibe. πŸ’…


-drive option[,option[,option[,...]]] πŸš—

Okay so this one defines a new drive. It includes creating a block driver node (that's the backend) and a guest device, so it's basically a shortcut for defining the corresponding -blockdev and -device options. Iconic, honestly. ✨

-drive accepts all the options that -blockdev accepts. On top of that, it knows the following:

  • file=file β€” this defines which disk image to use with this drive (see the Disk Images chapter in the System Emulation Users Guide). Heads up: if the filename contains a comma, you gotta double it β€” for instance, "file=my,,file" to use the file "my,file". πŸ“

Special files such as iSCSI devices can be specified using protocol specific URLs. See the section for "Device URL Syntax" for more info.

  • if=interface β€” defines which type of interface the drive is connected to. Available types are: ide, scsi, sd, mtd, floppy, pflash, virtio, none. πŸ”Œ
  • bus=bus,unit=unit β€” these define where the drive is connected by defining the bus number and the unit id. 🚌
  • index=index β€” defines where the drive is connected by using an index in the list of available connectors of a given interface type. πŸ”’
  • media=media β€” defines the type of media: disk or cdrom. πŸ’Ώ
  • snapshot=snapshot β€” snapshot is "on" or "off" and controls snapshot mode for the given drive (see -snapshot). πŸ“Έ
  • cache=cache β€” cache is "none", "writeback", "unsafe", "directsync" or "writethrough" and controls how the host cache is used to access block data. This is a shortcut that sets the cache.direct and cache.no-flush options (as in -blockdev), and additionally cache.writeback, which provides a default for the write-cache option of block guest devices (as in -device). The modes correspond to the following settings: ⚑
    • writeback β†’ cache.writeback = on, cache.direct = off, cache.no-flush = off
    • none β†’ cache.writeback = on, cache.direct = on, cache.no-flush = off
    • writethrough β†’ cache.writeback = off, cache.direct = off, cache.no-flush = off
    • directsync β†’ cache.writeback = off, cache.direct = on, cache.no-flush = off
    • unsafe β†’ cache.writeback = on, cache.direct = off, cache.no-flush = on

The default mode is cache=writeback. πŸŽ€

  • aio=aio β€” aio is "threads", "native", or "io_uring" and selects between pthread based disk I/O, native Linux AIO, or the Linux io_uring API. 🧡
  • format=format β€” specify which disk format will be used rather than detecting the format. You can use it to specify format=raw to avoid interpreting an untrusted format header. πŸ›‘οΈ
  • werror=action,rerror=action β€” specify which action to take on write and read errors. Valid actions are: "ignore" (ignore the error and try to continue), "stop" (pause QEMU), "report" (report the error to the guest), "enospc" (pause QEMU only if the host disk is full; report the error to the guest otherwise). The default setting is werror=enospc and rerror=report. 🚨
  • copy-on-read=copy-on-read β€” copy-on-read is "on" or "off" and enables whether to copy read backing file sectors into the image file. πŸ“–
  • bps=b,bps_rd=r,bps_wr=w β€” specify bandwidth throttling limits in bytes per second, either for all request types or for reads or writes only. Small values can lead to timeouts or hangs inside the guest, so a safe minimum for disks is 2 MiB/s. 🐒
  • bps_max=bm,bps_rd_max=rm,bps_wr_max=wm β€” specify bursts in bytes per second, either for all request types or for reads or writes only. Bursts allow the guest I/O to spike above the limit temporarily. πŸš€
  • iops=i,iops_rd=r,iops_wr=w β€” specify request rate limits in requests per second, either for all request types or for reads or writes only. πŸ“Š
  • iops_max=bm,iops_rd_max=rm,iops_wr_max=wm β€” specify bursts in requests per second, either for all request types or for reads or writes only. Bursts allow the guest I/O to spike above the limit temporarily, periodt. πŸ’₯
  • iops_size=is β€” let every is bytes of a request count as a new request for iops throttling purposes. Use this option so guests can't circumvent iops limits by sending fewer but larger requests. Sneaky little guests, honestly. πŸ™ˆ
  • group=g β€” join a throttling quota group with given name g. All drives that are members of the same group are accounted for together. Use this option to prevent guests from circumventing throttling limits by using many small disks instead of a single larger disk. πŸ‘―β€β™€οΈ

And the default cache vibe? By default, cache.writeback=on is what you get. What that means: QEMU reports data writes as completed the second the data shows up in the host page cache. It's safe β€” as long as your guest OS is out here correctly flushing disk caches where it needs to. But if your guest OS does not handle volatile disk write caches correctly, and your host crashes or loses power? Yeah. Your guest may experience data corruption. 😭 Not cute. At. All.

So if you've got one of those guests, pls consider cache.writeback=off. That means the host page cache is still used to read and write data, but the write notification only goes to the guest after QEMU has made sure to flush each write to the disk. Heads up though: this has a major impact on performance. Like, major major. πŸ’€

Oh and when you're using the -snapshot option? Unsafe caching is always used. Always. 😌

Copy-on-read avoids accessing the same backing file sectors over and over and over, and it's genuinely useful when the backing file lives over a slow network. By default copy-on-read is off.

Instead of -cdrom you can use:

qemu-kvm -drive file=file,index=2,media=cdrom

Instead of -hda, -hdb, -hdc, -hdd, you can use:

qemu-kvm -drive file=file,index=0,media=disk
qemu-kvm -drive file=file,index=1,media=disk
qemu-kvm -drive file=file,index=2,media=disk
qemu-kvm -drive file=file,index=3,media=disk

You can open an image using pre-opened file descriptors from an fd set β€” bestie this one is iconic:

qemu-kvm \
 -add-fd fd=3,set=2,opaque="rdwr:/path/to/file" \
 -add-fd fd=4,set=2,opaque="rdonly:/path/to/file" \
 -drive file=/dev/fdset/2,index=0,media=disk

You can connect a CDROM to the slave of ide0:

qemu-kvm -drive file=file,if=ide,index=1,media=cdrom

If you don't specify the "file=" argument, you define an empty drive:

qemu-kvm -drive if=ide,index=1,media=cdrom

Instead of -fda, -fdb, you can use:

qemu-kvm -drive file=file,index=0,if=floppy
qemu-kvm -drive file=file,index=1,if=floppy

By default, interface is "ide" and index is automatically incremented:

qemu-kvm -drive file=a -drive file=b

which is interpreted like:

qemu-kvm -hda a -hdb b

  • -mtdblock file β€” use file as an on-board Flash memory image. 🫢
  • -sd file β€” use file as a SecureDigital card image. πŸ’Ύβœ¨
  • -snapshot β€” write to temporary files instead of disk image files. In this case the raw disk image you use is not written back. You can, however, force the write back by pressing C-a s (see the Disk Images chapter in the System Emulation Users Guide). πŸŽ€
WARNING: 🚨 snapshot is incompatible with -blockdev β€” instead, use qemu-img to manually create snapshot images to attach to your blockdev. If you have mixed -blockdev and -drive declarations, you can use the 'snapshot' property on your drive declarations instead of this global option.
  • -fsdev local,id=id,path=path,security_model=security_model[,writeout=writeout][,readonly=on][,fmode=fmode][,dmode=dmode][,max_xattr=max][,throttling.option=value[,throttling.option=value[,...]]]
  • -fsdev synth,id=id[,readonly=on][,max_xattr=max] β€” define a new file system device. πŸ’œ Valid options are:
    • local β€” accesses to the filesystem are done by QEMU.
    • synth β€” synthetic filesystem, only used by QTests.
    • id=id β€” specifies the identifier for this device.
    • path=path β€” specifies the export path for the file system device. Files under this path will be available to the 9p client on the guest.
    • security_model=security_model β€” specifies the security model to be used for this export path. The supported security models are "passthrough", "mapped-xattr", "mapped-file" and "none". In the "passthrough" security model, files are stored using the same credentials as they are created on the guest β€” and that requires QEMU to run as root. 😳 In the "mapped-xattr" security model, some of the file attributes like uid, gid, mode bits and link target are stored as file attributes. For "mapped-file" these attributes are stored in the hidden .virtfs_metadata directory. Directories exported by this security model cannot interact with other unix tools. The "none" security model is the same as passthrough except the server won't report failures if it fails to set file attributes like ownership. Security model is mandatory only for the local fsdriver.
    • writeout=writeout β€” optional argument, bestie. The only supported value is "immediate". This means the host page cache will be used to read and write data, but the write notification will be sent to the guest only when the data has been reported as written by the storage subsystem.
    • readonly=on β€” enables exporting the 9p share as a readonly mount for guests. By default, read-write access is given.
    • fmode=fmode β€” specifies the default mode for newly created files on the host. Works only with the security models "mapped-xattr" and "mapped-file".
    • dmode=dmode β€” specifies the default mode for newly created directories on the host. Works only with the security models "mapped-xattr" and "mapped-file".
    • throttling.bps-total=b,throttling.bps-read=r,throttling.bps-write=w β€” specify bandwidth throttling limits in bytes per second, either for all request types or for reads or writes only.
    • throttling.bps-total-max=bm,bps-read-max=rm,bps-write-max=wm β€” specify bursts in bytes per second, either for all request types or for reads or writes only. Bursts let the guest I/O spike above the limit temporarily.
    • throttling.iops-total=i,throttling.iops-read=r,throttling.iops-write=w β€” specify request rate limits in requests per second, either for all request types or for reads or writes only.
    • throttling.iops-total-max=im,throttling.iops-read-max=irm,throttling.iops-write-max=iwm β€” specify bursts in requests per second, either for all request types or for reads or writes only. Bursts let the guest I/O spike above the limit temporarily.
    • throttling.iops-size=is β€” let every is bytes of a request count as a new request for iops throttling purposes.
    • max_xattr=max β€” specifies the maximum number of concurrent xattr FIDs allowed for this export. The default is 1024. Set to 0 to allow an infinite number of xattr FIDs. This limit prevents host memory exhaustion attacks by capping the number of simultaneous xattr FIDs. πŸ”₯

Also, the -fsdev option is used along with the -device driver "virtio-9p-...". They're a package deal, iykyk.

  • -device virtio-9p-type,fsdev=id,mount_tag=mount_tag β€” options for the virtio-9p-... driver are:
    • type β€” specifies the variant to be used. Supported values are "pci", "ccw" or "device", depending on the machine type.
    • fsdev=id β€” specifies the id value specified along with the -fsdev option.
    • mount_tag=mount_tag β€” specifies the tag name to be used by the guest to mount this export point.
  • -virtfs local,path=path,mount_tag=mount_tag,security_model=security_model[,writeout=writeout][,readonly=on][,fmode=fmode][,dmode=dmode][,multidevs=multidevs][,max_xattr=max]
  • -virtfs synth,mount_tag=mount_tag[,max_xattr=max] β€” define a new virtual filesystem device and expose it to the guest using a virtio-9p-device (a.k.a. 9pfs). Essentially that means a certain directory on the host is made directly accessible by the guest as a pass-through file system, using the 9P network protocol for communication between host and guests β€” and if you want, it can even be accessible, and shared, by several guests at the same time. 🌈

Note that -virtfs is actually just a convenience shortcut for its generalized form -fsdev -device virtio-9p-pci. ✨

The general form of pass-through file system options are:

  • local β€” accesses to the filesystem are done by QEMU.
  • synth β€” synthetic filesystem, only used by QTests.
  • id=id β€” specifies the identifier for the filesystem device.
  • path=path β€” specifies the export path for the file system device. Files under this path will be available to the 9p client on the guest.
  • security_model=security_model β€” specifies the security model to be used for this export path. The supported security models are "passthrough", "mapped-xattr", "mapped-file" and "none". In the "passthrough" security model, files are stored using the same credentials as they are created on the guest β€” which requires QEMU to run as root. 😳 In the "mapped-xattr" security model, some of the file attributes like uid, gid, mode bits and link target are stored as file attributes. For "mapped-file" these attributes are stored in the hidden .virtfs_metadata directory. Directories exported by this security model cannot interact with other unix tools. The "none" security model is the same as passthrough except the server won't report failures if it fails to set file attributes like ownership. Security model is mandatory only for the local fsdriver.
  • writeout=writeout β€” optional argument. The only supported value is "immediate". This means the host page cache will be used to read and write data, but the write notification will be sent to the guest only when the data has been reported as written by the storage subsystem.
  • readonly=on β€” enables exporting the 9p share as a readonly mount for guests. By default, read-write access is given.
  • fmode=fmode β€” specifies the default mode for newly created files on the host. Works only with the security models "mapped-xattr" and "mapped-file".
  • dmode=dmode β€” sets the default mode for directories that get newly created on the host. πŸ’… Ngl this one only works with the security models "mapped-xattr" and "mapped-file", so if you're using anything else it's just gonna sit there doing nothing.
  • mount_tag=mount_tag β€” the tag name your guest uses to mount this export point. It's literally the label on the door πŸšͺ✨
  • max_xattr=max β€” caps how many concurrent xattr FIDs this export is allowed to have. Default is 1024. Set it to 0 and you get infinite xattr FIDs. Why does this exist? Because it prevents host memory exhaustion attacks by capping the number of simultaneous xattr FIDs β€” so like, it's a bouncer for your RAM 🫢
  • multidevs=remap|forbid|warn β€” tells QEMU how to deal with multiple devices being shared through the same 9p export, all so you don't get file ID collisions on the guest. The supported behaviours are "remap" (the default), "forbid", or "warn".
    • remap β€” assumes there's a real possibility that more than one device is shared with the same 9p export, so inode numbers from the host get remapped for the guest in a way that prevents file ID collisions. Remapping in these cases is required because the original device IDs from the host are never passed along and exposed on the guest β€” instead, all files of an export shared with virtfs always share the same device ID on the guest. So two files with identical inode numbers but from actually different devices on the host would otherwise cause a file ID collision, and hence potential severe misbehaviours on the guest. 😭
    • warn β€” virtfs 9p expects only one device to be shared with the same export. If more than one device is shared and accessed via the same 9p export, then only a warning message gets logged (once) by qemu on the host side. No further action is performed to prevent file ID collisions on the guest. This could therefore lead to severe misbehaviours, like wrong files being accessed and data corruption on the exported tree. πŸ’€ Not the vibe.
    • forbid β€” assumes, like "warn", that only one device is shared by the same 9p export, but it will not only log a warning message, it'll also deny access to additional devices on the guest. Note though: "forbid" does currently not block all possible file access operations (e.g. readdir() would still return entries from other devices). πŸ™ˆ
  • -iscsi β€” configure iSCSI session parameters.

πŸ”Œ USB convenience options

  • -usb β€” enables USB emulation on machine types that have an on-board USB host controller (if it's not already enabled by default). Heads up: on-board USB host controllers may not support USB 3.0 β€” in that case you can use -device qemu-xhci instead, on machines with PCI. πŸ¦‹
  • -usbdevice devname β€” adds the USB device devname, and enables an on-board USB controller if that's possible and necessary (just like you can do it via -machine usb=on). Note that this option is mainly intended for the user's convenience only β€” more fine-grained control can be achieved by selecting a USB host controller (if necessary) and the desired USB device via the -device option instead. For example, instead of using -usbdevice mouse it's possible to use -device qemu-xhci -device usb-mouse to connect the USB mouse to a USB 3.0 controller instead (at least on machines that support PCI and don't have a USB controller enabled by default yet). For more details, see the chapter about Connecting USB devices in the System Emulation Users Guide. πŸ“–

Possible devices for devname are:

  • braille β€” braille device. This will use BrlAPI to display the braille output on a real or fake device (i.e. it also creates a corresponding braille chardev automatically beside the usb-braille USB device). 🫢
  • keyboard β€” standard USB keyboard. Will override the PS/2 keyboard (if present).
  • mouse β€” virtual mouse. This will override the PS/2 mouse emulation when activated. 🐭
  • tablet β€” pointer device that uses absolute coordinates (like a touchscreen). This means QEMU is able to report the mouse position without having to grab the mouse. Also overrides the PS/2 mouse emulation when activated. Iconic behaviour honestly.
  • wacom-tablet β€” Wacom PenPartner USB tablet. ✍️

πŸ–₯️ Display options

  • -display type β€” picks the type of display to use. This may also influence the default audio backend selection, so it's lowkey doing two jobs. πŸ‘‘

Use -display help to list the available display types. Valid values for type are:

  • spice-app[,gl=on|off] β€” starts QEMU as a Spice server and launches the default Spice client application. The Spice server will redirect the serial consoles and QEMU monitors. (Since 4.0)
  • dbus β€” exports the display over D-Bus interfaces. (Since 7.0) πŸ’…

If no audio backend is specified and the dbus display backend is specified, the dbus audio backend is used by default.

The connection is registered with the "org.qemu" name (and queued when already owned).

  • addr=<dbusaddr> β€” D-Bus bus address to connect to.
  • p2p=yes|no β€” use peer-to-peer connection, accepted via QMP add_client.
  • gl=on|off|core|es β€” use OpenGL for rendering (the D-Bus interface will share framebuffers with DMABUF file descriptors).
  • sdl β€” display video output via SDL (usually in a separate graphics window; see the SDL documentation for other possibilities). Valid parameters are:
    • grab-mod=<mods> β€” used to select the modifier keys for toggling the mouse grabbing in conjunction with the "g" key. <mods> can be either lshift-lctrl-lalt or rctrl.
    • gl=on|off|core|es β€” use OpenGL for displaying.
    • show-cursor=on|off β€” force showing the mouse cursor.
    • window-close=on|off β€” allow quitting qemu with the window close button.
  • gtk β€” display video output in a GTK window. This interface provides drop-down menus and other UI elements to configure and control the VM during runtime. Valid parameters are:
    • clipboard=on|off β€” enable host-guest clipboard sharing, defaults to "off".
    • full-screen=on|off β€” start in fullscreen mode.
    • gl=on|off β€” use OpenGL for displaying.
    • grab-on-hover=on|off β€” grab keyboard input on mouse hover.
    • show-tabs=on|off β€” display the tab bar for switching between the various graphical interfaces (e.g. VGA and virtual console character devices) by default.
    • show-cursor=on|off β€” force showing the mouse cursor.
    • window-close=on|off β€” allow quitting qemu with the window close button.
    • show-menubar=on|off β€” display the main window menubar, defaults to "on".
    • zoom-to-fit=on|off β€” expand video output to the window size, defaults to "off".
  • curses[,charset=<encoding>] β€” display video output via curses. For graphics device models which support a text mode, QEMU can display this output using a curses/ncurses interface. Nothing is displayed when the graphics device is in graphical mode or if the graphics device does not support a text mode. Generally only the VGA device models support text mode. The font charset used by the guest can be specified with the charset option, for example charset=CP850 for IBM CP850 encoding. The default is CP437. πŸŽ€
  • cocoa β€” display video output in a Cocoa window. Mac only. 🍎 This interface provides drop-down menus and other UI elements to configure and control the VM during runtime. Valid parameters are:
    • full-grab=on|off β€” capture all key presses, including system combos. This requires accessibility permissions, since it performs a global grab on key events. (default: off) See https://support.apple.com/en-in/guide/mac-help/mh32356/mac
    • swap-opt-cmd=on|off β€” swap the Option and Command keys so that their key codes match their position on non-Mac keyboards and you can use Meta/Super and Alt where you expect them. (default: off)
    • show-cursor=on|off β€” force showing the mouse cursor.
    • left-command-key=on|off β€” disable forwarding the left command key to the host.
    • full-screen=on|off β€” start in fullscreen mode.
    • zoom-to-fit=on|off β€” expand video output to the window size, defaults to "off".
  • egl-headless[,rendernode=<file>] β€” offload all OpenGL operations to a local DRI device. For any graphical display, this display needs to be paired with either VNC or SPICE displays. ⭐
  • vnc=<display> β€” start a VNC server on display <display>.
  • none β€” do not display video output. The guest will still see an emulated graphics card, but its output won't be displayed to the QEMU user. This option differs from the -nographic option in that it only affects what is done with video output; -nographic also changes the destination of the serial and parallel port data. πŸ«₯

  • -nographic β€” okay so normally, if QEMU is built with graphical window support, it pops guest graphics, guest console, and the QEMU monitor into a window. With this flag you can totally disable graphical output and make QEMU a simple command line application. The emulated serial port gets redirected onto the console and muxed with the monitor (unless you explicitly redirect it somewhere else). So yes, bestie, you can still use QEMU to debug a Linux kernel with a serial console. Use C-a h for help switching between the console and monitor. πŸ’…
  • -spice option[,option[,...]] β€” enable the spice remote desktop protocol. Valid options are:
    • port=<nr> β€” set the TCP port spice is listening on for plaintext channels. πŸŽ€
    • addr=<addr> β€” set the IP address spice is listening on. Default is any address. ✨
    • ipv4=on|off; ipv6=on|off; unix=on|off β€” force using the specified IP version. πŸ¦‹
    • password-secret=<secret-id> β€” set the ID of the secret object containing the password you need to authenticate. πŸ”
    • sasl=on|off β€” require that the client use SASL to authenticate with the spice. The exact choice of authentication method used is controlled from the system / user's SASL configuration file for the qemu service. This is typically found in /etc/sasl2/qemu.conf. If running QEMU as an unprivileged user, an environment variable SASL_CONF_PATH can be used to make it search alternate locations for the service config. While some SASL auth methods can also provide data encryption (eg GSSAPI), it is recommended that SASL always be combined with the tls and x509 settings to enable use of SSL and server certificates. This ensures a data encryption preventing compromise of authentication credentials. πŸ”₯
    • disable-ticketing=on|off β€” allow client connects without authentication. πŸ™ˆ
    • disable-copy-paste=on|off β€” disable copy paste between the client and the guest. βœ‚οΈ
    • disable-agent-file-xfer=on|off β€” disable spice-vdagent based file-xfer between the client and the guest. πŸ“
    • tls-port=<nr> β€” set the TCP port spice is listening on for encrypted channels. πŸ”’
    • x509-dir=<dir> β€” set the x509 file directory. Expects same filenames as -vnc $display,x509=$dir. πŸ—‚οΈ
    • x509-key-file=<file>; x509-key-password=<file>; x509-cert-file=<file>; x509-cacert-file=<file>; x509-dh-key-file=<file> β€” the x509 file names can also be configured individually. πŸŽ€
    • tls-ciphers=<list> β€” specify which ciphers to use. πŸ’œ
    • tls-channel=main|display|cursor|inputs|record|playback; plaintext-channel=main|display|cursor|inputs|record|playback β€” force a specific channel to be used with or without TLS encryption. The options can be specified multiple times to configure multiple channels. The special name "default" can be used to set the default mode. For channels which are not explicitly forced into one mode the spice client is allowed to pick tls/plaintext as it pleases. 🌈
    • image-compression=auto_glz|auto_lz|quic|glz|lz|off β€” configure image compression (lossless). Default is auto_glz. πŸ–ΌοΈ
    • jpeg-wan-compression=auto|never|always; zlib-glz-wan-compression=auto|never|always β€” configure wan image compression (lossy for slow links). Default is auto. 🌸
    • streaming-video=off|all|filter β€” configure video stream detection. Default is off. πŸŽ₯
    • agent-mouse=on|off β€” enable/disable passing mouse events via vdagent. Default is on. πŸ–±οΈ
    • playback-compression=on|off β€” enable/disable audio stream compression (using celt 0.5.1). Default is on. 🎧
    • seamless-migration=on|off β€” enable/disable spice seamless migration. Default is off. 🧚
    • video-codec=<codec> β€” provide the preferred codec the Spice server should use with the Gstreamer encoder. This option is only relevant when gl=on is specified. If no codec is provided, then the codec gstreamer:h264 would be used as default. And, for the case where gl=off, the default codec to be used is determined by the Spice server. 🎬
    • max-refresh-rate=rate β€” provide the maximum refresh rate (or FPS) at which the encoding requests should be sent to the Spice server. Default would be 30. ⏱️
    • gl=on|off β€” enable/disable OpenGL context. Default is off. ✨
    • rendernode=<file> β€” DRM render node for OpenGL rendering. If not specified, it will pick the first available. (Since 2.9) πŸ’…
  • -vga type β€” select type of VGA card to emulate. Valid values for type are:
    • cirrus β€” Cirrus Logic GD5446 Video card. All Windows versions starting from Windows 95 should recognize and use this graphic card. For optimal performances, use 16 bit color depth in the guest and the host OS. (This card was the default before QEMU 2.2) πŸ–₯️
    • std β€” Standard VGA card with Bochs VBE extensions. If your guest OS supports the VESA 2.0 VBE extensions (e.g. Windows XP) and if you want to use high resolution modes (>= 1280x1024x16) then you should use this option. (This card is the default since QEMU 2.2) ⭐
    • vmware β€” VMWare SVGA-II compatible adapter. Use it if you have sufficiently recent XFree86/XOrg server or Windows guest with a driver for this card. πŸͺŸ
    • qxl β€” QXL paravirtual graphic card. It is VGA compatible (including VESA 2.0 VBE support). Works best with qxl guest drivers installed though. Recommended choice when using the spice protocol. πŸ‘‘
    • tcx β€” (sun4m only) Sun TCX framebuffer. This is the default framebuffer for sun4m machines and offers both 8-bit and 24-bit colour depths at a fixed resolution of 1024x768. 🌞
    • cg3 β€” (sun4m only) Sun cgthree framebuffer. This is a simple 8-bit framebuffer for sun4m machines available in both 1024x768 (OpenBIOS) and 1152x900 (OBP) resolutions aimed at people wishing to run older Solaris versions. πŸ¦‹
    • virtio β€” Virtio VGA card. 🧚
    • none β€” Disable VGA card. πŸ’€
  • -full-screen β€” start in full screen. πŸ–₯️✨
  • -g widthxheight[xdepth] β€” set the initial graphical resolution and depth (PPC, SPARC only). 🌸

For PPC the default is 800x600x32.

For SPARC with the TCX graphics device, the default is 1024x768x8 with the option of 1024x768x24. For cgthree, the default is 1024x768x8 with the option of 1152x900x8 for people who wish to use OBP. 🫢

  • -vnc display[,option[,option[,...]]] β€” okay so normally, if QEMU is compiled with graphical window support, it displays output such as guest graphics, guest console, and the QEMU monitor in a window. With this option, you can have QEMU listen on VNC display display and redirect the VGA display over the VNC session. It is very useful to enable the usb tablet device when using this option (option -device usb-tablet). When using the VNC display, you must use the -k parameter to set the keyboard layout if you are not using en-us. Valid syntax for display is:
    • to=L β€” with this option, QEMU will try next available VNC displays, until the number L, if the originally defined -vnc display is not available, e.g. port 5900+display is already used by another application. By default, to=0. πŸ”
    • host:d β€” TCP connections will only be allowed from host on display d. By convention the TCP port is 5900+d. Optionally, host can be omitted in which case the server will accept connections from any host. 🌐
    • unix:path β€” connections will be allowed over UNIX domain sockets where path is the location of a unix socket to listen for connections on. 🐚
    • none β€” VNC is initialized but not started. The monitor change command can be used to later start the VNC server. ⏸️

Following the display value there may be one or more option flags separated by commas. Valid options are:

  • reverse=on|off β€” connect to a listening VNC client via a "reverse" connection. The client is specified by the display. For reverse network connections like host:d with reverse, the d argument is a TCP port number, not a display number. πŸ”„
  • websocket=on|off β€” opens an additional TCP listening port dedicated to VNC Websocket connections. If a bare websocket option is given, the Websocket port is 5700+display. An alternative port can be specified with the syntax websocket=port. πŸ•ΈοΈ

If host is specified connections will only be allowed from this host. It is possible to control the websocket listen address independently, using the syntax websocket=host:port.

Websocket could be allowed over UNIX domain socket, using the syntax websocket=unix:path, where path is the location of a unix socket to listen for connections on.

If no TLS credentials are provided, the websocket connection runs in unencrypted mode. If TLS credentials are provided, the websocket connection requires encrypted client connections. πŸ”

  • password=on|off β€” require that password based authentication is used for client connections. πŸ”‘

The password must be set separately using the set_password command in the QEMU Monitor. The syntax to change your password is: set_password <protocol> <password> where <protocol> could be either "vnc" or "spice". πŸ’…

So if you wanna change a <protocol> password's expiration, you use expire_password <protocol> <expiration-time> β€” and the expiration time can be any of these: now, never, +seconds, or a straight-up UNIX timestamp. Like +60 makes the password expire in 60 seconds, and 1335196800 makes it expire on "Mon Apr 23 12:00:00 EDT 2012" (that's the UNIX time for that date and time, bestie).

You can also just use the keywords "now" or "never" as the expiration time so the <protocol> password expires immediately or literally never expires. πŸ’…

  • password-secret=<secret-id> β€” makes password-based auth mandatory for client connections, using the password from the secret object with that secret-id. πŸ”
  • tls-creds=ID β€” hands over the ID of a TLS credentials set to secure the VNC server. These apply to both the normal VNC server socket and the websocket socket (if it's enabled). Setting TLS creds makes the VNC server socket turn on the VeNCrypt auth mechanism. And psst β€” those credentials should've already been made earlier with the -object tls-creds argument.
  • tls-authz=ID β€” the ID of the QAuthZ authorization object that the client's x509 distinguished name gets validated against. This object is only resolved at time of use, so you can delete and recreate it on the fly while the VNC server is still active. If it's missing, it defaults to denying access. πŸ™ˆ
  • sasl=on|off β€” requires the client to use SASL to authenticate with the VNC server. The exact auth method is controlled from the system / user's SASL configuration file for the 'qemu' service β€” usually found at /etc/sasl2/qemu.conf. If you're running QEMU as an unprivileged user, you can use the environment variable SASL_CONF_PATH to make it search alternate places for the service config. Some SASL auth methods can also give you data encryption (eg GSSAPI), but it's recommended that SASL always be combined with the 'tls' and 'x509' settings so SSL and server certificates are in play. That's what ensures data encryption preventing compromise of authentication credentials. See the VNC security section in the System Emulation Users Guide for the deets on SASL auth.
  • sasl-authz=ID β€” the ID of the QAuthZ authorization object the client's SASL username gets validated against. Again, only resolved at time of use, so delete-and-recreate on the fly while the VNC server is active is totally fine. Missing = access denied by default.
  • acl=on|off β€” the ✨legacy✨ way of enabling client authorization against the x509 distinguished name and SASL username. It creates two authz-list objects with the IDs vnc.username and vnc.x509dname. You gotta configure the rules for those objects with the HMP ACL commands.
🚨 Deprecated alert β€” this option is deprecated and should no longer be used. The new sasl-authz and tls-authz options replace it. Periodt.
  • lossy=on|off β€” enables lossy compression methods (gradient, JPEG, ...). With this set, the VNC client may receive lossy framebuffer updates depending on its encoding settings. It can save you so much bandwidth, at the expense of quality. Trade-offs, bestie 😭
  • non-adaptive=on|off β€” disables adaptive encodings. Adaptive encodings are on by default. An adaptive encoding tries to detect frequently updated screen regions and sends updates there using a lossy encoding (like JPEG) β€” which is genuinely really helpful for saving bandwidth while playing videos. Disabling them restores the original static behavior of encodings like Tight. πŸŽ€
  • share=allow-exclusive|force-shared|ignore β€” sets the display sharing policy:
    • 'allow-exclusive' lets clients ask for exclusive access. As suggested by the rfb spec, this is implemented by dropping other connections. Connecting multiple clients in parallel requires all of them asking for a shared session (vncviewer: -shared switch). This is the default.
    • 'force-shared' disables exclusive client access. Super useful for shared desktop sessions where you don't want someone forgetting to specify -shared and disconnecting everybody else. πŸ’€
    • 'ignore' completely ignores the shared flag and lets everybody connect unconditionally. Doesn't conform to the rfb spec, but it's traditional QEMU behavior.
  • key-delay-ms β€” sets the keyboard delay for key down and key up events, in milliseconds. Default is 10. Keyboards are low-bandwidth devices, so this slowdown helps the device and guest keep up and not lose events when they're arriving in bulk β€” causes for that being flaky network connections, or scripts for automated testing. ⌨️
  • audiodev=audiodev β€” uses the specified audiodev when the VNC client requests audio transmission. If you're not using an -audiodev argument, this option must be omitted; otherwise it must be present and specify a valid audiodev. 🎧
  • power-control=on|off β€” permits the remote client to issue shutdown, reboot or reset power control requests. Power to the people, lowkey.

🌸 i386 target only 🌸

-win2k-hack

Use this when you're installing Windows 2000 to dodge a disk full bug. Once Windows 2000 is installed you don't need it anymore β€” and ngl, this option slows down the IDE transfers. Synonym of -global ide-device.win2k-install-hack=on.

-no-fd-bootchk

Disables boot signature checking for floppy disks in BIOS. Might be needed to boot from old floppy disks. Synonym of -m fd-bootchk=off. πŸ’Ύ

-acpitable [sig=str][,rev=n][,oem_id=str][,oem_table_id=str][,oem_rev=n][,asl_compiler_id=str][,asl_compiler_rev=n][,data=file1[:file2]...]

Adds an ACPI table with the specified header fields and context from the specified files. With file=, it takes the whole ACPI table from the specified files, including all ACPI headers (possibly overridden by other options). With data=, only the data portion of the table is used β€” all header info comes from the command line. And heads up: if a SLIC table is supplied to QEMU, then the SLIC's oem_id and oem_table_id fields will override the same in the RSDT and the FADT (a.k.a. FACP), so the field matches what the Microsoft SLIC spec and the ACPI spec require. ✨

-smbios file=binary

Loads the SMBIOS entry from a binary file. πŸ“„

-smbios type=0[,vendor=str][,version=str][,date=str][,release=%d.%d][,uefi=on|off]

Specify SMBIOS type 0 fields.

-smbios type=1[,manufacturer=str][,product=str][,version=str][,serial=str][,uuid=uuid][,sku=str][,family=str]

Specify SMBIOS type 1 fields.

-smbios type=2[,manufacturer=str][,product=str][,version=str][,serial=str][,asset=str][,location=str]

Specify SMBIOS type 2 fields.

-smbios type=3[,manufacturer=str][,version=str][,serial=str][,asset=str][,sku=str]

Specify SMBIOS type 3 fields.

-smbios type=4[,sock_pfx=str][,manufacturer=str][,version=str][,serial=str][,asset=str][,part=str][,processor-family=%d][,processor-id=%d]

Specify SMBIOS type 4 fields.

-smbios type=9[,slot_designation=str][,slot_type=%d][,slot_data_bus_width=%d][,current_usage=%d][,slot_length=%d][,slot_id=%d][,slot_characteristics1=%d][,slot_characteristics12=%d][,pci_device=str]

Specify SMBIOS type 9 fields.

-smbios type=11[,value=str][,path=filename]

Specify SMBIOS type 11 fields.

This argument can be repeated multiple times, and values are added in the order they're parsed. Applications planning to use OEM strings data are encouraged to use their application name as a prefix for the value string β€” that makes it way easier to pass info for multiple applications at once. 🫢

The value=str syntax gives the string data inline, while path=filename loads data from a file on disk. Note that the file is not permitted to contain any NUL bytes.

Both the value and path options can be repeated multiple times and get added to the SMBIOS table in the order they appear.

⚠️ Heads up: on the x86 architecture, the total size of all SMBIOS tables is limited to 65535 bytes. So OEM strings data is not suitable for passing large amounts of data into the guest β€” it should be used as an indicator to inform the guest where to find the real data set, like specifying the serial ID of a block device. 😭

An example passing three strings is:

-sm bios type=11,value=cloud-init:ds=nocloud-net;s=http://10.10.0.1:8000/,\
                value=anaconda:method=http://dl.fedoraproject.org/pub/fedora/linux/releases/25/x86_64/os,\
                path=/some/file/with/oemstringsdata.txt

In the guest OS this is visible with the dmidecode command:

$ dmidecode -t 11
Handle 0x0E00, DMI type 11, 5 bytes
OEM Strings
     String 1: cloud-init:ds=nocloud-net;s=http://10.10.0.1:8000/
     String 2: anaconda:method=http://dl.fedoraproject.org/pub/fedora/linux/releases/25/x86_64/os
     String 3: myapp:some extra data

-smbios type=17[,loc_pfx=str][,bank=str][,manufacturer=str][,serial=str][,asset=str][,part=str][,speed=%d]

Specify SMBIOS type 17 fields.

-smbios type=41[,designation=str][,kind=str][,instance=%d][,pcidev=str]

Specify SMBIOS type 41 fields. πŸ‘‘

  • -smbios … wait, we're mid-thought, bestie β€” okay so this argument can be repeated multiple times, and its ✨ main character ✨ use is letting network interfaces be created as enoX on Linux, where X is the instance number, instead of the name depending on the interface's position on the PCI bus. No more "why is my NIC named after a bus slot" meltdowns πŸ’…

Here's an example of use:

-netdev user,id=internet \
-device virtio-net-pci,mac=50:54:00:00:00:42,netdev=internet,id=internet-dev \
-smbios type=41,designation='Onboard LAN',instance=1,kind=ethernet,pcidev=internet-dev

In the guest OS, the device should then appear as eno1:

$ ip -brief l
lo               UNKNOWN        00:00:00:00:00:00 <LOOPBACK,UP,LOWER_UP>
eno1             UP             50:54:00:00:00:42 <BROADCAST,MULTICAST,UP,LOWER_UP>
Currently, the PCI device has to be attached to the root bus. That's the rule, bestie, no cap 🫢

🌐 Network options 🌐

πŸ¦‹ -nic

-nic [tap|passt|bridge|user|l2tpv3|vde|netmap|af-xdp|vhost-user|socket][,...][,mac=macaddr][,model=mn]

Okay so this one is the shortcut queen πŸ‘‘ β€” she configures both the on-board (default) guest NIC hardware and the host network backend in one go. The host backend options are literally the same as with the corresponding -netdev options below. You can set the guest NIC model with model=modelname β€” and yes, model=help lists all the available device types, slay. The hardware MAC address gets set with mac=macaddr.

The following two example do exactly the same β€” showing off how -nic can be used to shorten the command line length, because we love a low-effort high-impact moment ✨

qemu-kvm -netdev user,id=n1,ipv6=off -device e1000,netdev=n1,mac=52:54:98:76:54:32
qemu-kvm -nic user,ipv6=off,model=e1000,mac=52:54:98:76:54:32

🚫 -nic none

Indicate that no network devices should be configured. It's used to override the default configuration (that's the default NIC with the "user" host network backend) which gets activated if you don't provide any other networking options. It's giving "leave me alone, I'm offline" energy πŸ™ˆ

🧚 -netdev passt,id=str[,option][,...]

Configure a passt network backend which requires no administrator privilege to run. Obsessed. Valid options are:

  • id=id β€” assign a symbolic name for use in monitor commands.
  • path=file β€” filename of the passt program to run. If it's not provided, the passt command will be started with the help of the PATH environment variable.
  • quiet=on|off β€” by default, quiet=on, which disables informational messages from passt. quiet=on is passed as --quiet to passt.
  • vhost-user=on|off β€” by default, vhost-user=off and QEMU uses the stream network backend to talk to passt. If vhost-user=on, passt is started with --vhost-user and QEMU uses the vhost-user network backend to communicate with passt.
  • @mtu β€” assign MTU via DHCP/NDP
  • address β€” IPv4 or IPv6 address
  • netmask β€” IPv4 mask
  • mac β€” source MAC address
  • gateway β€” IPv4 or IPv6 address as gateway
  • interface β€” interface for addresses and routes
  • outbound β€” bind to address as outbound source
  • outbound-if4 β€” bind to outbound interface for IPv4
  • outbound-if6 β€” bind to outbound interface for IPv6
  • dns β€” IPv4 or IPv6 address as DNS
  • search β€” search domains
  • fqdn β€” FQDN to configure the client with
  • dhcp-dns β€” enable/disable DNS list in DHCP/DHCPv6/NDP
  • dhcp-search β€” enable/disable list in DHCP/DHCPv6/NDP
  • map-host-loopback β€” address to refer to host
  • map-guest-addr β€” addr to translate to the guest's address
  • dns-forward β€” forward DNS queries sent to
  • dns-host β€” host nameserver to direct queries to
  • tcp β€” enable/disable TCP
  • udp β€” enable/disable UDP
  • icmp β€” enable/disable ICMP
  • dhcp β€” enable/disable DHCP
  • ndp β€” enable/disable NDP
  • dhcpv6 β€” enable/disable DHCPv6
  • ra β€” enable/disable route advertisements
  • freebind β€” bind to any address for forwarding
  • ipv4 β€” enable/disable IPv4
  • ipv6 β€” enable/disable IPv6
  • tcp-ports β€” TCP ports to forward
  • udp-ports β€” UDP ports to forward
  • param=string β€” string will be passed to passt as a command line parameter. We can have multiple occurrences of the param parameter to pass multiple parameters to passt πŸ’–

For instance, to pass --trace --log=trace.log:

qemu-kvm -nic passt,param=--trace,param=--log=trace.log

πŸ“ -netdev user,id=id[,option][,option][,...]

Configure the user mode host network backend, which β€” say it with me β€” requires no administrator privilege to run. Iconic. Valid options are:

  • id=id β€” assign a symbolic name for use in monitor commands.
  • ipv4=on|off and ipv6=on|off β€” specify that either IPv4 or IPv6 must be enabled. If neither is specified, both protocols are enabled.
  • net=addr[/mask] β€” set the IP network address the guest will see. Optionally specify the netmask, either in the form a.b.c.d or as a number of valid top-most bits. Default is 10.0.2.0/24.
  • host=addr β€” specify the guest-visible address of the host. Default is the 2nd IP in the guest network, i.e. x.x.x.2.
  • ipv6-net=addr[/int] β€” set the IPv6 network address the guest will see (default is fec0::/64). The network prefix is given in the usual hexadecimal IPv6 address notation. The prefix size is optional, and is given as the number of valid top-most bits (default is 64).
  • ipv6-host=addr β€” specify the guest-visible IPv6 address of the host. Default is the 2nd IPv6 in the guest network, i.e. xxxx::2.
  • restrict=on|off β€” if this option is enabled, the guest will be isolated πŸ”’, i.e. it will not be able to contact the host and no guest IP packets will be routed over the host to the outside. This option does not affect any explicitly set forwarding rules.
  • hostname=name β€” specifies the client hostname reported by the built-in DHCP server.
  • dhcpstart=addr β€” specify the first of the 16 IPs the built-in DHCP server can assign. Default is the 15th to 31st IP in the guest network, i.e. x.x.x.15 to x.x.x.31.
  • dns=addr β€” specify the guest-visible address of the virtual nameserver. The address must be different from the host address. Default is the 3rd IP in the guest network, i.e. x.x.x.3.
  • ipv6-dns=addr β€” specify the guest-visible address of the IPv6 virtual nameserver. The address must be different from the host address. Default is the 3rd IP in the guest network, i.e. xxxx::3.
  • dnssearch=domain β€” provides an entry for the domain-search list sent by the built-in DHCP server. More than one domain suffix can be transmitted by specifying this option multiple times. If supported, this will cause the guest to automatically try to append the given domain suffix(es) in case a domain name can not be resolved.

Example:

qemu-kvm -nic user,dnssearch=mgmt.example.org,dnssearch=example.org
  • domainname=domain β€” specifies the client domain name reported by the built-in DHCP server.
  • tftp=dir β€” when using the user mode network stack, activate a built-in TFTP server. The files in dir will be exposed as the root of a TFTP server. The TFTP client on the guest must be configured in binary mode (use the command bin of the Unix TFTP client). The built-in TFTP server is read-only β€” it does not implement any command for writing files. QEMU will not write to this directory. 🚫✍️
  • tftp-server-name=name β€” in the BOOTP reply, broadcast name as the "TFTP server name" (RFC2132 option 66). This can be used to advise the guest to load boot files or configurations from a different server than the host address.
  • bootfile=file β€” when using the user mode network stack, broadcast file as the BOOTP filename. In conjunction with tftp, this can be used to network boot a guest from a local directory πŸ₯Ύβœ¨

Example (using pxelinux):

qemu-kvm -hda linux.img -boot n -device e1000,netdev=n1 \
    -netdev user,id=n1,tftp=/path/to/tftp/files,bootfile=/pxelinux.0
  • smb=dir[,smbserver=addr] β€” when using the user mode network stack, activate a built-in SMB server so that Windows OSes can access the host files in dir transparently. The IP address of the SMB server can be set to addr. By default the 4th IP in the guest network is used, i.e. x.x.x.4.

In the guest Windows OS, the line:

10.0.2.4 smbserver #PRE #NOFNR

must be added in the LMHOSTS file. In this line, #PRE requests pre-caching of the mapping, which speeds up the initial connection on some Windows versions. #NOFNR is necessary for Windows NT 3.1 to tell it not to send NBNS query packets that QEMU does not handle, and is harmlessly ignored on other versions.

The LMHOSTS file may be in different locations depending on the Windows version:

  • C:\WINDOWS\LMHOSTS for Windows 3x/9x/Me
  • C:\WINNT\SYSTEM32\DRIVERS\ETC\LMHOSTS for Windows NT/2000
  • C:\WINDOWS\SYSTEM32\DRIVERS\ETC\LMHOSTS for Windows XP and newer

Then dir can be accessed in \\smbserver\qemu.

Note that a SAMBA server must be installed on the host OS. Like, actually installed, bestie β€” this isn't magic 🧚
  • hostfwd=[tcp|udp|unix]:[[hostaddr]:hostport|hostpath]-[guestaddr]:guestport β€” okay so this one redirects incoming TCP, UDP or UNIX connections to the host port hostport over to the guest IP address guestaddr on guest port guestport. If you don't specify guestaddr, it just defaults to x.x.x.15 (that's the default first address the built-in DHCP server hands out, bestie πŸ’–). And if you specify hostaddr, the rule gets bound to a specific host interface. No connection type set? Then TCP is what you get. You can give this option multiple times, stack 'em up πŸŽ€

Like, say you wanna redirect the host X11 connection from screen 1 to guest screen 0 β€” literally just:

# on the host
qemu-kvm -nic user,hostfwd=tcp:127.0.0.1:6001-:6000
# this host xterm should open in the guest X11 server
xterm -display :1

And to redirect telnet connections from host port 5555 to the telnet port on the guest:

# on the host
qemu-kvm -nic user,hostfwd=tcp::5555-:23
telnet localhost 5555

Then when you use telnet localhost 5555 on the host, you connect to the guest telnet server. slay ✨

And to redirect host unix socket /tmp/vm to guest tcp socket 23, use:

# on the host
qemu-kvm -nic user,hostfwd=unix:/tmp/vm-:23
  • guestfwd=[tcp]:server:port-dev;
  • guestfwd=[tcp]:server:port-cmd:command β€” this one's the other direction, forwarding guest TCP connections to the IP address server on port port to the character device dev, or to a program executed by cmd:command which gets spawned for each connection. Multiple times? Yes bestie, as many as you want πŸ’…

You can either use a chardev directly and have that one used throughout QEMU's lifetime, like:

# open 10.10.1.1:4321 on bootup, connect 10.0.2.100:1234 to it whenever
# the guest accesses it
qemu-kvm -nic user,guestfwd=tcp:10.0.2.100:1234-tcp:10.10.1.1:4321

Or you can execute a command on every TCP connection established by the guest, so QEMU behaves similar to an inetd process for that virtual server:

# call "netcat 10.10.1.1 4321" on every TCP connection to 10.0.2.100:1234
# and connect the TCP stream to its stdin/stdout
qemu-kvm -nic  'user,id=n1,guestfwd=tcp:10.0.2.100:1234-cmd:netcat 10.10.1.1 4321'

🫢 -netdev β€” the TAP one

  • tap,id=id[,fd=h][,ifname=name][,script=file][,downscript=dfile][,br=bridge][,helper=helper] β€” configures a host TAP network backend with ID id. Obsessed with a backend that's just named tap ngl πŸ¦‹

So you use the network script file file to configure it, and the network script dfile to deconfigure it. If name isn't provided, the OS automatically provides one for you (iconic, no notes). The default network configure script is /etc/qemu-ifup and the default network deconfigure script is /etc/qemu-ifdown. Use script=no or downscript=no to disable script execution entirely πŸ’€

If you're running QEMU as an unprivileged user, use the network helper helper to configure the TAP interface and attach it to the bridge. The default network helper executable is /path/to/qemu-bridge-helper and the default bridge device is br0.

And fd=h can be used to specify the handle of an already opened host TAP interface. iykyk ✨

Examples:

#launch a QEMU instance with the default network script
qemu-kvm linux.img -nic tap
#launch a QEMU instance with two NICs, each one connected
#to a TAP device
qemu-kvm linux.img \
        -netdev tap,id=nd0,ifname=tap0 -device e1000,netdev=nd0 \
        -netdev tap,id=nd1,ifname=tap1 -device rtl8139,netdev=nd1
#launch a QEMU instance with the default network helper to
#connect a TAP device to bridge br0
qemu-kvm linux.img -device virtio-net-pci,netdev=n1 \
        -netdev tap,id=n1,"helper=/path/to/qemu-bridge-helper"

  • bridge,id=id[,br=bridge][,helper=helper] β€” connects a host TAP network interface to a host bridge device 🌈

You use the network helper helper to configure the TAP interface and attach it to the bridge. The default network helper executable is /path/to/qemu-bridge-helper and the default bridge device is br0. Same defaults, different backend β€” we love consistency πŸŽ€

Examples:

#launch a QEMU instance with the default network helper to
#connect a TAP device to bridge br0
qemu-kvm linux.img -netdev bridge,id=n1 -device virtio-net,netdev=n1
#launch a QEMU instance with the default network helper to
#connect a TAP device to bridge qemubr0
qemu-kvm linux.img -netdev bridge,br=qemubr0,id=n1 -device virtio-net,netdev=n1

  • socket,id=id[,fd=h][,listen=[host]:port][,connect=host:port] β€” this host network backend links the guest's network to another QEMU virtual machine using a TCP socket connection. networking but make it a group chat πŸ’¬

If listen is specified, QEMU waits for incoming connections on port (host is optional). connect is used to connect to another QEMU instance using the listen option. And fd=h specifies an already opened TCP socket.

Example:

# launch a first QEMU instance
qemu-kvm linux.img \
                 -device e1000,netdev=n1,mac=52:54:00:12:34:56 \
                 -netdev socket,id=n1,listen=:1234
# connect the network of this instance to the network of the first instance
qemu-kvm linux.img \
                 -device e1000,netdev=n2,mac=52:54:00:12:34:57 \
                 -netdev socket,id=n2,connect=127.0.0.1:1234

  • socket,id=id[,fd=h][,mcast=maddr:port[,localaddr=addr]] β€” configures a socket host network backend to share the guest's network traffic with other QEMU virtual machines using a UDP multicast socket, effectively making a bus for every QEMU with the same multicast address maddr and port. a whole little bus, bestie 🚌✨

NOTES (read these fr fr):

  1. Several QEMU can be running on different hosts and share same bus (assuming correct multicast setup for these hosts).
  2. mcast support is compatible with User Mode Linux (argument ethN=mcast), see http://user-mode-linux.sf.net.
  3. Use fd=h to specify an already opened UDP multicast socket.

Example:

# launch one QEMU instance
qemu-kvm linux.img \
                 -device e1000,netdev=n1,mac=52:54:00:12:34:56 \
                 -netdev socket,id=n1,mcast=230.0.0.1:1234
# launch another QEMU instance on same "bus"
qemu-kvm linux.img \
                 -device e1000,netdev=n2,mac=52:54:00:12:34:57 \
                 -netdev socket,id=n2,mcast=230.0.0.1:1234
# launch yet another QEMU instance on same "bus"
qemu-kvm linux.img \
                 -device e1000,netdev=n3,mac=52:54:00:12:34:58 \
                 -netdev socket,id=n3,mcast=230.0.0.1:1234

Example (User Mode Linux compat.):

# launch QEMU instance (note mcast address selected is UML's default)
qemu-kvm linux.img \
                 -device e1000,netdev=n1,mac=52:54:00:12:34:56 \
                 -netdev socket,id=n1,mcast=239.192.168.1:1102
# launch UML
/path/to/linux ubd0=/path/to/root_fs eth0=mcast

Example (send packets from host's 1.2.3.4):

qemu-kvm linux.img \
                 -device e1000,netdev=n1,mac=52:54:00:12:34:56 \
                 -netdev socket,id=n1,mcast=239.192.168.1:1102,localaddr=1.2.3.4

  • stream,id=str[,server=on|off],addr.type=inet,addr.host=host,addr.port=port[,to=maxport][,numeric=on|off][,keep-alive=on|off][,mptcp=on|off][,addr.ipv4=on|off][,addr.ipv6=on|off][,reconnect-ms=milliseconds] β€” configures a network backend to connect to another QEMU virtual machine or a proxy using a TCP/IP socket πŸ”₯
    • server=on|off β€” if on create a server socket
    • addr.host=host,addr.port=port β€” socket address to listen on (server=on) or connect to (server=off)
    • to=maxport β€” if present, this is range of possible addresses, with port between port and maxport.
    • numeric=on|off β€” if on host and port are guaranteed to be numeric, otherwise a name resolution should be attempted (default: off)
    • keep-alive=on|off β€” enable keep-alive when connecting to this socket. Not supported for passive sockets.
    • mptcp=on|off β€” enable multipath TCP
    • ipv4=on|off β€” whether to accept IPv4 addresses, default to try both IPv4 and IPv6
    • ipv6=on|off β€” whether to accept IPv6 addresses, default to try both IPv4 and IPv6
    • reconnect-ms=milliseconds β€” for a client socket, if a socket is disconnected, then attempt a reconnect after the given number of milliseconds. Setting this to zero disables this function. (default: 0)

Example (two guests connected using a TCP/IP socket):

# first VM
qemu-kvm linux.img \
              -device virtio-net,netdev=net0,mac=52:54:00:12:34:56 \
              -netdev stream,id=net0,server=on,addr.type=inet,addr.host=localhost,addr.port=1234
# second VM
qemu-kvm linux.img \
              -device virtio-net,netdev=net0,mac=52:54:00:12:34:57 \
              -netdev stream,id=net0,server=off,addr.type=inet,addr.host=localhost,addr.port=1234,reconnect-ms=5000

  • stream,id=str[,server=on|off],addr.type=unix,addr.path=path[,abstract=on|off][,tight=on|off][,reconnect-ms=milliseconds] β€” same energy but it connects to another QEMU virtual machine or a proxy using a stream oriented unix domain socket 🧚
    • server=on|off β€” if on create a server socket
    • addr.path=path β€” filesystem path to use
    • abstract=on|off β€” if on, this is a Linux abstract socket address.
    • tight=on|off β€” if false, pad an abstract socket address with enough null bytes to make it fill struct sockaddr_un member sun_path.
  • reconnect-ms=milliseconds β€” okay so if this is a client socket and it gets disconnected, it'll try to reconnect after this many milliseconds. Set it to zero and the whole reconnect thing is off. Default is 0. πŸ’…

Example (using passt as a glow-up replacement for -netdev user) β€” lowkey obsessed with this one:

# start passt server as a non privileged user
passt
UNIX domain socket bound at /tmp/passt_1.socket
# start QEMU to connect to passt
qemu-kvm linux.img \
              -device virtio-net,netdev=net0 \
              -netdev stream,id=net0,server=off,addr.type=unix,addr.path=/tmp/passt_1.socket

Example (two guests connected using a stream oriented unix domain socket) β€” bestie networking, fr fr:

# first VM
qemu-kvm linux.img \
              -device virtio-net,netdev=net0,mac=52:54:00:12:34:56 \
              netdev stream,id=net0,server=on,addr.type=unix,addr.path=/tmp/qemu0
# second VM
qemu-kvm linux.img \
              -device virtio-net,netdev=net0,mac=52:54:00:12:34:57 \
              -netdev stream,id=net0,server=off,addr.type=unix,addr.path=/tmp/qemu0,reconnect-ms=5000

🫢 -netdev stream,id=str[,server=on|off],addr.type=fd,addr.str=file-descriptor[,reconnect-ms=milliseconds]

This one sets up a network backend that connects to another QEMU virtual machine or a proxy using a stream oriented socket file descriptor. Slay.

  • server=on|off β€” if it's on, we create a server socket. That's the whole vibe.
  • addr.str=file-descriptor β€” the file descriptor number to use as a socket.
  • reconnect-ms=milliseconds β€” for a client socket: if the socket gets disconnected, attempt a reconnect after this many milliseconds. Setting it to zero disables this function. (default: 0)

πŸ¦‹ -netdev dgram,id=str,remote.type=inet,remote.host=maddr,remote.port=port[,local.type=inet,local.host=addr]

Configure a network backend to connect to a multicast address. Yes, multicast. We're being social.

  • remote.host=maddr, remote.port=port β€” the multicast address.
  • local.host=addr β€” specify the host address to send packets from.

Example β€” three icons on the same "bus", I cannot:

# launch one QEMU instance
qemu-kvm linux.img \
              -device virtio-net,netdev=net0,mac=52:54:00:12:34:56 \
              -netdev dgram,id=net0,remote.type=inet,remote.host=224.0.0.1,remote.port=1234
# launch another QEMU instance on same "bus"
qemu-kvm linux.img \
              -device virtio-net,netdev=net0,mac=52:54:00:12:34:57 \
              -netdev dgram,id=net0,remote.type=inet,remote.host=224.0.0.1,remote.port=1234
# launch yet another QEMU instance on same "bus"
qemu-kvm linux.img \
              -device virtio-net,netdev=net0,mac=52:54:00:12:34:58 \
              -netdev dgram,id=net0,remote.type=inet,remote.host=224.0.0.1,remote.port=1234

🧚 -netdev dgram,id=str,remote.type=inet,remote.host=maddr,remote.port=port[,local.type=fd,local.str=file-descriptor]

Same multicast energy, but this time it connects to a multicast address using a UDP socket file descriptor. Iconic variation.

  • remote.host=maddr, remote.port=port β€” the multicast address.
  • local.str=file-descriptor β€” file descriptor to use to send packets.

πŸ’œ -netdev dgram,id=str,local.type=inet,local.host=addr,local.port=port[,remote.type=inet,remote.host=addr,remote.port=port]

Configure a network backend to connect to another QEMU virtual machine or a proxy using a datagram oriented unix domain socket. (Yes, that's what the manpage says, and yes, the flags are inet. We report, we don't judge. ✨)

  • local.host=addr, local.port=port β€” IP address to use to send the packets from.
  • remote.host=addr, remote.port=port β€” destination IP address.

Example (two guests connected using an UDP/IP socket) β€” look at these matching port swaps, it's giving choreography:

# first VM
qemu-kvm linux.img \
              -device virtio-net,netdev=net0,mac=52:54:00:12:34:56 \
              -netdev dgram,id=net0,local.type=inet,local.host=localhost,local.port=1234,remote.type=inet,remote.host=localhost,remote.port=1235
# second VM
qemu-kvm linux.img \
              -device virtio-net,netdev=net0,mac=52:54:00:12:34:56 \
              -netdev dgram,id=net0,local.type=inet,local.host=localhost,local.port=1235,remote.type=inet,remote.host=localhost,remote.port=1234

🌸 -netdev dgram,id=str,local.type=unix,local.path=path[,remote.type=unix,remote.path=path]

Configure a network backend to connect to another QEMU virtual machine or a proxy using a datagram oriented unix socket. The unix-socket remix, we love her.

  • local.path=path β€” filesystem path to use to bind the socket.
  • remote.path=path β€” filesystem path to use as a destination (see sendto(2)).

Example (two guests connected using an UDP/UNIX socket):

# first VM
qemu-kvm linux.img \
              -device virtio-net,netdev=net0,mac=52:54:00:12:34:56 \
              -netdev dgram,id=net0,local.type=unix,local.path=/tmp/qemu0,remote.type=unix,remote.path=/tmp/qemu1
# second VM
qemu-kvm linux.img \
              -device virtio-net,netdev=net0,mac=52:54:00:12:34:57 \
              -netdev dgram,id=net0,local.type=unix,local.path=/tmp/qemu1,remote.type=unix,remote.path=/tmp/qemu0

πŸŽ€ -netdev dgram,id=str,local.type=fd,local.str=file-descriptor

Configure a network backend to connect to another QEMU virtual machine or a proxy using a datagram oriented socket file descriptor. Short and sweet, we stan a concise queen.

  • local.str=file-descriptor β€” file descriptor to use to send packets.

πŸ”₯ -netdev l2tpv3,id=id,src=srcaddr,dst=dstaddr[,srcport=srcport][,dstport=dstport],txsession=txsession[,rxsession=rxsession][,ipv6=on|off][,udp=on|off][,cookie64=on|off][,counter=on|off][,pincounter=on|off][,txcookie=txcookie][,rxcookie=rxcookie][,offset=offset]

Bestie. This configures an L2TPv3 pseudowire host network backend. L2TPv3 (RFC3931) is a popular protocol for transporting Ethernet (and other Layer 2) data frames between two systems. It lives in routers, firewalls, and the Linux kernel (from version 3.3 onwards). Main character protocol energy.

This transport lets a VM talk directly to another VM, router, or firewall. No middleman, no cap.

  • src=srcaddr β€” source address (mandatory ⚠️).
  • dst=dstaddr β€” destination address (mandatory ⚠️).
  • udp=on β€” select udp encapsulation (default is ip).
  • srcport=srcport β€” source udp port.
  • dstport=dstport β€” destination udp port.
  • ipv6=on β€” force v6, otherwise it defaults to v4.
  • rxcookie=rxcookie; txcookie=txcookie β€” cookies are a weak form of security in the l2tpv3 specification. Their function is mostly to prevent misconfiguration. By default they're 32 bit.
  • cookie64=on β€” set cookie size to 64 bit instead of the default 32.
  • counter=off β€” force a 'cut-down' L2TPv3 with no counter, as in draft-mkonstan-l2tpext-keyed-ipv6-tunnel-00.
  • pincounter=on β€” work around broken counter handling in the peer. This may also help on networks which have packet reorder.
  • offset=offset β€” add an extra offset between header and data.

For example, to attach a VM running on host 4.3.2.1 via L2TPv3 to the bridge br-lan on the remote Linux host 1.2.3.4:

# Setup tunnel on linux host using raw ip as encapsulation
# on 1.2.3.4
ip l2tp add tunnel remote 4.3.2.1 local 1.2.3.4 tunnel_id 1 peer_tunnel_id 1 \
    encap udp udp_sport 16384 udp_dport 16384
ip l2tp add session tunnel_id 1 name vmtunnel0 session_id \
    0xFFFFFFFF peer_session_id 0xFFFFFFFF
ifconfig vmtunnel0 mtu 1500
ifconfig vmtunnel0 up
brctl addif br-lan vmtunnel0

# on 4.3.2.1
# launch QEMU instance - if your network has reorder or is very lossy add ,pincounter

qemu-kvm 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

⭐ -netdev vde,id=id[,sock=socketpath][,port=n][,group=groupname][,mode=octalmode]

Configure a VDE backend to connect to PORT n of a vde switch running on the host and listening for incoming connections on socketpath. Use GROUP groupname and MODE octalmode to change the default ownership and permissions for the communication port.

Heads up bestie 🫢 this option is only available if QEMU has been compiled with vde support enabled. No vde support, no vde for you. 😭

Example:

# launch vde switch
vde_switch -F -sock /tmp/myswitch
# launch QEMU instance
qemu-kvm linux.img -nic vde,sock=/tmp/myswitch

🌈 -netdev af-xdp,id=str,ifname=name[,mode=native|skb][,force-copy=on|off][,queues=n][,start-queue=m][,inhibit=on|off][,sock-fds=x:y:...:z][,map-path=/path/to/socket/map][,map-start-index=i]

Configure an AF_XDP backend to connect to a network interface name using an AF_XDP socket. A specific program attach mode for a default XDP program can be forced with mode, and it defaults to best-effort, where the likely most performant mode will be in use. The number of queues n should generally match the number of queues in the interface, and defaults to 1. Traffic arriving on non-configured device queues will not be delivered to the network backend. πŸ‘€

# set number of queues to 4
ethtool -L eth0 combined 4
# launch QEMU instance
qemu-kvm linux.img -device virtio-net-pci,netdev=n1 \
    -netdev af-xdp,id=n1,ifname=eth0,queues=4

The start-queue option can be specified if a particular range of queues [m, m + n] should be in use. For example, this may be necessary in order to use certain NICs in native mode. The kernel allows the driver to create a separate set of XDP queues on top of regular ones, and only these queues can be used for AF_XDP sockets. NICs that work this way may also require an additional traffic redirection with ethtool to these special queues. πŸ¦‹

# set number of queues to 1
ethtool -L eth0 combined 1
# redirect all the traffic to the second queue (id: 1)
# note: drivers may require non-empty key/mask pair.
ethtool -N eth0 flow-type ether \
    dst 00:00:00:00:00:00 m FF:FF:FF:FF:FF:FE action 1
ethtool -N eth0 flow-type ether \
    dst 00:00:00:00:00:01 m FF:FF:FF:FF:FF:FE action 1
# launch QEMU instance
qemu-kvm linux.img -device virtio-net-pci,netdev=n1 \
    -netdev af-xdp,id=n1,ifname=eth0,queues=1,start-queue=1

Bestie, you can also load the XDP program externally instead ✨ In that case the inhibit option should be set to on πŸ’…. And when inhibit is enabled you can use either sock-fds or map-path β€” pick one, okay? 🫢 sock-fds takes file descriptors for XDP sockets that are already open but not bound, and that are already added to a socket map for the corresponding queues. Literally one socket per queue 🧚

qemu-kvm linux.img -device virtio-net-pci,netdev=n1 \
    -netdev af-xdp,id=n1,ifname=eth0,queues=3,inhibit=on,sock-fds=15:16:17

If you set inhibit to on and pair it with map-path, then the expectation is that the XDP program with the socket map is already loaded on the networking device, and that the map is pinned into the BPF file system πŸŽ€. The path to that pinned map gets passed to QEMU, and QEMU goes ahead and creates the file descriptors and inserts them into the existing socket map πŸ’–

qemu-kvm linux.img -device virtio-net-pci,netdev=n1 \
    -netdev af-xdp,id=n1,ifname=eth0,queues=2,inhibit=on,map-path=/sys/fs/bpf/xsks_map

Also, map-start-index exists so you can specify the start offset for insertion into the socket map πŸ‘‘. And heads up: combining map-path and sock-fds together is not supported πŸ™ˆ.

  • -netdev vhost-user,chardev=id[,vhostforce=on|off][,queues=n] β€” sets up a vhost-user netdev, backed by a chardev id ✨. That chardev should be a unix domain socket backed one, mmkay. vhost-user uses its own very specifically defined protocol to pass vhost ioctl replacement messages to an application sitting on the other end of the socket πŸ’…. On non-MSIX guests you can force the feature with vhostforce. And use queues=n to say how many queues you want created for multiqueue vhost-user πŸ¦‹

Example, bestie:

qemu-kvm -m 512 -object memory-backend-file,id=mem,size=512M,mem-path=/hugetlbfs,share=on \
         -numa node,memdev=mem \
         -chardev socket,id=chr0,path=/path/to/socket \
         -netdev type=vhost-user,id=net0,chardev=chr0 \
         -device virtio-net-pci,netdev=net0
  • -netdev vhost-vdpa[,vhostdev=/path/to/dev][,vhostfd=h] β€” sets up a vhost-vdpa netdev 🌸. So what even is a vDPA device? It's a device that uses a datapath complying with the virtio specifications, but with a vendor specific control path, no cap. And vDPA devices can be physically on the hardware or emulated by software πŸ’œ
  • -netdev hubport,id=id,hubid=hubid[,netdev=nd] β€” creates a hub port on the emulated hub with ID hubid πŸŽ€. The hubport netdev is literally the thing that lets you connect a NIC to a QEMU emulated hub instead of to a single netdev. Or, if you'd rather, you can connect the hubport to another netdev with ID nd using the netdev=nd option πŸ’–
  • -net nic[,netdev=nd][,macaddr=mac][,model=type][,name=name][,addr=addr][,vectors=v] β€” the legacy option for configuring or creating an on-board (or machine default) Network Interface Card (NIC), and connecting it either to the emulated hub with ID 0 (i.e. the default hub) or to the netdev nd πŸ™ˆ.

If model is omitted, then the default NIC model associated with the machine type gets used β€” but πŸ‘€ note that the default NIC model may change in future QEMU releases, so it is highly recommended to always specify a model, fr fr.

Optionally the MAC address can be changed to mac, the device address set to addr (PCI cards only πŸ’…), and a name can be assigned for use in monitor commands ✨.

Optionally, for PCI cards, you can specify the number v of MSI-X vectors that the card should have β€” this option currently only affects virtio cards, and setting v = 0 disables MSI-X πŸ¦‹.

If no -net option is specified, a single NIC is created 😌. QEMU can emulate several different models of network card, and you can use -net nic,model=help for a list of available devices for your target πŸ‘‘

  • -net user|passt|tap|bridge|socket|l2tpv3|vde[,...][,name=name] β€” configures a host network backend (with the options corresponding to the same -netdev option) and hooks it up to the emulated hub 0 (the default hub) 🌈. Use name to specify the name of the hub port πŸ’œ

🌸 Character device options 🌸

The general form of a character device option is, okay:

-chardev backend,id=id[,mux=on|off][,options]

backend is one of: null, socket, udp, msmouse, hub, vc, ringbuf, file, pipe, console, serial, pty, stdio, braille, parallel, spicevmc, spiceport, dbus πŸŽ€. The specific backend determines which options actually apply to you πŸ’…

Use -chardev help to print all the available chardev backend types, super handy ✨

Every device must have an id, which can be any string up to 127 characters long πŸ“. It's used to uniquely identify this device in other command line directives, iykyk πŸ‘‘

A character device may be used in multiplexing mode by multiple front-ends β€” just specify mux=on to enable that mode πŸ¦‹. A multiplexer is a "1:N" device, where the "1" end is your specified chardev backend and the "N" end is the various parts of QEMU that can talk to a chardev. So if you create a chardev with id=myid and mux=on, QEMU creates a multiplexer with your specified ID, and then you can configure multiple front ends to use that chardev ID for their input/output πŸ’–. Up to four different front ends can connect to a single multiplexed chardev. (Without multiplexing enabled, a chardev can only be used by a single front end, facts are facts πŸ™ˆ.) For instance you could use this so a single stdio chardev gets used by two serial ports and the QEMU monitor 🌟:

-chardev stdio,mux=on,id=char0 \
-object monitor-hmp,id=hmp0,chardev=char0 \
-serial chardev:char0 \
-serial chardev:char0

You can have more than one multiplexer in a system configuration too 😭 for instance you could have a TCP port multiplexed between UART 0 and UART 1, and stdio multiplexed between the QEMU monitor and a parallel port:

-chardev stdio,mux=on,id=char0 \
-object monitor-hmp,id=hmp0,chardev=char0 \
-parallel chardev:char0 \
-chardev tcp,...,mux=on,id=char1 \
-serial chardev:char1 \
-serial chardev:char1

When you're using a multiplexed character device, some escape sequences get interpreted in the input πŸ‘€. See the chapter about Keys in the character backend multiplexer in the System Emulation Users Guide for more details, bestie πŸ“–

Also note that some other command line options may implicitly create multiplexed character backends β€” for instance -serial mon:stdio creates a multiplexed stdio backend connected to the serial port and the QEMU monitor, and -nographic also multiplexes the console and the monitor to stdio πŸ’…

If you need to aggregate data in the opposite direction (where one QEMU frontend interface receives input and output from multiple backend chardev devices), please refer to the paragraph below about the chardev hub aggregator device configuration 🫢

Every backend supports the logfile option, which supplies the path to a file that records all data transmitted via the backend πŸŽ€. And the logappend option controls whether that log file gets truncated or appended to when it's opened ✨

The available backends are:

  • -chardev null,id=id β€” a total void device πŸ’€. It won't emit any data and it'll drop any data it receives. The null backend takes no options at all, iconic minimalism πŸ‘‘
  • -chardev socket,id=id[,TCP options or unix options][,server=on|off][,wait=on|off][,telnet=on|off][,websocket=on|off][,reconnect-ms=milliseconds][,tls-creds=id][,tls-authz=id] β€” creates a two-way stream socket, which can be either a TCP or a unix socket 🌈. A unix socket gets created if path is specified. And behaviour is undefined if TCP options are specified for a unix socket, so don't do that πŸ™ˆ

server=on|off specifies that the socket shall be a listening socket πŸ‘‚

wait=on|off specifies that QEMU should not block waiting for a client to connect to a listening socket πŸ’…

telnet=on|off specifies that traffic on the socket should interpret telnet escape sequences πŸ“Ί

websocket=on|off specifies that the socket uses the WebSocket protocol for communication πŸ•ΈοΈ

reconnect-ms sets the timeout for reconnecting on non-server sockets when the remote end goes away 😭. QEMU will delay this many milliseconds and then attempt to reconnect. Zero disables reconnecting, and zero is the default πŸŽ€

tls-creds requests enablement of the TLS protocol for encryption, and specifies the id of the TLS credentials to use for the handshake πŸ”. Those credentials must be previously created with the -object tls-creds argument, no shortcuts.

tls-auth provides the ID of the QAuthZ authorization object against which the client's x509 distinguished name will be validated πŸ‘‘. This object is only resolved at time of use, so it can be deleted and recreated on the fly while the chardev server is active 🀯. If it's missing, it will default to denying access β€” safest default ever tbh.

TCP and unix socket options are given below πŸ’–

TCP options:

port=port[,host=host][,to=to][,ipv4=on|off][,ipv6=on|off][,nodelay=on|off]

  • host for a listening socket specifies the local address to be bound πŸ“. For a connecting socket it specifies the remote host to connect to 🌐. host is optional for listening sockets, and if it's not specified it defaults to 0.0.0.0 ✨
  • port for a listening socket specifies the local port to be bound πŸ”Œ. For a connecting socket it specifies the port on the remote host to connect to. port can be given as either a port number or a service name, and port is required periodt πŸ’…

okay so continuing right where we left off with the socket chardev, bestie:

to is only relevant to listening sockets, fr. If you specify it, and port cannot be bound, QEMU will attempt to bind to subsequent ports up to and including to until it succeeds. to must be specified as a port number. That's it, that's the rule.

ipv4=on|off and ipv6=on|off specify that either IPv4 or IPv6 must be used. If neither is specified the socket may use either protocol. πŸ’…

nodelay=on|off disables the Nagle algorithm. (Yes, that Nagle. He's not invited.)

πŸ¦‹ unix options: path=path[,abstract=on|off][,tight=on|off]

  • path specifies the local path of the unix socket. path is required, no skipping.
  • abstract=on|off specifies the use of the abstract socket namespace, rather than the filesystem. Optional, defaults to false.
  • tight=on|off sets the socket length of abstract sockets to their minimum, rather than the full sun_path length. Optional, defaults to true.

  • -chardev udp,id=id[,host=host],port=port[,localaddr=localaddr][,localport=localport][,ipv4=on|off][,ipv6=on|off] β€” sends all traffic from the guest to a remote host over UDP. 🌈
    • host specifies the remote host to connect to. If not specified it defaults to localhost.
    • port specifies the port on the remote host to connect to. port is required.
    • localaddr specifies the local address to bind to. If not specified it defaults to 0.0.0.0.
    • localport specifies the local port to bind to. If not specified any available local port will be used.
    • ipv4=on|off and ipv6=on|off specify that either IPv4 or IPv6 must be used. If neither is specified the device may use either protocol.
  • -chardev msmouse,id=id β€” forward QEMU's emulated msmouse events to the guest. msmouse does not take any options. iconic, minimal, no notes. ✨
  • -chardev hub,id=id,chardevs.0=id[,chardevs.N=id] β€” explicitly create a chardev backend hub device, with the possibility to aggregate input from multiple backend devices and forward it to a single frontend device. Lowkey genius: the hub device also takes the output from the frontend device and sends it back to all the connected backend devices. This allows for seamless interaction between different backend devices and a single frontend interface. Aggregation supported for up to 4 chardev devices. (Since 10.0) 🫢

For example, the following is a use case of 2 backend devices: virtual console vc0 and a pseudo TTY pty0 connected to a single virtio hvc console frontend device with a hub hub0 help. Virtual console renders text to an image, which can be shared over the VNC protocol. In turn, pty backend provides bidirectional communication to the virtio hvc console over the pseudo TTY file. The example configuration can be as follows:

-chardev pty,path=/tmp/pty,id=pty0 \
-chardev vc,id=vc0 \
-chardev hub,id=hub0,chardevs.0=pty0,chardevs.1=vc0 \
-device virtconsole,chardev=hub0 \
-vnc 0.0.0.0:0

Once QEMU starts VNC client and any TTY emulator can be used to control a single hvc console:

# Start TTY emulator
tio /tmp/pty

# Start VNC client and switch to virtual console Ctrl-Alt-2
vncviewer :0
πŸ’€ Several frontend devices is not supported. Stacking of multiplexers and hub devices is not supported as well. So don't try it, bestie, it's giving "undefined behaviour" energy.
  • -chardev vc,id=id[[,width=width][,height=height]][[,cols=cols][,rows=rows]][,encoding=ENCODING] β€” connect to a QEMU text console. The implementation and supported feature set depend on the selected display backend. πŸ‘€
    • The GTK backend uses libvte for the emulation and display (when available).
    • The D-Bus backend exports the character device as a Chardev object.
    • spice-app backend exports it as a Spice port.

In other cases, QEMU uses its own emulated VT100, and vc may optionally be given a specific size.

width and height specify the width and height respectively of the console, in pixels.

cols and rows specify that the console be sized to fit a text console with the given dimensions.

encoding specifies the character set expected from the guest: utf8 or cp437 (8-bit Extended ASCII / VGA).

  • -chardev ringbuf,id=id[,size=size] β€” create a ring buffer with fixed size size. size must be a power of two and defaults to 64K. Not me checking your math for you, but like… check your math. πŸŽ€
  • -chardev file,id=id,path=path[,input-path=input-path] β€” log all traffic received from the guest to a file. πŸ“
    • path specifies the path of the file to be opened. This file will be created if it does not already exist, and overwritten if it does. path is required.
    • If input-path is specified, this is the path of a second file which will be used for input. If input-path is not specified, no input will be available from the chardev.
🫢 Note that input-path is not supported on Windows hosts.
  • -chardev pipe,id=id,path=path β€” create a two-way connection to the guest. The behaviour differs slightly between Windows hosts and other hosts:
    • On Windows, a single duplex pipe will be created at \\.pipe\path.
    • On other hosts, 2 pipes will be created called path.in and path.out. Data written to path.in will be received by the guest. Data written by the guest can be read from path.out. QEMU will not create these fifos, and requires them to be present.

path forms part of the pipe path as described above. path is required. ✨

  • -chardev console,id=id β€” send traffic from the guest to QEMU's standard output. console does not take any options.
console is only available on Windows hosts. Windows girlies rise up πŸ’…
  • -chardev serial,id=id,path=path β€” send traffic from the guest to a serial device on the host.

On Unix hosts serial will actually accept any tty device, not only serial lines. (she's flexible like that)

path specifies the name of the serial device to open.

  • -chardev pty,id=id[,path=path] β€” create a new pseudo-terminal on the host and connect to it.
pty is not available on Windows hosts.

If path is specified, QEMU will create a symbolic link at that location which points to the new PTY device. This avoids having to make QMP or HMP monitor queries to find out what the new PTY device path is. 🌸

😭 Note that while QEMU will remove the symlink when it exits gracefully, it will not do so in case of crashes or on certain startup errors. It is recommended that the user checks and removes the symlink after QEMU terminates to account for this. Literally check your symlinks, bestie, for me.
  • -chardev stdio,id=id[,signal=on|off] β€” connect to standard input and standard output of the QEMU process.

signal controls if signals are enabled on the terminal, that includes exiting QEMU with the key sequence Control+c. This option is enabled by default, use signal=off to disable it. ⭐

  • -chardev braille,id=id β€” connect to a local BrlAPI server. braille does not take any options. accessibility icon behaviour, we love to see it πŸ¦‹
  • -chardev parallel,id=id,path=path
parallel is only available on Linux, FreeBSD and DragonFlyBSD hosts. πŸ’€

Connect to a local parallel port.

path specifies the path to the parallel port device. path is required.

  • -chardev spicevmc,id=id,debug=debug,name=name β€” spicevmc is only available when spice support is built in.
    • debug β€” debug level for spicevmc
    • name β€” name of spice channel to connect to

Connect to a spice virtual machine channel, such as vdiport. ✨

  • -chardev spiceport,id=id,debug=debug,name=name β€” spiceport is only available when spice support is built in.
    • debug β€” debug level for spicevmc
    • name β€” name of spice port to connect to

Connect to a spice port, allowing a Spice client to handle the traffic identified by a name (preferably a fqdn). iykyk πŸŽ€

  • -chardev dbus,id=id,name=name β€” dbus is only available when D-Bus display support is built in.
    • name β€” name of the chardev as exported on the D-Bus display interface

Export the character device on the D-Bus display interface, so that a D-Bus client can connect to it. 🫢


🧚 TPM device options 🧚

The general form of a TPM device option is:

  • -tpmdev backend,id=id[,options] β€” the specific backend type will determine the applicable options. The -tpmdev option creates the TPM backend and requires a -device option that specifies the TPM frontend interface model.

Use -tpmdev help to print all available TPM backend types. πŸ‘‘

The available backends are:

  • -tpmdev passthrough,id=id,path=path,cancel-path=cancel-path β€” (Linux-host only) enable access to the host's TPM using the passthrough driver. 🐧
    • path specifies the path to the host's TPM device, i.e., on a Linux host this would be /dev/tpm0. path is optional and by default /dev/tpm0 is used.
    • cancel-path specifies the path to the host TPM device's sysfs entry allowing for cancellation of an ongoing TPM command. cancel-path is optional and by default QEMU will search for the sysfs entry to use.

Some notes about using the host's TPM with the passthrough driver, and bestie you're gonna wanna read these:

  • The TPM device accessed by the passthrough driver must not be used by any other application on the host. Like, at all. It's taken. πŸ’€
  • Since the host's firmware (BIOS/UEFI) has already initialized the TPM, the VM's firmware (BIOS/UEFI) will not be able to initialize the TPM again and may therefore not show a TPM-specific menu that would otherwise allow the user to configure the TPM β€” e.g., allow the user to enable/disable or activate/deactivate the TPM. Further, if TPM ownership is released from within a VM then the host's TPM will get disabled and deactivated. To enable and activate the TPM again afterwards, the host has to be rebooted and the user is required to enter the firmware's menu to enable and activate the TPM. If the TPM is left disabled and/or deactivated most TPM commands will fail. 😭 seriously, don't skip this part

To create a passthrough TPM use the following two options:

-tpmdev passthrough,id=tpm0 -device tpm-tis,tpmdev=tpm0

Note that the -tpmdev id is tpm0 and is referenced by tpmdev=tpm0 in the device option. Match your ids, bestie, it's literally the whole vibe. πŸ’–

  • -tpmdev emulator,id=id,chardev=dev β€” bestie, this one is Linux-host only and it lets you tap into a TPM emulator using a Unix domain socket based chardev backend. πŸ’…

chardev picks the unique ID of a character device backend that gives you the connection to the software TPM server. 🫢

To create a TPM emulator backend device with the chardev socket backend:

-chardev socket,id=chrtpm,path=/tmp/swtpm-sock -tpmdev emulator,id=tpm0,chardev=chrtpm -device tpm-tis,tpmdev=tpm0

πŸŽ€ Boot Image or Kernel specific πŸŽ€

Okay so there are broadly 4 ways you can boot a system with QEMU:

  • specify a firmware and let it control finding a kernel
  • specify a firmware and pass a hint to the kernel to boot
  • direct kernel image boot
  • manually load files into the guest's address space

The third method is useful for quickly testing kernels, but β€” and this is the catch β€” as there is no firmware to pass configuration information to the kernel, the hardware must either be probeable, the kernel built for the exact configuration, or passed some configuration data (e.g. a DTB blob) which tells the kernel what drivers it needs. The exact details are often hardware specific. 😭

The final method is the most generic way of loading images into the guest address space and is used mostly for bare metal type development where the reset vectors of the processor are taken into account. πŸ‘‘

For x86 machines and some other architectures -bios will generally do the right thing with whatever it is given. For other machines the more strict -pflash option needs an image that is sized for the flash device for the given machine type. ✨

Please see the QEMU System Emulator Targets section of the manual for more detailed documentation.

  • -bios file β€” set the filename for the BIOS. 🧚
  • -pflash file β€” use file as a parallel flash image. πŸ¦‹

The kernel options were designed to work with Linux kernels although other things (like hypervisors) can be packaged up as a kernel executable image. The exact format of an executable image is usually architecture specific. πŸ’€

The way in which the kernel is started (what address it is loaded at, what if any information is passed to it via CPU registers, the state of the hardware when it is started, and so on) is also architecture specific. Typically it follows the specification laid down by the Linux kernel for how kernels for that architecture must be started. 🌸

  • -kernel bzImage β€” use bzImage as kernel image. The kernel can be either a Linux kernel or in multiboot format. πŸ”₯
  • -shim shim.efi β€” use 'shim.efi' to boot the kernel. πŸ’œ
  • -append cmdline β€” use cmdline as kernel command line. πŸŽ€
  • -initrd file β€” use file as initial ram disk. 🫢
  • -initrd "file1 arg=foo,file2" β€” this syntax is only available with multiboot. Use file1 and file2 as modules and pass arg=foo as parameter to the first module. Commas can be provided in module parameters by doubling them on the command line to escape them. 😭
  • -initrd "bzImage earlyprintk=xen,,keep root=/dev/xvda1,initrd.img" β€” Multiboot only. Use bzImage as the first module with "earlyprintk=xen,keep root=/dev/xvda1" as its command line, and initrd.img as the second module. πŸ’…
  • -dtb file β€” use file as a device tree binary (dtb) image and pass it to the kernel on boot. 🌈

Finally you can also manually load images directly into the address space of the guest. This is most useful for developers who already know the layout of their guest and take care to ensure something sane will happen when the reset vector executes. πŸ‘€

The generic loader can be invoked by using the loader device:

-device loader,addr=<addr>,data=<data>,data-len=<data-len>[,data-be=<data-be>][,cpu-num=<cpu-num>]

There is also the guest loader which operates in a similar way but tweaks the DTB so a hypervisor loaded via -kernel can find where the guest image is:

-device guest-loader,addr=<addr>[,kernel=<path>,[bootargs=<arguments>]][,initrd=<path>]

πŸ”₯ Debug/Expert options πŸ”₯

  • -compat [deprecated-input=<input-policy>][,deprecated-output=<output-policy>] β€” set policy for handling deprecated management interfaces. This one is experimental. ⚠️
    • deprecated-input=accept (default) β€” accept deprecated commands and arguments. βœ…
    • deprecated-input=reject β€” reject deprecated commands and arguments. 🚫
    • deprecated-input=crash β€” crash on deprecated commands and arguments. πŸ’€
    • deprecated-output=accept (default) β€” emit deprecated command results and events. βœ…
    • deprecated-output=hide β€” suppress deprecated command results and events. πŸ™ˆ

Limitation: covers only syntactic aspects of QMP. 🫠

  • -compat [unstable-input=<input-policy>][,unstable-output=<output-policy>] β€” set policy for handling unstable management interfaces. Also experimental. ✨
    • unstable-input=accept (default) β€” accept unstable commands and arguments. βœ…
    • unstable-input=reject β€” reject unstable commands and arguments. 🚫
    • unstable-input=crash β€” crash on unstable commands and arguments. πŸ’€
    • unstable-output=accept (default) β€” emit unstable command results and events. βœ…
    • unstable-output=hide β€” suppress unstable command results and events. πŸ™ˆ

Limitation: covers only syntactic aspects of QMP. 🫠

  • -fw_cfg [name=]name,file=file β€” add a named fw_cfg entry with contents from file file. If the filename contains a comma, you must double it (for instance, "file=my,,file" to use file "my,file"). πŸ“
  • -fw_cfg [name=]name,string=str β€” add a named fw_cfg entry with contents from string str. If the string contains a comma, you must double it (for instance, "string=my,,string" to use file "my,string"). πŸ“

The terminating NUL character of the contents of str will not be included as part of the fw_cfg item data. To insert contents with embedded NUL characters, you have to use the file parameter. πŸ’‘

The fw_cfg entries are passed by QEMU through to the guest. 🎁

Example:

-fw_cfg name=opt/com.mycompany/blob,file=./my_blob.bin

This creates an fw_cfg entry named opt/com.mycompany/blob with contents from ./my_blob.bin. 🌟

  • -serial dev β€” redirect the virtual serial port to host character device dev. The default device is vc in graphical mode and stdio in non graphical mode. πŸŽ€

This option can be used several times to simulate multiple serial ports. πŸ’…

You can use -serial none to suppress the creation of default serial devices. 🚫

Available character devices are:

  • vc[:WxH] β€” virtual console. Optionally, a width and height can be given in pixels with:
vc:800x600

It is also possible to specify width or height in characters:

vc:80Cx24C
  • pty[:path] β€” [Linux only] pseudo TTY (a new PTY is automatically allocated). 🐧

If path is specified, QEMU will create a symbolic link at that location which points to the new PTY device. πŸ”—

This avoids having to make QMP or HMP monitor queries to find out what the new PTY device path is. 😌

Note that while QEMU will remove the symlink when it exits gracefully, it will not do so in case of crashes or on certain startup errors. It is recommended that the user checks and removes the symlink after QEMU terminates to account for this. ⚠️
  • none β€” no device is allocated. Note that for machine types which emulate systems where a serial device is always present in real hardware, this may be equivalent to the null option, in that the serial device is still present but all output is discarded. For boards where the number of serial ports is truly variable, this suppresses the creation of the device. πŸ«₯
  • null β€” a guest will see the UART or serial device as present in the machine, but all output is discarded, and there is no input. Conceptually equivalent to redirecting the output to /dev/null. πŸ•³οΈ
  • chardev:id β€” use a named character device defined with the -chardev option. 🏷️
  • /dev/XXX β€” [Linux only] use host tty, e.g. /dev/ttyS0. The host serial port parameters are set according to the emulated ones. 🐧
  • /dev/parportN β€” [Linux only, parallel port only] use host parallel port N. Currently SPP and EPP parallel port features can be used. πŸ–¨οΈ
  • file:filename β€” write output to filename. No character can be read. πŸ“„
  • stdio β€” [Unix only] standard input/output. πŸ–₯️
  • pipe:filename β€” name pipe filename (yes, that's what it says πŸ˜…). πŸ§ͺ
  • COMn β€” [Windows only] use host serial port n. πŸͺŸ
  • udp:[remote_host]:remote_port[@[src_ip]:src_port] β€” this implements UDP Net Console. When remote_host or src_ip are not specified they default to 0.0.0.0. When not using a specified src_port a random port is automatically chosen. 🌐

If you just want a simple readonly console you can use netcat or nc, by starting QEMU with: -serial udp::4555 and nc as: nc -u -l -p 4555. Any time QEMU writes something to that port it will appear in the netconsole session. πŸ’¬

If you plan to send characters back via netconsole or you want to stop and start QEMU a lot of times, you should have QEMU use the same source port each time by using something like -serial udp::4555@:4556 to QEMU. Another approach is to use a patched version of netcat which can listen to a TCP port and send and receive characters via udp. If you have a patched version of netcat which activates telnet remote echo and single char transfer, then you can use the following options to set up a netcat redirector to allow telnet on port 5555 to access the QEMU port. πŸ› οΈ

QEMU Options:

-serial udp::4555@:4556

netcat options:

-u -P 4555 -L 0.0.0.0:4556 -t -p 5555 -I -T

telnet options:

localhost 5555

So the serial backends keep going, and bestie, this is the part where things get ✨spicy✨. Buckle up. πŸŽ€

  • tcp:[host]:port[,server=on|off][,wait=on|off][,nodelay=on|off][,reconnect-ms=milliseconds] β€” okay so the TCP Net Console is genuinely a two-mode girlie. Mode one: it sends the serial I/O to a location. Mode two: it waits for a connection from a location. By default the TCP Net Console gets sent to host at the port. If you slap server=on on, QEMU waits for a client socket application to connect to the port before continuing β€” unless you also said wait=on|off, in which case that overrides it. The nodelay=on|off option disables the Nagle buffering algorithm (yes, that Nagle). The reconnect-ms option only does anything if server=no is set β€” if the connection goes down it will attempt to reconnect at the given interval. If host is omitted, 0.0.0.0 is assumed. And heads up: only one TCP connection at a time is accepted. You can use telnet=on to connect to the corresponding character device. πŸ’–

Example to send tcp console to 192.168.0.2 port 4444:

-serial tcp:192.168.0.2:4444

Example to listen and wait on port 4444 for connection:

-serial tcp::4444,server=on

Example to not wait and listen on ip 192.168.0.100 port 4444:

-serial tcp:192.168.0.100:4444,server=on,wait=off
  • telnet:host:port[,server=on|off][,wait=on|off][,nodelay=on|off] β€” this one's the telnet-protocol version instead of raw tcp sockets. The options work the same as if you had specified -serial tcp. The difference? The port acts like a telnet server or client using telnet option negotiation. And it will also let you send the MAGIC_SYSRQ sequence if you use a telnet that supports sending the break sequence. Typically in unix telnet you do it with Control+] and then type "send break" followed by pressing the enter key. cute, right? πŸ¦‹
  • websocket:host:port,server=on[,wait=on|off][,nodelay=on|off] β€” the WebSocket protocol is used instead of raw tcp socket. The port acts as a WebSocket server. Client mode is not supported β€” sorry bestie, that's just the vibe check result. πŸ’…
  • unix:path[,server=on|off][,wait=on|off][,reconnect-ms=milliseconds] β€” a unix domain socket is used instead of a tcp socket. The option works the same as if you had specified -serial tcp except the unix domain socket path is used for connections. 🌸
  • mon:dev_string β€” this is a special little icon to allow the monitor to be multiplexed onto another serial port. The monitor is accessed with the key sequence of Control+a and then pressing c. dev_string should be any one of the serial devices specified above. An example to multiplex the monitor onto a telnet server listening on port 4444 would be:
-serial mon:telnet::4444,server=on,wait=off
When the monitor is multiplexed to stdio in this way, Ctrl+C will not terminate QEMU any more but will be passed to the guest instead. so like, don't panic when it doesn't die, that's on purpose. 😭
  • braille β€” braille device! This will use BrlAPI to display the braille output on a real or fake device. accessibility main character energy fr fr. 🫢
  • msmouse β€” three button serial mouse. Configure the guest to use Microsoft protocol. πŸ–±οΈ

parallel & monitor-adjacent things ✨

  • -parallel dev β€” redirect the virtual parallel port to host device dev (same devices as the serial port). On Linux hosts, /dev/parportN can be used to use hardware devices connected on the corresponding host parallel port.

This option can be used several times to simulate up to 3 parallel ports. πŸ‘‘

Use -parallel none to disable all parallel ports.

  • -monitor dev β€” redirect the monitor to host device dev (same devices as the serial port). The default device is vc in graphical mode and stdio in non graphical mode. Use -monitor none to disable the default monitor. πŸŽ€

The use of -monitor dev is syntactic sugar for creating a character device from dev and pairing it with -object monitor-hmp. Both the character device and monitor object will be given an ID compat_monitorNNN where NNN is a counter starting from 0.

  • -qmp dev β€” like -monitor but opens in 'control' mode. For example, to make QMP available on localhost port 4444:
-qmp tcp:localhost:4444,server=on,wait=off

The use of -qmp dev is syntactic sugar for creating a character device from dev and pairing it with -object monitor-qmp. Both the character device and monitor object will be given an ID compat_monitorNNN where NNN is a counter starting from 0.

  • -qmp-pretty dev β€” like -qmp but uses pretty JSON formatting. it's giving aesthetic. πŸ’…
  • -mon [chardev=]name[,mode=readline|control][,pretty=on|off] β€” set up a monitor connected to the chardev name. QEMU supports two monitors: the Human Monitor Protocol (HMP; for human interaction), and the QEMU Monitor Protocol (QMP; a JSON RPC-style protocol). The default is HMP; mode=control selects QMP instead. pretty is only valid when mode=control, turning on JSON pretty printing to ease human reading and debugging. πŸ¦‹

For example:

-chardev socket,id=mon1,host=localhost,port=4444,server=on,wait=off \
-mon chardev=mon1,mode=control,pretty=on

enables the QMP monitor on localhost port 4444 with pretty-printing. slay.

The use of -mon mode=readline is deprecated syntactic sugar for the new -object monitor-hmp option, each use of which creates an object with the ID compat_monitorNNN where NNN is a counter starting from 0.
The use of -mon mode=control is deprecated syntactic sugar for the new -object monitor-qmp option, each use of which creates an object with the ID compat_monitorNNN where NNN is a counter starting from 0.

ngl, deprecated = move on bestie, the new -object way is the moment. πŸ’€

  • -debugcon dev β€” redirect the debug console to host device dev (same devices as the serial port). The debug console is an I/O port which is typically port 0xe9; writing to that I/O port sends output to this device. The default device is vc in graphical mode and stdio in non graphical mode. πŸ”₯
  • -pidfile file β€” store the QEMU process PID in file. It is useful if you launch QEMU from a script. tiny but mighty. πŸ“
  • --preconfig β€” pause QEMU for interactive configuration before the machine is created, which allows querying and configuring properties that will affect machine initialization. Use QMP command 'x-exit-preconfig' to exit the preconfig state and move to the next state (i.e. run guest if -S isn't used or pause the second time if -S is used). This option is experimental ⚠️ β€” so like, she's cute but she's still in beta.
  • -S β€” do not start CPU at startup (you must type 'c' in the monitor). the "wait for me" of options tbh. βœ‹

overcommit, gdb & friends πŸ’œ

  • -overcommit mem-lock=on|off|on-fault
  • -overcommit cpu-pm=on|off

Run qemu with hints about host resource overcommit. The default is to assume that host overcommits all resources. πŸ™ˆ

Locking qemu and guest memory can be enabled via mem-lock=on or mem-lock=on-fault (disabled by default). This works when host memory is not overcommitted and reduces the worst-case latency for guest. The on-fault option is better for reducing the memory footprint since it makes allocations lazy, but the pages still get locked in place once faulted by the guest or QEMU. Note that the two options are mutually exclusive. ⚠️ pick a lane bestie.

Guest ability to manage power state of host cpus (increasing latency for other processes on the same host cpu, but decreasing latency for guest) can be enabled via cpu-pm=on (disabled by default). This works best when host CPU is not overcommitted. When used, host estimates of CPU cycle and power utilization will be incorrect, not taking into account guest idle time. πŸ’€

  • -gdb dev β€” accept a gdb connection on device dev (see the GDB usage chapter in the System Emulation Users Guide). Note that this option does not pause QEMU execution β€” if you want QEMU to not start the guest until you connect with gdb and issue a continue command, you will need to also pass the -S option to QEMU. 😌

The most usual configuration is to listen on a local TCP socket:

-gdb tcp::3117

but you can specify other backends; UDP, pseudo TTY, or even stdio are all reasonable use cases. For example, a stdio connection allows you to start QEMU from within gdb and establish the connection via a pipe:

(gdb) target remote | exec qemu-kvm -gdb stdio ...
  • -s β€” shorthand for -gdb tcp::1234, i.e. open a gdbserver on TCP port 1234 (see the GDB usage chapter in the System Emulation Users Guide). ✨
  • -d item1[,...] β€” enable logging of specified items. Use '-d help' for a list of log items. πŸŽ€
  • -D logfile β€” output log in logfile instead of to stderr.
  • -dfilter range1[,...] β€” filter debug output to that relevant to a range of target addresses. The filter spec can be either start+size, start-size or start..end where start, end and size are the addresses and sizes required. For example:
-dfilter 0x8000..0x8fff,0xffffffc000080000+0x200,0xffffffc000060000-0x1000

Will dump output for any code in the 0x1000 sized block starting at 0x8000 and the 0x200 sized block starting at 0xffffffc000080000 and another 0x1000 sized block starting at 0xffffffc00005f000. math girlie behavior honestly. 🧚

  • -seed number β€” force the guest to use a deterministic pseudo-random number generator, seeded with number. This does not affect crypto routines within the host. 🌈
  • -L path β€” set the directory for the BIOS, VGA BIOS and keymaps. To list all the data directories, use -L help. πŸ”
  • -enable-kvm β€” enable KVM full virtualization support. This option is only available if KVM support is enabled when compiling. πŸ’…
  • -xen-domid id β€” specify xen guest domain id (XEN only).
  • -xen-attach β€” attach to existing xen domain. libxl will use this when starting QEMU (XEN only). Restrict set of available xen operations to specified domain id (XEN only). πŸ‘‘
  • -no-reboot β€” exit instead of rebooting. truly the "I'm not doing this again" energy. 😭
  • -no-shutdown β€” ok so normally when the guest shuts down QEMU just dips, right? Not with this flag bestie πŸ’… it makes QEMU only stop the emulation instead of exiting. Which means you can, like, switch over to the monitor and commit your changes to the disk image. Very much the "don't leave yet, I'm not done" energy.
  • -action event=action β€” this is the generic glow-up for QEMU's default behavior when certain guest events happen ✨ It's literally the same behaviors that -no-reboot and -no-shutdown tweak, just expressed in one unified way.

Examples, bestie:

-action panic=none -action reboot=shutdown,shutdown=pause -device
i6300esb -action watchdog=pause
  • -loadvm file β€” start immediately from a saved state (basically the loadvm command in the monitor). Instant main-character entrance, no waiting πŸŽ€
  • -daemonize β€” daemonize the QEMU process after initialization. And here's the cute part: QEMU will not detach from standard IO until it's actually ready to receive connections on any of its devices. So external programs can launch QEMU without having to deal with initialization race conditions πŸ¦‹ lowkey a lifesaver.
  • -option-rom file β€” loads the contents of file as an option ROM. Super useful for loading things like EtherBoot πŸ‘‘
  • -rtc [base=utc|localtime|datetime][,clock=host|rt|vm][,driftfix=none|slew] β€” the real-time clock knobs, bestie. So:
    • Set base to utc or localtime to let the RTC start at the current UTC or local time respectively. <italic>localtime</italic> is required for the correct date in MS-DOS or Windows. If you wanna start at a specific point in time, hand over datetime in the format 2006-06-17T16:01:21 or 2006-06-17. The default base is UTC.
    • By default the RTC is driven by the host system time. That lets you use the RTC as an accurate reference clock inside the guest β€” specifically if the host time is smoothly following an accurate external reference clock, e.g. via NTP. If you want to isolate the guest time from the host, set clock to rt instead, which gives you a host monotonic clock if the host supports it. To even stop the RTC from progressing during suspension, set clock to vm (virtual clock). clock=vm is recommended especially in icount mode to preserve determinism β€” but heads up, in icount mode the speed of the virtual clock is variable and can in general differ from the host clock πŸ™ˆ
    • Enable driftfix (i386 targets only) if you're experiencing time drift problems, specifically with Windows' ACPI HAL. This option tries to figure out how many timer interrupts were not processed by the Windows guest and re-injects them. Very "we noticed you missed these, here you go" 🫢
  • -icount [shift=N|auto][,align=on|off][,sleep=on|off][,rr=record|replay,rrfile=filename[,rrsnapshot=snapshot]] β€” enables the virtual instruction counter ✨ The virtual cpu executes one instruction every 2^N ns of virtual time. If auto is specified, the virtual cpu speed gets automatically adjusted to keep virtual time within a few seconds of real time.

Note that while this option can give deterministic behavior, it does not provide cycle-accurate emulation. Modern CPUs contain superscalar out-of-order cores with complex cache hierarchies, and the number of instructions executed often has little or no correlation with actual performance. It's giving "vibes, not benchmarks" πŸ’€

When the virtual cpu is sleeping, virtual time advances at default speed unless sleep=off is specified. With sleep=off, virtual time jumps to the next timer deadline instantly whenever the virtual cpu goes into sleep mode, and won't advance if no timer is enabled. This gives deterministic execution times from the guest's point of view. The default when icount is enabled is sleep=on. sleep=off cannot be used together with either shift=auto or align=on 🚫

align=on activates the delay algorithm that tries to synchronise the host clock and the virtual clock. The goal is a guest running at the real frequency imposed by the shift option. Whenever the guest clock is behind the host clock and align=on is specified, a message gets printed to the user to inform about the delay. Currently this option does not work when shift is auto. Note: the sync algorithm works for those shift values for which the guest clock runs ahead of the host clock β€” typically when the shift value is high (how high depends on the host machine). The default when icount is enabled is align=off.

When the rr option is specified, deterministic record/replay is enabled. The rrfile= option must also be provided to specify the path to the replay log. In record mode data is written to this file, and in replay mode it's read back. If the rrsnapshot option is given, it specifies a VM snapshot name. In record mode, a new VM snapshot with the given name is created at the start of execution recording. In replay mode this option specifies the snapshot name used to load the initial VM state 🎬

  • -watchdog-action action β€” controls what QEMU does when the watchdog timer expires. The default is reset (forcefully reset the guest). Other possible actions:
    • shutdown β€” attempt to gracefully shutdown the guest
    • poweroff β€” forcefully poweroff the guest
    • inject-nmi β€” inject a NMI into the guest
    • pause β€” pause the guest
    • debug β€” print a debug message and continue
    • none β€” do nothing
Note that the shutdown action requires the guest to respond to ACPI signals, which it may not be able to do in the sort of situations where the watchdog would have expired β€” and thus -watchdog-action shutdown is not recommended for production use 😭 fr fr take this seriously.

Example:

-device i6300esb -watchdog-action pause
  • -echr numeric_ascii_value β€” changes the escape character used to switch to the monitor when using monitor and serial sharing. The default is 0x01 when using the -nographic option, and 0x01 is equal to pressing Control+a. You can pick a different character from the ascii control keys, where 1 through 26 map to Control-a through Control-z. For instance, either of these changes the escape character to Control-t πŸŽ€
-echr 0x14; -echr 20

The -incoming option specifies the migration channel for an incoming migration. It may be used multiple times to specify multiple migration channel types πŸ’– The channel type is specified in <channel>, or is main for all other forms of -incoming. If multiple -incoming options are specified for a channel type, the last one takes precedence.

  • -incoming tcp:[host]:port[,to=maxport][,ipv4=on|off][,ipv6=on|off]
  • -incoming rdma:host:port[,ipv4=on|off][,ipv6=on|off] β€” prepare for incoming migration, listen on a given tcp port.
  • -incoming unix:socketpath β€” prepare for incoming migration, listen on a given unix socket πŸ¦‹
  • -incoming fd:fd β€” accept incoming migration from a given file descriptor.
  • -incoming file:filename[,offset=offset] β€” accept incoming migration from a given file starting at offset. offset allows the common size suffixes, or a 0x prefix, but not both πŸ™…
  • -incoming exec:cmdline β€” accept incoming migration as an output from the specified external command.
  • -incoming <channel> β€” accept incoming migration on the migration channel. For the syntax of <channel>, see the QAPI documentation of MigrationChannel. Examples, bestie:
-incoming '{"channel-type": "main",
            "addr": { "transport": "socket",
                      "type": "unix",
                      "path": "my.sock" }}'

-incoming main,addr.transport=socket,addr.type=unix,addr.path=my.sock
  • -incoming defer β€” wait for the URI to be specified via migrate_incoming. The monitor can be used to change settings (such as migration parameters) prior to issuing the migrate_incoming, so the migration can begin whenever you're ready ✨
  • -only-migratable β€” only allow migratable devices. Devices will not be allowed to enter an unmigratable state πŸ‘‘
  • -nodefaults β€” don't create default devices. Normally QEMU sets up default devices like the serial port, parallel port, virtual console, monitor device, VGA adapter, floppy and CD-ROM drive and others β€” -nodefaults disables all of those default devices. Very minimalist of you πŸ’…
  • -prom-env variable=value β€” set OpenBIOS nvram variable to the given value (PPC, SPARC only).
qemu-system-sparc -prom-env 'auto-boot?=false' \
 -prom-env 'boot-device=sd(0,2,0):d' -prom-env 'boot-args=linux single'

qemu-system-ppc -prom-env 'auto-boot?=false' \
 -prom-env 'boot-device=hd:2,\yaboot' \
 -prom-env 'boot-args=conf=hd:2,\yaboot.conf'
  • -semihosting β€” enable Semihosting mode (ARM, M68K, Xtensa, MIPS, RISC-V only).
WARNING: note that this allows the guest direct access to the host filesystem, so it should only be used with a trusted guest OS 😭 please please please be careful.

See the -semihosting-config option documentation for further information about the facilities this enables 🫢

  • -semihosting-config [enable=on|off][,target=native|gdb|auto][,chardev=id][,userspace=on|off][,arg=str[,...]] β€” enable and configure Semihosting (ARM, M68K, Xtensa, MIPS, RISC-V only).
WARNING: again β€” this allows the guest direct access to the host filesystem, so it should only be used with a trusted guest OS πŸ’€
  • target=native|gdb|auto β€” defines where the semihosting calls will be addressed: to QEMU (native) or to GDB (gdb). The default is auto, which means gdb during debug sessions and native otherwise.
  • chardev=str1 β€” send the output to a chardev backend output for native or auto output when not in gdb.
  • userspace=on|off β€” allows code running in guest userspace to access the semihosting interface. The default is that only privileged guest code can make semihosting calls. Note that setting userspace=on should only be used if all guest code is trusted (for example, in bare-metal test case code) πŸ™ˆ
  • arg=str1,arg=str2,... β€” okay so this is how you hand QEMU a whole little list of input arguments, and bestie you can pass it multiple times and it just keeps stacking them up into one big gorgeous list 🫢. The ancient -kernel/-append way of passing a command line is still supported for backward compatibility (respect the elders πŸ’…). But if you specify both the --semihosting-config arg thing and -kernel/-append, the former gets passed to semihosting, because it always takes precedence. Always. No negotiating.

  • -sandbox β€” turn on the Seccomp mode 2 system call filter. 'on' enables syscall filtering, 'off' disables it. The default is 'off'. Signature, exactly:
-sandbox arg[,obsolete=string][,elevateprivileges=string][,spawn=string][,resourcecontrol=string]
  • obsolete=string β€” enable Obsolete system calls.
  • elevateprivileges=string β€” disable set*uid|gid system calls.
  • spawn=string β€” disable *fork and execve.
  • resourcecontrol=string β€” disable process affinity and scheduler priority.
  • -readconfig file β€” reads device configuration from file. Super useful when you wanna spawn a QEMU process with, like, a million command line options but you do NOT wanna slam into the command line character limit 😭. Put it in a file, live your truth ✨.
  • -no-user-config β€” makes QEMU not load any of the user-provided config files on sysconfdir. That's it, that's the whole vibe. No user config, no drama.
  • -trace β€” specify tracing options. Signature:
-trace [[enable=]pattern][,events=file][,file=file]
  • [enable=]PATTERN β€” immediately enable events matching PATTERN (either an event name or a globbing pattern). This option is only available if QEMU has been compiled with the simple, log or ftrace tracing backend. To specify multiple events or patterns, just specify the -trace option multiple times, go off πŸ‘‘. And real talk: use -trace help to print a list of names of trace points. iykyk.
  • events=FILE β€” immediately enable events listed in FILE. The file must contain one event name (as listed in the trace-events-all file) per line; globbing patterns are accepted too. This option is only available if QEMU has been compiled with the simple, log or ftrace tracing backend.
  • file=FILE β€” log output traces to FILE. This option is only available if QEMU has been compiled with the simple tracing backend. (Only that one. Not the others. Yeah.)
  • -plugin β€” load a plugin. Signature:
-plugin file=file[,argname=argvalue]
  • file=file β€” load the given plugin from a shared library file.
  • argname=argvalue β€” argument passed to the plugin. (Can be given multiple times.) Stack 'em πŸ’…
  • -run-with β€” set QEMU process lifecycle options. Signature:
-run-with [async-teardown=on|off][,chroot=dir][,exit-with-parent=on|off][,user=username|uid:gid]
  • async-teardown=on enables asynchronous teardown. A new process called "cleanup/<QEMU_PID>" will be created at startup, sharing the address space with the main QEMU process, using clone. It will wait for the main QEMU process to terminate completely, and then exit. This allows QEMU to terminate very quickly even if the guest was huge, leaving the teardown of the address space to the cleanup process. Since the cleanup process shares the same cgroups as the main QEMU process, accounting is performed correctly. ⚠️ This only works if the cleanup process is not forcefully killed with SIGKILL before the main QEMU process has terminated completely. Do not do that.
  • chroot=dir can be used for doing a chroot to the specified directory immediately before starting the guest execution. This is especially useful in combination with user=.... Chef's kiss combo 🀌
  • exit-with-parent=on causes QEMU to exit if the parent process of QEMU exits. This can be used when QEMU runs a captive appliance, where the lifetime of the appliance is scoped to the parent process. In case the parent process crashes, QEMU is still cleaned up. This only works on Linux, FreeBSD and macOS platforms. 🍎🐧
  • user=username or user=uid:gid can be used to drop root privileges before starting guest execution. QEMU will use the setuid and setgid system calls to switch to the specified identity. Note that the user=username syntax will also apply the full set of supplementary groups for the user, whereas the user=uid:gid will use only the gid group. Different vibes, different group situations, choose wisely πŸŽ€
  • -msg β€” control error message format. Signature:
-msg [timestamp=on|off][,guest-name=on|off]
  • timestamp=on|off β€” prefix messages with a timestamp. Default is off.
  • guest-name=on|off β€” prefix messages with guest name, but only if the -name guest option is set β€” otherwise the option is just ignored, no cap. Default is off.
  • -dump-vmstate file β€” dump json-encoded vmstate information for current machine type to file in file. Just a lil json snapshot of the machine's state for you 🧚
  • -enable-sync-profile β€” enable synchronization profiling. Short, sweet, iconic.
  • -perfmap β€” generate a map file for Linux perf tools that will allow basic profiling information to be broken down into basic blocks. Profiling stans rise πŸ”₯
  • -jitdump β€” generate a dump file for Linux perf tools that maps basic blocks to symbol names, line numbers and JITted code. The full deluxe version, we love to see it πŸ’–

🧸 Generic object creation 🧸

  • -object typename[,prop1=value1,...] β€” create a new object of type typename, setting properties in the order they are specified. Lowkey important: note that the 'id' property must be set. These objects are placed in the /objects path. Okay now the specific ones πŸ‘‡
    • -object monitor-hmp,id=id,chardev=chardev_id,readline=on|off β€” set up a monitor running the Human Monitor Protocol, connected to the chardev chardev_id.

The id parameter is a unique ID that can be used to dynamically delete the monitor at runtime. Note that monitors created using the historical syntax will be allocated IDs following the pattern compat_monmitorNNN. (Yes, that's spelled monmitor in the docs. We don't fix it. We respect it. πŸ™ˆ) Mixing -object with -monitor syntax is discouraged.

The readline parameter, which defaults to on, controls whether the monitor provides line editing. Fancy ✨

  • -object monitor-qmp,id=id,chardev=chardev_id,pretty=on|off,close-action=none|delete β€” set up a monitor running the QEMU Monitor Protocol, connected to the chardev chardev_id.

The id parameter is a unique ID that can be used to dynamically delete the monitor at runtime. Note that monitors created using the historical syntax will be allocated IDs following the pattern compat_monitorNNN. Mixing -object with -qmp and -qmp-pretty syntax is discouraged.

The pretty parameter, which defaults to off, controls whether the monitor responses are pretty printed as multi-line indented JSON, as opposed to constrained to a single line without extraneous whitespace. (Multi-line indented JSON is so aesthetically pleasing but it's your call πŸ’…)

The close-action parameter, which defaults to none, controls what happens when the connection to the monitor is terminated by the user. If set to delete, then the monitor-qmp object and its associated character device are both immediately deleted. This can be useful if an extra monitor was hotplugged for a specific task and should be unplugged when completed. Cleanup queen behaviour πŸ§ΉπŸ‘‘

  • -object memory-backend-file,id=id,size=size,mem-path=dir,share=on|off,discard-data=on|off,merge=on|off,dump=on|off,prealloc=on|off,host-nodes=host-nodes,policy=default|preferred|bind|interleave,align=align,offset=offset,readonly=on|off,rom=on|off|auto β€” creates a memory file backend object, which can be used to back the guest RAM with huge pages. Big paging energy πŸ”₯

The id parameter is a unique ID that will be used to reference this memory region in other parameters, e.g. -numa, -device nvdimm, etc.

The size option provides the size of the memory region, and accepts common suffixes, e.g. 500M.

The mem-path provides the path to either a shared memory or huge page filesystem mount.

The share boolean option determines whether the memory region is marked as private to QEMU, or shared. The latter allows a co-operating external process to access the QEMU memory region.

Setting share=on might affect the ability to configure NUMA bindings for the memory backend under some circumstances β€” see Documentation/vm/numa_memory_policy.txt on the Linux kernel source tree for additional details.

Setting the discard-data boolean option to on indicates that file contents can be destroyed when QEMU exits, to avoid unnecessarily flushing data to the backing file. Note that discard-data is only an optimization, and QEMU might not discard file contents if it aborts unexpectedly or is terminated using SIGKILL. πŸ’€ So don't, like, rely on it for anything important, bestie.

The merge boolean option enables memory merge, also known as MADV_MERGEABLE, so that Kernel Samepage Merging will consider the pages for memory deduplication.

Setting the dump boolean option to off excludes the memory from core dumps. This feature is also known as MADV_DONTDUMP.

The prealloc boolean option enables memory preallocation.

The host-nodes option binds the memory range to a list of NUMA host nodes.

The policy option sets the NUMA policy to one of the following values:

  • default β€” default host policy
  • preferred β€” prefer the given host node list for allocation
  • bind β€” restrict memory allocation to the given host node list
  • interleave β€” interleave memory allocations across the given host node list
  • align β€” sets the base address alignment QEMU uses when it mmap(2)s mem-path, and it takes the usual suffixes, like 2M πŸ’…. Some backends out there (looking at you, mem-path stores) need a different alignment than QEMU's default β€” for example the device DAX /dev/dax0.0 wants 2M alignment, not 4K. In those cases you just tell QEMU what alignment you need with this option, and it slays accordingly.
  • offset β€” says where inside the target file the region starts. Yes bestie, you can back multiple regions with a single file using this. Multiplexing, but make it memory ✨.
  • pmem β€” tells QEMU whether the backing file in mem-path lives in host persistent memory that's accessible through the SNIA NVM programming model (think Intel NVDIMM, iykyk). If pmem is on, QEMU does the necessary operations to guarantee that its own writes to mem-path are persistent (this matters for, like, vNVDIMM label emulation and live migration 🫢). It also maps the backend file with the MAP_SYNC flag, which keeps the file metadata in sync for mem-path if the host crashes or loses power. Heads up though: MAP_SYNC needs support from both the host kernel (since Linux kernel 4.15) and the filesystem of mem-path mounted with the DAX option. No DAX, no sync, no cap πŸ’€.
  • readonly β€” whether the backing file gets opened read-only or read-write. Default is read-write, bestie.
  • rom β€” whether to create Read Only Memory (ROM) that the VM literally cannot modify. Any write attempt to that ROM gets denied, periodt. Most use cases want actual RAM, not ROM β€” but selected use cases, like R/O NVDIMMs, genuinely benefit from ROM 🌸. Set it to on β†’ create ROM; off β†’ create writable RAM; auto (which is the default) β†’ the value of the readonly option is used. This option is mainly a lifesaver when you want writable RAM in configurations that would traditionally create ROM back before the rom option even existed: VM templating, where you want to open a file readonly (readonly=on) and mark the memory private for QEMU (share=off). In that use case you need writable RAM instead of ROM, so you also want to set rom=off ✨.
  • -object memory-backend-ram,id=id,merge=on|off,dump=on|off,share=on|off,prealloc=on|off,size=size,host-nodes=host-nodes,policy=default|preferred|bind|interleave β€” creates a memory backend object, which can be used to back the guest RAM. Memory backend objects give you way more control than the -m option that's traditionally used to define guest RAM. For what all these options actually do, go peek at memory-backend-file πŸ‘€.
  • -object memory-backend-memfd,id=id,merge=on|off,dump=on|off,share=on|off,prealloc=on|off,size=size,host-nodes=host-nodes,policy=default|preferred|bind|interleave,seal=on|off,hugetlb=on|off,hugetlbsize=size β€” creates an anonymous memory file backend object, which lets QEMU share the memory with an external process (like when you're using vhost-user πŸ¦‹). The memory is allocated with memfd plus optional sealing. Linux only, obviously πŸ’….
    • seal β€” creates a sealed-file, which blocks any further resizing of the memory. It's on by default, so like… it comes pre-sealed.
    • hugetlb β€” says the file being created lives in the hugetlbfs filesystem (since Linux 4.14). Used together with the hugetlb option, the hugetlbsize option specifies the hugetlb page size on systems that support multiple hugetlb page sizes (and ngl it must be a power of 2 value supported by the system).
    • ⚠️ On some versions of Linux, the hugetlb option is incompatible with the seal option β€” it needs at least Linux 4.16 for them to coexist.
    • For a description of all the other options, please refer to memory-backend-file.

And one more thing: the share boolean option is on by default with memfd 🫢.

  • -object memory-backend-shm,id=id,merge=on|off,dump=on|off,share=on|off,prealloc=on|off,size=size,host-nodes=host-nodes,policy=default|preferred|bind|interleave β€” creates a POSIX shared memory backend object, which lets QEMU share the memory with an external process (again, vhost-user vibes 🧚).

memory-backend-shm is basically the more portable, less featureful version of memory-backend-memfd. So it can be used on any POSIX system, especially when memfd isn't supported 😌.

For a description of the options, refer to memory-backend-file.

The share boolean option is on by default with shm. Setting it to off will cause a failure during allocation, because this backend just doesn't support that β€” it's not being mean, it literally can't πŸ’€.

  • -object iommufd,id=id[,fd=fd] β€” creates an iommufd backend, which lets you control DMA mapping through the /dev/iommu device πŸ‘‘.

The id parameter is a unique ID which frontends (like vfio-pci or vdpa) will use to connect with the iommufd backend.

The fd parameter is an optional pre-opened file descriptor resulting from opening /dev/iommu. Usually the iommufd is shared across all subsystems, which brings you the benefit of centralized reference counting. Efficient and iconic ✨.

  • -object rng-builtin,id=id β€” creates a random number generator backend that gets its entropy from QEMU builtin functions 🌈. The id parameter is a unique ID that will be used to reference this entropy backend from the virtio-rng device. Fun fact: by default, the virtio-rng device uses this RNG backend, so it's the main character of entropy sources πŸ’….
  • -object rng-random,id=id,filename=/dev/random β€” creates a random number generator backend that gets entropy from a device on the host πŸ“. The id parameter is a unique ID used to reference this entropy backend from the virtio-rng device. The filename parameter says which file to grab entropy from β€” and if you omit it, it defaults to /dev/urandom.
  • -object rng-egd,id=id,chardev=chardevid β€” creates a random number generator backend that gets entropy from an external daemon running on the host 🌸. The id parameter is a unique ID used to reference this entropy backend from the virtio-rng device. The chardev parameter is the unique ID of a character device backend that provides the connection to the RNG daemon. Entropy, outsourced πŸ’–.
  • -object tls-creds-anon,id=id,endpoint=endpoint,dir=/path/to/cred/dir,verify-peer=on|off β€” creates a TLS anonymous credentials object, which can be used to provide TLS support on network backends πŸ”₯. The id parameter is a unique ID which network backends will use to access the credentials. The endpoint is either server or client, depending on whether the QEMU network backend using these credentials will be acting as a client or as a server. If verify-peer is enabled (and it is by default), then once the handshake is completed the peer credentials get verified β€” though for anonymous credentials that's a no-op, so it's kind of doing nothing with extra steps πŸ™ˆ.

The dir parameter tells QEMU where to find the credential files. For server endpoints, this directory may contain a file dh-params.pem providing diffie-hellman parameters to use for the TLS server. If that file is missing, QEMU will generate a set of DH parameters at startup β€” which is a computationally expensive operation that consumes random pool entropy, so it's recommended that you generate a persistent set of parameters up front and save them. Save your future self the pain, bestie 😭.

  • -object tls-creds-psk,id=id,endpoint=endpoint,dir=/path/to/keys/dir[,username=username] β€” creates a TLS Pre-Shared Keys (PSK) credentials object, which can be used to provide TLS support on network backends πŸ¦‹. The id parameter is a unique ID which network backends will use to access the credentials. The endpoint is either server or client, depending on whether the QEMU network backend using these credentials will be acting as a client or as a server. For clients only, username is the username that will be sent to the server β€” and if it's omitted it defaults to "qemu".

The dir parameter tells QEMU where to find the keys file. It's called "dir/keys.psk" and it contains "username:key" pairs. The easiest way to make this file is using the GnuTLS psktool program, no cap πŸ’….

For server endpoints, dir may also contain a file dh-params.pem providing diffie-hellman parameters to use for the TLS server. If that file is missing, QEMU will generate a set of DH parameters at startup. This is a computationally expensive operation that consumes random pool entropy, so it's recommended that a persistent set of parameters be generated up front and saved ✨.

  • -object tls-creds-x509,id=id,endpoint=endpoint,dir=/path/to/cred/dir,priority=priority,verify-peer=on|off,passwordid=id β€” creates a TLS anonymous credentials object, which can be used to provide TLS support on network backends πŸ‘‘. The id parameter is a unique ID which network backends will use to access the credentials. The endpoint is either server or client, depending on whether the QEMU network backend using these credentials will be acting as a client or as a server. If verify-peer is enabled (it's the default), then once the handshake is completed the peer credentials will be verified. With x509 certificates, this implies that the clients must be provided with valid client certificates too β€” so everyone shows their ID at the door πŸŽ€.

okay so back to the dir parameter πŸ’… β€” that’s the one telling QEMU where to find the credential files. For server endpoints, this directory may contain a file dh-params.pem providing diffie-hellman parameters to use for the TLS server. If that file is missing, QEMU will generate a set of DH parameters at startup. That is a computationally expensive operation that consumes random pool entropy, so it’s recommended that a persistent set of parameters be generated upfront and saved. 🫢

For x509 certificate credentials, the directory will contain further files providing the x509 certificates. The certificates must be stored in PEM format, in filenames ca-cert.pem, ca-crl.pem (optional), server-cert.pem (only servers), server-key.pem (only servers), client-cert.pem (only clients), and client-key.pem (only clients). ✨

For the server-key.pem and client-key.pem files which contain sensitive private keys, it is possible to use an encrypted version by providing the passwordid parameter. This provides the ID of a previously created secret object containing the password for decryption. πŸ”

The priority parameter allows overriding the global default priority used by gnutls. This can be useful if the system administrator needs to use a weaker set of crypto priorities for QEMU without potentially forcing the weakness onto all applications. Or conversely, if one wants a stronger default for QEMU than for all other applications, they can do this through this parameter. Its format is a gnutls priority string as described at https://gnutls.org/manual/html_node/Priority-Strings.html. πŸŽ€

  • -object tls-cipher-suites,id=id,priority=priority β€” creates a TLS cipher suites object, which can be used to control the TLS cipher/protocol algorithms that applications are permitted to use. πŸ¦‹

The id parameter is a unique ID which frontends will use to access the ordered list of permitted TLS cipher suites from the host.

The priority parameter allows overriding the global default priority used by gnutls. This can be useful if the system administrator needs to use a weaker set of crypto priorities for QEMU without potentially forcing the weakness onto all applications. Or conversely, if one wants a stronger default for QEMU than for all other applications, they can do this through this parameter. Its format is a gnutls priority string as described at https://gnutls.org/manual/html_node/Priority-Strings.html.

An example of use of this object is to control UEFI HTTPS Boot. The tls-cipher-suites object exposes the ordered list of permitted TLS cipher suites from the host side to the guest firmware, via fw_cfg. The list is represented as an array of IANA_TLS_CIPHER objects. The firmware uses the IANA_TLS_CIPHER array for configuring guest-side TLS. 🌈

In the following example, the priority at which the host-side policy is retrieved is given by the priority property. Given that QEMU uses GNUTLS, priority=@SYSTEM may be used to refer to /etc/crypto-policies/back-ends/gnutls.config.

# qemu-kvm \
    -object tls-cipher-suites,id=mysuite0,priority=@SYSTEM \
    -fw_cfg name=etc/edk2/https/ciphers,gen_id=mysuite0
  • -object filter-buffer,id=id,netdev=netdevid,interval=t[,queue=all|rx|tx][,status=on|off][,position=head|tail|id=<id>][,insert=behind|before] β€” interval t can’t be 0; this filter batches packet delivery: all packets arriving in a given interval on netdev netdevid are delayed until the end of the interval. Interval is in microseconds. status is optional and indicates whether the netfilter is on (enabled) or off (disabled); the default status for netfilter will be on. πŸ‘‘
    • queue all|rx|tx is an option that can be applied to any netfilter.
      • all: the filter is attached both to the receive and the transmit queue of the netdev (default).
      • rx: the filter is attached to the receive queue of the netdev, where it will receive packets sent to the netdev.
      • tx: the filter is attached to the transmit queue of the netdev, where it will receive packets sent by the netdev.
    • position head|tail|id=<id> is an option to specify where the filter should be inserted in the filter list. It can be applied to any netfilter.
      • head: the filter is inserted at the head of the filter list, before any existing filters.
      • tail: the filter is inserted at the tail of the filter list, behind any existing filters (default).
      • id=<id>: the filter is inserted before or behind the filter specified by <id>, see the insert option below.
    • insert behind|before is an option to specify where to insert the new filter relative to the one specified with position=id=<id>. It can be applied to any netfilter.
      • before: insert before the specified filter.
      • behind: insert behind the specified filter (default).
  • -object filter-mirror,id=id,netdev=netdevid,outdev=chardevid,queue=all|rx|tx[,vnet_hdr_support][,position=head|tail|id=<id>][,insert=behind|before] β€” filter-mirror on netdev netdevid mirrors net packets to the chardev chardevid; if it has the vnet_hdr_support flag, filter-mirror will mirror packets with vnet_hdr_len. πŸͺž
  • -object filter-redirector,id=id,netdev=netdevid,indev=chardevid,outdev=chardevid,queue=all|rx|tx[,vnet_hdr_support][,position=head|tail|id=<id>][,insert=behind|before] β€” filter-redirector on netdev netdevid redirects the filter’s net packet to chardev chardevid, and redirects indev’s packet to the filter. If it has the vnet_hdr_support flag, filter-redirector will redirect packets with vnet_hdr_len. To create a filter-redirector we need the outdev id to differ from the indev id β€” id can’t be the same. We can use just indev or just outdev, but at least one of indev or outdev needs to be specified. 🎯
  • -object filter-rewriter,id=id,netdev=netdevid,queue=all|rx|tx,[vnet_hdr_support][,position=head|tail|id=<id>][,insert=behind|before] β€” filter-rewriter is a part of the COLO project. It will rewrite TCP packets to the secondary from the primary to keep the secondary TCP connection, and rewrite TCP packets to the primary from the secondary so the TCP packet can be handled by the client. If it has the vnet_hdr_support flag, we can parse packets with a vnet header. 🧚

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
  • -object filter-dump,id=id,netdev=dev[,file=filename][,maxlen=len][,position=head|tail|id=<id>][,insert=behind|before] β€” dump the network traffic on netdev dev to the file specified by filename. At most len bytes (64k by default) per packet are stored. The file format is libpcap, so it can be analyzed with tools such as tcpdump or Wireshark. πŸ“¦
  • -object colo-compare,id=<id>,primary_in=<chardevid>,secondary_in=<chardevid>,outdev=<chardevid>,iothread=<id>[,vnet_hdr_support][,notify_dev=<id>][,compare_timeout=<time_ms>][,expired_scan_cycle=<time_ms>][,max_queue_size=<maxsize>] β€” Colo-compare gets packets from the chardev backends specified by primary_in and secondary_in, and compares whether the payloads of the primary packet and the secondary packet are the same. If they match, it will output the primary packet to the chardev backend specified by outdev; otherwise it will notify COLO-framework to do a checkpoint and send the primary packet to outdev. πŸ”

In order to improve efficiency, we need to put the task of comparison in another iothread; the iothread option specifies that iothread object (which your commandline should create).

  • vnet_hdr_support tells colo compare to pass the vnet header length when it sends and receives packets.
  • compare_timeout sets the maximum time that colo-compare will hold the packet for, in ms.
  • expired_scan_cycle sets the period of scanning expired primary node network packets, in ms.
  • max_queue_size sets the max compare queue size.

If you want to use Xen COLO, you need to specify notify_dev to tell colo-compare how to notify Xen colo-frame to do a checkpoint.

important vibe check: COLO-compare must be used with the help of filter-mirror, filter-redirector and filter-rewriter. πŸ’€

KVM COLO

okay bestie, here's the actual invocation for that colo-compare setup β€” primary side first, and every single flag is doing its job πŸ’…

primary:
-netdev tap,id=hn0,vhost=off
-device e1000,id=e0,netdev=hn0,mac=52:a4:00:12:78:66
-chardev socket,id=mirror0,host=3.3.3.3,port=9003,server=on,wait=off
-chardev socket,id=compare1,host=3.3.3.3,port=9004,server=on,wait=off
-chardev socket,id=compare0,host=3.3.3.3,port=9001,server=on,wait=off
-chardev socket,id=compare0-0,host=3.3.3.3,port=9001
-chardev socket,id=compare_out,host=3.3.3.3,port=9005,server=on,wait=off
-chardev socket,id=compare_out0,host=3.3.3.3,port=9005
-object iothread,id=iothread1
-object filter-mirror,id=m0,netdev=hn0,queue=tx,outdev=mirror0
-object filter-redirector,netdev=hn0,id=redire0,queue=rx,indev=compare_out
-object filter-redirector,netdev=hn0,id=redire1,queue=rx,outdev=compare0
-object colo-compare,id=comp0,primary_in=compare0-0,secondary_in=compare1,outdev=compare_out0,iothread=iothread1

and the secondary side, which is giving "yes queen, mirror me" energy πŸͺžβœ¨

secondary:
-netdev tap,id=hn0,vhost=off
-device e1000,netdev=hn0,mac=52:a4:00:12:78:66
-chardev socket,id=red0,host=3.3.3.3,port=9003
-chardev socket,id=red1,host=3.3.3.3,port=9004
-object filter-redirector,id=f1,netdev=hn0,queue=tx,indev=red0
-object filter-redirector,id=f2,netdev=hn0,queue=rx,outdev=red1

Xen COLO 🧚 β€” now the Xen flavour. It's this close to the one above, except it also spins up a notify_way chardev on port 9009 and hands notify_dev=notify_way to colo-compare so the two sides can gossip πŸ‘€

primary:
-netdev tap,id=hn0,vhost=off
-device e1000,id=e0,netdev=hn0,mac=52:a4:00:12:78:66
-chardev socket,id=mirror0,host=3.3.3.3,port=9003,server=on,wait=off
-chardev socket,id=compare1,host=3.3.3.3,port=9004,server=on,wait=off
-chardev socket,id=compare0,host=3.3.3.3,port=9001,server=on,wait=off
-chardev socket,id=compare0-0,host=3.3.3.3,port=9001
-chardev socket,id=compare_out,host=3.3.3.3,port=9005,server=on,wait=off
-chardev socket,id=compare_out0,host=3.3.3.3,port=9005
-chardev socket,id=notify_way,host=3.3.3.3,port=9009,server=on,wait=off
-object filter-mirror,id=m0,netdev=hn0,queue=tx,outdev=mirror0
-object filter-redirector,netdev=hn0,id=redire0,queue=rx,indev=compare_out
-object filter-redirector,netdev=hn0,id=redire1,queue=rx,outdev=compare0
-object iothread,id=iothread1
-object colo-compare,id=comp0,primary_in=compare0-0,secondary_in=compare1,outdev=compare_out0,notify_dev=notify_way,iothread=iothread1
secondary:
-netdev tap,id=hn0,vhost=off
-device e1000,netdev=hn0,mac=52:a4:00:12:78:66
-chardev socket,id=red0,host=3.3.3.3,port=9003
-chardev socket,id=red1,host=3.3.3.3,port=9004
-object filter-redirector,id=f1,netdev=hn0,queue=tx,indev=red0
-object filter-redirector,id=f2,netdev=hn0,queue=rx,outdev=red1
if you're sitting here like "okay but what do all those lines mean" β€” the manpage says: if you want to know the detail of above command line, you can read the colo-compare git log. that's it, that's the hint 🫢

πŸŽ€ -object cryptodev-backend-builtin,id=id[,queues=queues]

makes a cryptodev backend that runs crypto operations straight from the QEMU cipher APIs πŸ”₯ the id is a unique ID you'll use later to reference this backend from the virtio-crypto device. queues is optional and sets the queue number of the cryptodev backend β€” default queues is 1.

# qemu-kvm \
  [...] \
      -object cryptodev-backend-builtin,id=cryptodev0 \
      -device virtio-crypto-pci,id=crypto0,cryptodev=cryptodev0 \
  [...]

🌸 -object cryptodev-vhost-user,id=id,chardev=chardevid[,queues=queues]

makes a vhost-user cryptodev backend, backed by a chardev called chardevid ✨ id is a unique ID you'll reference from the virtio-crypto device. heads up: the chardev should be a unix domain socket backed one β€” vhost-user uses a specifically defined protocol to pass vhost ioctl replacement messages to an application on the other end of that socket. queues is optional and sets the queue number of the cryptodev backend for multiqueue vhost-user; default is 1.

# qemu-kvm \
  [...] \
      -chardev socket,id=chardev0,path=/path/to/socket \
      -object cryptodev-vhost-user,id=cryptodev0,chardev=chardev0 \
      -device virtio-crypto-pci,id=crypto0,cryptodev=cryptodev0 \
  [...]

πŸ’œ -object secret,id=id,data=string,format=raw|base64[,keyid=secretid,iv=string]

πŸ’œ -object secret,id=id,file=filename,format=raw|base64[,keyid=secretid,iv=string]

defines a secret β€” a password, an encryption key, or whatever else is sensitive πŸ” the sensitive data goes either directly in the data parameter or indirectly via the file parameter. and ngl, using data is insecure unless the sensitive data is already encrypted.

you can hand over that sensitive data in raw format (the default) or base64. when it's encoded as JSON, the raw format only supports valid UTF-8 characters, so base64 is the recommended move for sending binary data πŸ“¦ QEMU converts from whichever format you gave it into the format it needs internally β€” eg, an RBD password can be provided in raw format, even though it'll be base64 encoded when passed onto the RBD sever.

for extra protection you can encrypt the data tied to a secret using the AES-256-CBC cipher πŸ›‘οΈ you signal encryption by providing keyid and iv. the keyid parameter gives the ID of a previously defined secret that holds the AES-256 decryption key β€” that key should be 32 bytes long and base64 encoded. the iv parameter gives the random initialization vector used for encrypting this particular secret, and should be a base64 encrypted string of the 16-byte IV.

the simplest (insecure πŸ™ˆ) usage is putting the secret inline:

# qemu-kvm -object secret,id=sec0,data=letmein,format=raw

the simplest secure usage is handing the secret over via a file:

# printf "letmein" > mypasswd.txt
# QEMU_SYSTEM_MACRO -object secret,id=sec0,file=mypasswd.txt,format=raw

for greater security, AES-256-CBC should be used πŸ’ͺ to illustrate, consider the openssl command line tool, which can encrypt the data. note that when encrypting, the plaintext must be padded to the cipher block size (32 bytes) using the standard PKCS#5/6 compatible padding algorithm.

first a master key needs to be created in base64 encoding:

# openssl rand -base64 32 > key.b64
# KEY=$(base64 -d key.b64 | hexdump  -v -e '/1 "%02X"')

each secret to be encrypted needs a random initialization vector generated. these do not need to be kept secret πŸ‘€

# openssl rand -base64 16 > iv.b64
# IV=$(base64 -d iv.b64 | hexdump  -v -e '/1 "%02X"')

now the secret to be defined can be encrypted β€” here we're telling openssl to base64 encode the result, but it could be left as raw bytes if you'd rather:

# SECRET=$(printf "letmein" |
           openssl enc -aes-256-cbc -a -K $KEY -iv $IV)

when launching QEMU, create a master secret pointing to key.b64 and say that's the one to decrypt the user password with. pass the contents of iv.b64 to the second secret 🌈

# qemu-kvm \
    -object secret,id=secmaster0,format=base64,file=key.b64 \
    -object secret,id=sec0,keyid=secmaster0,format=base64,\
        data=$SECRET,iv=$(<iv.b64)

πŸ‘‘ -object sev-guest,id=id,cbitpos=cbitpos,reduced-phys-bits=val,[sev-device=string,policy=policy,handle=handle,dh-cert-file=file,session-file=file,kernel-hashes=on|off]

creates a Secure Encrypted Virtualization (SEV) guest object, which you can use to get guest memory encryption support on AMD processors πŸ”₯

when memory encryption is on, one of the physical address bits (aka the C-bit) is utilized to mark whether a memory page is protected 🧐 cbitpos provides the C-bit position. the C-bit position is Host family dependent, hence the user must provide this value. on EPYC, the value should be 47.

when memory encryption is on, we loose certain bits in physical address space. reduced-phys-bits provides the number of bits we loose in physical address space β€” like the C-bit, this is Host family dependent. on EPYC, a guest will lose a maximum of 1 bit, so the value should be 1.

sev-device gives the device file used to talk to the SEV firmware running inside the AMD Secure Processor. default device is /dev/sev β€” if the hardware supports memory encryption then /dev/sev devices are created by the CCP driver.

policy gives the guest policy that the SEV firmware enforces, restricting what configuration and operational commands the hypervisor can perform on this guest 🚫 the policy should be provided by the guest owner and is bound to the guest β€” it can't be changed throughout the lifetime of the guest. the default is 0.

If the guest policy lets your SEV guest share its key with another SEV guest, then handle is how you pass in the handle of the guest you're sharing from. iykyk πŸ”‘

The dh-cert-file and session-file are where the guest owner's Public Diffie-Hellman key (as defined in the SEV spec) lives. The PDH and session params get used to set up a cryptographic session with the guest owner so y'all can negotiate the keys used for attestation. Both files must be base64 encoded β€” no cap, this is not a suggestion. 🧚

And kernel-hashes adds the hashes of your given kernel/initrd/cmdline to a designated guest firmware page, which is what you want for measured Linux boot with -kernel. Default is off. (Since 6.2) ✨

Like, e.g., to launch a SEV guest:

# qemu-kvm \
    ...... \
    -object sev-guest,id=sev0,cbitpos=47,reduced-phys-bits=1 \
    -machine ...,confidential-guest-support=sev0 \
    .....

πŸ‘‘ -object tdx-guest,id=id,[attributes=attrs,sept-ve-disable=on|off,mrconfigid=sha384_digest,mrowner=sha384_digest,mrownerconfig=sha384_digest,quote-generation-socket=socketaddr]

Bestie, this one creates an Intel Trusted Domain eXtensions (TDX) guest object β€” which is the confidential-guest-support type of object. Then when you pass the object ID to the machine's confidential-guest-support property, boom πŸ’₯ you've got a TDX guest.

  • attributes β€” a 64-bit integer that specifies the TD attributes of the TD.
  • sept-ve-disable β€” controls bit 28 of the TD attributes, specifically that bit. When it's on, the EPT violation conversion to #VE on guest access of PENDING pages is disabled. Some guest OSes (e.g., a Linux TD guest) may require this to be set, otherwise they flat-out refuse to boot. Default value is on. πŸ™ˆ
  • mrconfigid β€” a base64 encoded SHA384 digest that provides the ID for the non-owner-defined configuration of the guest TD, e.g., run-time or OS configuration. Default value is all zeros.
  • mrowner β€” a base64 encoded SHA384 digest that provides the ID for the guest TD's owner. Default value is all zeros.
  • mrownerconfig β€” a base64 encoded SHA384 digest that provides the ID for owner-defined configuration of the guest TD, e.g., the configuration specific to the workload rather than the run-time of the OS. Default value is all zeros.
  • quote-generation-socket β€” specifies the socket address of the Quote Generation Service (QGS). QGS is a daemon running on the host. QEMU forwards the <GetQuote> request from the TD guest to QGS, then sends the reply (which contains the generated QUOTE on success) from QGS back to the guest TD. πŸŽ€
# qemu-kvm \
    ...... \
    -object '{"qom-type":"tdx-guest","id":"tdx","quote-generation-socket":{"type":"unix","path":"/var/run/qgs.socket"}}' \
    -machine ...,confidential-guest-support=tdx \
    ......

πŸ¦‹ -object igvm-cfg,file=file

Creates an IGVM configuration object that defines the initial state of the guest using a file that conforms to the Independent Guest Virtual Machine (IGVM) file format. Literally giving "I brought my own initial state" energy. ✨

Currently it's only supported by -machine q35 and -machine pc β€” so don't come at it with anything else, it's not gonna slay for you.

The file parameter is what you use to specify the IGVM file to load. When provided, the IGVM file is used to populate the initial memory of the virtual machine and, depending on the platform, can define the initial processor state, memory map and parameters.

Heads up bestie: the IGVM file is expected to contain the firmware for the virtual machine, so an igvm-cfg object cannot be provided along with other ways of specifying firmware, such as the -bios parameter on x86 machines. Pick a lane. πŸ’…

e.g. to launch a machine providing the firmware in an IGVM file:

# qemu-kvm \
    ...... \
    -object igvm-cfg,id=igvm0,file=bios.igvm \
    -machine ...,igvm-cfg=igvm0 \
    .....

🌸 -object authz-simple,id=id,identity=string

Creates an authorization object that controls access to network services. Security era. πŸ”

The identity parameter identifies the user, and its format depends on the network service that the authorization object is associated with. For authorizing based on TLS x509 certificates, the identity must be the x509 distinguished name. Note that care must be taken to escape any commas in the distinguished name β€” commas are out here causing chaos fr fr.

An example authorization object to validate an x509 distinguished name would look like:

# qemu-kvm \
    ... \
    -object 'authz-simple,id=auth0,identity=CN=laptop.example.com,,O=Example Org,,L=London,,ST=London,,C=GB' \
    ...

Note the use of quotes due to the x509 distinguished name containing whitespace, and the escaping of ','. 🫢

πŸ“ -object authz-listfile,id=id,filename=path,refresh=on|off

Creates an authorization object that controls access to network services. Same vibe, different delivery. ✨

The filename parameter is the fully qualified path to a file containing the access control list rules in JSON format.

An example set of rules that match against SASL usernames might look like:

{
  "rules": [
     { "match": "fred", "policy": "allow", "format": "exact" },
     { "match": "bob", "policy": "allow", "format": "exact" },
     { "match": "danb", "policy": "deny", "format": "glob" },
     { "match": "dan*", "policy": "allow", "format": "exact" },
  ],
  "policy": "deny"
}

When checking access, the object iterates over all the rules and the first rule to match has its policy value returned as the result. If no rules match, then the default policy value is returned. First come, first served, periodt. πŸ’…

The rules can either be an exact string match, or they can use simple UNIX glob pattern matching to allow wildcards to be used.

If refresh is set to true, the file will be monitored and automatically reloaded whenever its content changes. Set it and forget it, iconic behaviour honestly. πŸŽ€

As with the authz-simple object, the format of the identity strings being matched depends on the network service, but it's usually a TLS x509 distinguished name, or a SASL username.

An example authorization object to validate a SASL username would look like:

# qemu-kvm \
    ... \
    -object authz-simple,id=auth0,filename=/etc/qemu/vnc-sasl.acl,refresh=on \
    ...

πŸ’œ -object authz-pam,id=id,service=string

Creates an authorization object that controls access to network services. Third flavour of the same delicious thing. 🌈

The service parameter provides the name of a PAM service to use for authorization. It requires that a file /etc/pam.d/service exist to provide the configuration for the account subsystem.

An example authorization object to validate a TLS x509 distinguished name would look like:

# qemu-kvm \
    ... \
    -object authz-pam,id=auth0,service=qemu-vnc \
    ...

There would then be a corresponding config file for PAM at /etc/pam.d/qemu-vnc that contains:

account requisite  pam_listfile.so item=user sense=allow \
           file=/etc/qemu/vnc.allow

Finally the /etc/qemu/vnc.allow file would contain the list of x509 distinguished names that are permitted access:

CN=laptop.example.com,O=Example Home,L=London,ST=London,C=GB

πŸ”₯ -object iothread,id=id,poll-max-ns=poll-max-ns,poll-grow=poll-grow,poll-shrink=poll-shrink,poll-weight=poll-weight,aio-max-batch=aio-max-batch

Creates a dedicated event loop thread that devices can be assigned to. This is known as an IOThread, and honestly it's main character energy for scaling. By default, device emulation happens in vCPU threads or the main event loop thread, and that can become a scalability bottleneck. IOThreads let device emulation and I/O run on other host CPUs. Slay. πŸ‘‘

The id parameter is a unique ID that's used to reference this IOThread from -device ...,iothread=id. Multiple devices can be assigned to a single IOThread. Note that not all devices support an iothread parameter β€” check before you commit, bestie. πŸ™ˆ

The query-iothreads QMP command lists IOThreads and reports their thread IDs, so you can configure host CPU pinning/affinity. πŸ’…

IOThreads use an adaptive polling algorithm to reduce event loop latency. Instead of entering a blocking system call to monitor file descriptors and then paying the cost of being woken up when an event occurs, the polling algorithm spins waiting for events for a short time. The algorithm's default parameters are suitable for many cases, but can be adjusted based on knowledge of the workload and/or host device latency.

  • poll-max-ns β€” the maximum number of nanoseconds to busy wait for events. Polling can be disabled by setting this value to 0.
  • poll-grow β€” the multiplier used to increase the polling time when the algorithm detects it's missing events due to not polling long enough.
  • poll-shrink β€” the divisor used to decrease the polling time when the algorithm notices it's been polling foreverrr without actually catching any events 😴 like bestie read the room.
  • poll-weight β€” the weight factor for adaptive polling. It decides how much the most recent event interval affects the next polling duration calculation. If you set it to 0, the system default value of 3 is used. Typical values: 1 (high weight on recent interval), 2-4 (moderate weight on recent interval) πŸ’…
  • aio-max-batch β€” the maximum number of requests in a batch for the AIO engine. 0 means the engine will use its default ✨

The IOThread parameters can be modified at run-time using the qom-set command (where iothread1 is the IOThread's id):

(qemu) qom-set /objects/iothread1 poll-max-ns 100000

πŸŽ€ MULTIPLEXER KEYS πŸŽ€

During the graphical emulation, you can use special key combinations from the following table to change modes. By default the modifier is Ctrl+Alt (used in the table below) which can be changed with -display suboption mod= where appropriate. For example, -display sdl,grab-mod=lshift-lctrl-lalt changes the modifier key to Ctrl+Alt+Shift, while -display sdl,grab-mod=rctrl changes it to the right Ctrl key πŸ‘‘

  • Ctrl+Alt+f β€” Toggle full screen πŸ–₯️✨
  • Ctrl+Alt++ β€” Enlarge the screen
  • Ctrl+Alt+- β€” Shrink the screen
  • Ctrl+Alt+0 β€” Restore the screen's un-scaled dimensions
  • Ctrl+Alt+n β€” Switch to virtual console 'n'. Standard console mappings are:
    • 1: Target system display
    • 2: Monitor
    • 3: Serial port
  • Ctrl+Alt+g β€” Toggle mouse and keyboard grab πŸ–±οΈ

In the virtual consoles, you can use Ctrl+Up, Ctrl+Down, Ctrl+PageUp and Ctrl+PageDown to move in the back log πŸ“œ no cap, that's how you scroll back.


⌨️ MULTIPLEXER KEYS ⌨️ <span>(yes, again β€” this is the other multiplexer, iykyk)</span>

During emulation, if you are using a character backend multiplexer (which is the default if you are using -nographic) then several commands are available via an escape sequence. These key sequences all start with an escape character, which is Ctrl+a by default, but can be changed with -echr. The list below assumes you're using the default πŸ’œ

  • Ctrl+a h β€” Print this help
  • Ctrl+a x β€” Exit emulator πŸšͺ
  • Ctrl+a s β€” Save disk data back to file (if -snapshot)
  • Ctrl+a t β€” Toggle console timestamps ⏱️
  • Ctrl+a b β€” Send break (magic sysrq in Linux) πŸ’€
  • Ctrl+a c β€” Rotate between the frontends connected to the multiplexer (usually this switches between the monitor and the console) πŸ”„
  • Ctrl+a Ctrl+a β€” Send the escape character to the frontend

πŸ“ NOTES πŸ“

In addition to using normal file images for the emulated storage devices, QEMU can also use networked resources such as iSCSI devices. These are specified using a special URL syntax πŸ¦‹

πŸ“ iSCSI

iSCSI support allows QEMU to access iSCSI resources directly and use as images for the guest storage. Both disk and cdrom images are supported πŸ’Ύβœ¨

Syntax for specifying iSCSI LUNs is:

"iscsi://<target-ip>[:<port>]/<target-iqn>/<lun>"

By default qemu will use the iSCSI initiator-name 'iqn.2008-11.org.linux-kvm[:<name>]' but this can also be set from the command line or a configuration file πŸ‘‘

Since version QEMU 2.4 it is possible to specify a iSCSI request timeout to detect stalled requests and force a reestablishment of the session. The timeout is specified in seconds. The default is 0 which means no timeout. Libiscsi 1.15.0 or greater is required for this feature ⚠️ like fr, check your libiscsi version first.

Example (without authentication):

qemu-kvm -iscsi initiator-name=iqn.2001-04.com.example:my-initiator \
         -cdrom iscsi://192.0.2.1/iqn.2001-04.com.example/2 \
         -drive file=iscsi://192.0.2.1/iqn.2001-04.com.example/1

Example (CHAP username/password via URL):

qemu-kvm -drive file=iscsi://user%password@192.0.2.1/iqn.2001-04.com.example/1

Example (CHAP username/password via environment variables):

LIBISCSI_CHAP_USERNAME="user" \
LIBISCSI_CHAP_PASSWORD="password" \
qemu-kvm -drive file=iscsi://192.0.2.1/iqn.2001-04.com.example/1

🌈 NBD

QEMU supports NBD (Network Block Devices) both using TCP protocol as well as Unix Domain Sockets. With TCP, the default port is 10809 πŸ”Œ

Syntax for specifying a NBD device using TCP, in preferred URI form:

"nbd://<server-ip>[:<port>]/[<export>]"

Syntax for specifying a NBD device using Unix Domain Sockets; remember that '?' is a shell glob character and may need quoting:

"nbd+unix:///[<export>]?socket=<domain-socket>"

Older syntax that is also recognized:

"nbd:<server-ip>:<port>[:exportname=<export>]"

Syntax for specifying a NBD device using Unix Domain Sockets

"nbd:unix:<domain-socket>[:exportname=<export>]"

Example for TCP

qemu-kvm --drive file=nbd:192.0.2.1:30000

Example for Unix Domain Sockets

qemu-kvm --drive file=nbd:unix:/tmp/nbd-socket

🧚 SSH

QEMU supports SSH (Secure Shell) access to remote disks πŸ”

Examples:

qemu-kvm -drive file=ssh://user@host/path/to/disk.img
qemu-kvm -drive file.driver=ssh,file.user=user,file.host=host,file.port=22,file.path=/path/to/disk.img

Currently authentication must be done using ssh-agent. Other authentication methods may be supported in future πŸ‘€

πŸ¦‹ HTTP/HTTPS/FTP/FTPS

QEMU supports read-only access to files accessed over http(s) and ftp(s) πŸ“– (read-only bestie, don't try to write, it's not gonna happen).

Syntax using a single filename:

<protocol>://[<username>[:<password>]@]<host>/<path>

where:

  • protocol β€” 'http', 'https', 'ftp', or 'ftps'.
  • username β€” Optional username for authentication to the remote server.
  • password β€” Optional password for authentication to the remote server πŸ”‘ (maybe don't put this in your shell history, just saying).
  • host β€” Address of the remote server.
  • path β€” Path on the remote server, including any query string.

The following options are also supported, bestie β€” these are the extra lil knobs for the remote-driver vibe:

  • url β€” the full URL, used when you're passing options to the driver explicitly ✨
  • readahead β€” how much data to read ahead with each range request to the remote server. This value can optionally wear a suffix: 'T', 'G', 'M', 'K', 'k' or 'b'. No suffix? Then it's assumed to be in bytes, no cap. The value must be a multiple of 512 bytes. Defaults to 256k πŸŽ€
  • sslverify β€” whether to verify the remote server's certificate when connecting over SSL. Takes the value 'on' or 'off'. Defaults to 'on' β€” keep it on, she's protecting you πŸ’…
  • cookie β€” send this cookie (it can also be a list of cookies separated by ';') with each outgoing request. Only supported when using protocols like HTTP that actually support cookies β€” otherwise it's just ignored, no hard feelings πŸ™ˆ
  • timeout β€” sets the timeout in seconds of the CURL connection. This timeout is the time that CURL waits for a response from the remote server to get the size of the image to be downloaded. Not set? Then the default timeout of 5 seconds is used ⏱️
  • force-range β€” don't issue a HEAD HTTP request to discover if the http server server supports range requests, and rely only on GET requests. This is especially useful for S3 presigned URLs where HEAD requests are unauthorized. Defaults to 'false' πŸ”₯
Heads up bestie: when you're passing options to qemu explicitly, driver is the value of <protocol>. That's just how it is, iykyk πŸ’–

Example: boot from a remote Fedora 20 live ISO image 🌸

qemu-kvm --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

qemu-kvm --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

Example: boot from a remote Fedora 20 cloud image using a local overlay for writes, copy-on-read, and a readahead of 64k πŸ¦‹

qemu-img create -f qcow2 -o backing_file='json:{"file.driver":"http",, "file.url":"http://archives.fedoraproject.org/pub/archive/fedora/linux/releases/20/Images/x86_64/Fedora-x86_64-20-20131211.1-sda.qcow2",, "file.readahead":"64k"}' /tmp/Fedora-x86_64-20-20131211.1-sda.qcow2

qemu-kvm -drive file=/tmp/Fedora-x86_64-20-20131211.1-sda.qcow2,copy-on-read=on

Example: boot from an image stored on a VMware vSphere server with a self-signed certificate using a local overlay for writes, a readahead of 64k and a timeout of 10 seconds. 🧚

qemu-img create -f qcow2 -o backing_file='json:{"file.driver":"https",, "file.url":"https://user:password@vsphere.example.com/folder/test/test-flat.vmdk?dcPath=Datacenter&dsName=datastore1",, "file.sslverify":"off",, "file.readahead":"64k",, "file.timeout":10}' /tmp/test.qcow2

qemu-kvm -drive file=/tmp/test.qcow2

🌈 SEE ALSO 🌈

The HTML documentation of QEMU for more precise information, plus Linux user mode emulator invocation. Go read the HTML docs, they're giving main character reference material energy πŸ‘‘


πŸ’œ AUTHOR πŸ’œ

Fabrice Bellard β€” the icon himself, periodt.


2026, The QEMU Project Developers


okay that's a wrap on the whole page, bestie!! 🫢 you just read the entire QEMU(1) man page, all 26 parts, and honestly? obsessed. this edition is version 11.1.0, dated Oct 26, 2026, and it's the QEMU(1) page β€” go forth and virtualize, slay, and remember: read the docs, verify your certs, and never skip the readahead πŸ’…βœ¨

πŸ“¦ where this page comes from