xref: /qemu/docs/system/introduction.rst (revision ca45a640b36e2bc7e3129293f3fcae5abc4c26f8)
12c46bc24SAlex BennéeIntroduction
22c46bc24SAlex Bennée============
32c46bc24SAlex Bennée
42c46bc24SAlex BennéeVirtualisation Accelerators
52c46bc24SAlex Bennée---------------------------
62c46bc24SAlex Bennée
72c46bc24SAlex BennéeQEMU's system emulation provides a virtual model of a machine (CPU,
82c46bc24SAlex Bennéememory and emulated devices) to run a guest OS. It supports a number
92c46bc24SAlex Bennéeof hypervisors (known as accelerators) as well as a JIT known as the
102c46bc24SAlex BennéeTiny Code Generator (TCG) capable of emulating many CPUs.
112c46bc24SAlex Bennée
122c46bc24SAlex Bennée.. list-table:: Supported Accelerators
132c46bc24SAlex Bennée  :header-rows: 1
142c46bc24SAlex Bennée
152c46bc24SAlex Bennée  * - Accelerator
162c46bc24SAlex Bennée    - Host OS
172c46bc24SAlex Bennée    - Host Architectures
182c46bc24SAlex Bennée  * - KVM
192c46bc24SAlex Bennée    - Linux
202c46bc24SAlex Bennée    - Arm (64 bit only), MIPS, PPC, RISC-V, s390x, x86
212c46bc24SAlex Bennée  * - Xen
222c46bc24SAlex Bennée    - Linux (as dom0)
232c46bc24SAlex Bennée    - Arm, x86
242c46bc24SAlex Bennée  * - Intel HAXM (hax)
252c46bc24SAlex Bennée    - Linux, Windows
262c46bc24SAlex Bennée    - x86
272c46bc24SAlex Bennée  * - Hypervisor Framework (hvf)
282c46bc24SAlex Bennée    - MacOS
292c46bc24SAlex Bennée    - x86 (64 bit only), Arm (64 bit only)
30*ca45a640SStefan Weil  * - Windows Hypervisor Platform (whpx)
312c46bc24SAlex Bennée    - Windows
322c46bc24SAlex Bennée    - x86
332c46bc24SAlex Bennée  * - NetBSD Virtual Machine Monitor (nvmm)
342c46bc24SAlex Bennée    - NetBSD
352c46bc24SAlex Bennée    - x86
362c46bc24SAlex Bennée  * - Tiny Code Generator (tcg)
372c46bc24SAlex Bennée    - Linux, other POSIX, Windows, MacOS
382c46bc24SAlex Bennée    - Arm, x86, Loongarch64, MIPS, PPC, s390x, Sparc64
392c46bc24SAlex Bennée
402c46bc24SAlex BennéeFeature Overview
412c46bc24SAlex Bennée----------------
422c46bc24SAlex Bennée
432c46bc24SAlex BennéeSystem emulation provides a wide range of device models to emulate
442c46bc24SAlex Bennéevarious hardware components you may want to add to your machine. This
452c46bc24SAlex Bennéeincludes a wide number of VirtIO devices which are specifically tuned
462c46bc24SAlex Bennéefor efficient operation under virtualisation. Some of the device
472c46bc24SAlex Bennéeemulation can be offloaded from the main QEMU process using either
482c46bc24SAlex Bennéevhost-user (for VirtIO) or :ref:`Multi-process QEMU`. If the platform
492c46bc24SAlex Bennéesupports it QEMU also supports directly passing devices through to
502c46bc24SAlex Bennéeguest VMs to eliminate the device emulation overhead. See
512c46bc24SAlex Bennée:ref:`device-emulation` for more details.
522c46bc24SAlex Bennée
532c46bc24SAlex BennéeThere is a full :ref:`featured block layer<Live Block Operations>`
542c46bc24SAlex Bennéewhich allows for construction of complex storage topology which can be
552c46bc24SAlex Bennéestacked across multiple layers supporting redirection, networking,
562c46bc24SAlex Bennéesnapshots and migration support.
572c46bc24SAlex Bennée
582c46bc24SAlex BennéeThe flexible ``chardev`` system allows for handling IO from character
592c46bc24SAlex Bennéelike devices using stdio, files, unix sockets and TCP networking.
602c46bc24SAlex Bennée
612c46bc24SAlex BennéeQEMU provides a number of management interfaces including a line based
622c46bc24SAlex Bennée:ref:`Human Monitor Protocol (HMP)<QEMU monitor>` that allows you to
632c46bc24SAlex Bennéedynamically add and remove devices as well as introspect the system
642c46bc24SAlex Bennéestate. The :ref:`QEMU Monitor Protocol<QMP Ref>` (QMP) is a well
652c46bc24SAlex Bennéedefined, versioned, machine usable API that presents a rich interface
662c46bc24SAlex Bennéeto other tools to create, control and manage Virtual Machines. This is
672c46bc24SAlex Bennéethe interface used by higher level tools interfaces such as `Virt
682c46bc24SAlex BennéeManager <https://virt-manager.org/>`_ using the `libvirt framework
692c46bc24SAlex Bennée<https://libvirt.org>`_.
702c46bc24SAlex Bennée
712c46bc24SAlex BennéeFor the common accelerators QEMU, supported debugging with its
722c46bc24SAlex Bennée:ref:`gdbstub<GDB usage>` which allows users to connect GDB and debug
732c46bc24SAlex Bennéesystem software images.
742c46bc24SAlex Bennée
752c46bc24SAlex BennéeRunning
762c46bc24SAlex Bennée-------
772c46bc24SAlex Bennée
782c46bc24SAlex BennéeQEMU provides a rich and complex API which can be overwhelming to
792c46bc24SAlex Bennéeunderstand. While some architectures can boot something with just a
802c46bc24SAlex Bennéedisk image, those examples elide a lot of details with defaults that
812c46bc24SAlex Bennéemay not be optimal for modern systems.
822c46bc24SAlex Bennée
832c46bc24SAlex BennéeFor a non-x86 system where we emulate a broad range of machine types,
842c46bc24SAlex Bennéethe command lines are generally more explicit in defining the machine
852c46bc24SAlex Bennéeand boot behaviour. You will find often find example command lines in
862c46bc24SAlex Bennéethe :ref:`system-targets-ref` section of the manual.
872c46bc24SAlex Bennée
882c46bc24SAlex BennéeWhile the project doesn't want to discourage users from using the
892c46bc24SAlex Bennéecommand line to launch VMs, we do want to highlight that there are a
902c46bc24SAlex Bennéenumber of projects dedicated to providing a more user friendly
912c46bc24SAlex Bennéeexperience. Those built around the ``libvirt`` framework can make use
922c46bc24SAlex Bennéeof feature probing to build modern VM images tailored to run on the
932c46bc24SAlex Bennéehardware you have.
942c46bc24SAlex Bennée
952c46bc24SAlex BennéeThat said, the general form of a QEMU command line can be expressed
962c46bc24SAlex Bennéeas:
972c46bc24SAlex Bennée
982c46bc24SAlex Bennée.. parsed-literal::
992c46bc24SAlex Bennée
1002c46bc24SAlex Bennée  $ |qemu_system| [machine opts] \\
1012c46bc24SAlex Bennée                  [cpu opts] \\
1022c46bc24SAlex Bennée                  [accelerator opts] \\
1032c46bc24SAlex Bennée                  [device opts] \\
1042c46bc24SAlex Bennée                  [backend opts] \\
1052c46bc24SAlex Bennée                  [interface opts] \\
1062c46bc24SAlex Bennée                  [boot opts]
1072c46bc24SAlex Bennée
1082c46bc24SAlex BennéeMost options will generate some help information. So for example:
1092c46bc24SAlex Bennée
1102c46bc24SAlex Bennée.. parsed-literal::
1112c46bc24SAlex Bennée
1122c46bc24SAlex Bennée   $ |qemu_system| -M help
1132c46bc24SAlex Bennée
1142c46bc24SAlex Bennéewill list the machine types supported by that QEMU binary. ``help``
1152c46bc24SAlex Bennéecan also be passed as an argument to another option. For example:
1162c46bc24SAlex Bennée
1172c46bc24SAlex Bennée.. parsed-literal::
1182c46bc24SAlex Bennée
1192c46bc24SAlex Bennée  $ |qemu_system| -device scsi-hd,help
1202c46bc24SAlex Bennée
1212c46bc24SAlex Bennéewill list the arguments and their default values of additional options
1222c46bc24SAlex Bennéethat can control the behaviour of the ``scsi-hd`` device.
1232c46bc24SAlex Bennée
1242c46bc24SAlex Bennée.. list-table:: Options Overview
1252c46bc24SAlex Bennée  :header-rows: 1
1262c46bc24SAlex Bennée  :widths: 10, 90
1272c46bc24SAlex Bennée
1282c46bc24SAlex Bennée  * - Options
1292c46bc24SAlex Bennée    -
1302c46bc24SAlex Bennée  * - Machine
1312c46bc24SAlex Bennée    - Define the machine type, amount of memory etc
1322c46bc24SAlex Bennée  * - CPU
1332c46bc24SAlex Bennée    - Type and number/topology of vCPUs. Most accelerators offer
1342c46bc24SAlex Bennée      a ``host`` cpu option which simply passes through your host CPU
1352c46bc24SAlex Bennée      configuration without filtering out any features.
1362c46bc24SAlex Bennée  * - Accelerator
1372c46bc24SAlex Bennée    - This will depend on the hypervisor you run. Note that the
1382c46bc24SAlex Bennée      default is TCG, which is purely emulated, so you must specify an
1392c46bc24SAlex Bennée      accelerator type to take advantage of hardware virtualization.
1402c46bc24SAlex Bennée  * - Devices
1412c46bc24SAlex Bennée    - Additional devices that are not defined by default with the
1422c46bc24SAlex Bennée      machine type.
1432c46bc24SAlex Bennée  * - Backends
1442c46bc24SAlex Bennée    - Backends are how QEMU deals with the guest's data, for example
1452c46bc24SAlex Bennée      how a block device is stored, how network devices see the
1462c46bc24SAlex Bennée      network or how a serial device is directed to the outside world.
1472c46bc24SAlex Bennée  * - Interfaces
1482c46bc24SAlex Bennée    - How the system is displayed, how it is managed and controlled or
1492c46bc24SAlex Bennée      debugged.
1502c46bc24SAlex Bennée  * - Boot
1512c46bc24SAlex Bennée    - How the system boots, via firmware or direct kernel boot.
1522c46bc24SAlex Bennée
1532c46bc24SAlex BennéeIn the following example we first define a ``virt`` machine which is a
1542c46bc24SAlex Bennéegeneral purpose platform for running Aarch64 guests. We enable
1552c46bc24SAlex Bennéevirtualisation so we can use KVM inside the emulated guest. As the
1562c46bc24SAlex Bennée``virt`` machine comes with some built in pflash devices we give them
1572c46bc24SAlex Bennéenames so we can override the defaults later.
1582c46bc24SAlex Bennée
1592c46bc24SAlex Bennée.. code::
1602c46bc24SAlex Bennée
1612c46bc24SAlex Bennée $ qemu-system-aarch64 \
1622c46bc24SAlex Bennée    -machine type=virt,virtualization=on,pflash0=rom,pflash1=efivars \
1632c46bc24SAlex Bennée    -m 4096 \
1642c46bc24SAlex Bennée
1652c46bc24SAlex BennéeWe then define the 4 vCPUs using the ``max`` option which gives us all
1662c46bc24SAlex Bennéethe Arm features QEMU is capable of emulating. We enable a more
1672c46bc24SAlex Bennéeemulation friendly implementation of Arm's pointer authentication
1682c46bc24SAlex Bennéealgorithm. We explicitly specify TCG acceleration even though QEMU
1692c46bc24SAlex Bennéewould default to it anyway.
1702c46bc24SAlex Bennée
1712c46bc24SAlex Bennée.. code::
1722c46bc24SAlex Bennée
1732c46bc24SAlex Bennée -cpu max,pauth-impdef=on \
1742c46bc24SAlex Bennée -smp 4 \
1752c46bc24SAlex Bennée -accel tcg \
1762c46bc24SAlex Bennée
1772c46bc24SAlex BennéeAs the ``virt`` platform doesn't have any default network or storage
1782c46bc24SAlex Bennéedevices we need to define them. We give them ids so we can link them
1792c46bc24SAlex Bennéewith the backend later on.
1802c46bc24SAlex Bennée
1812c46bc24SAlex Bennée.. code::
1822c46bc24SAlex Bennée
1832c46bc24SAlex Bennée -device virtio-net-pci,netdev=unet \
1842c46bc24SAlex Bennée -device virtio-scsi-pci \
1852c46bc24SAlex Bennée -device scsi-hd,drive=hd \
1862c46bc24SAlex Bennée
1872c46bc24SAlex BennéeWe connect the user-mode networking to our network device. As
1882c46bc24SAlex Bennéeuser-mode networking isn't directly accessible from the outside world
1892c46bc24SAlex Bennéewe forward localhost port 2222 to the ssh port on the guest.
1902c46bc24SAlex Bennée
1912c46bc24SAlex Bennée.. code::
1922c46bc24SAlex Bennée
1932c46bc24SAlex Bennée -netdev user,id=unet,hostfwd=tcp::2222-:22 \
1942c46bc24SAlex Bennée
1952c46bc24SAlex BennéeWe connect the guest visible block device to an LVM partition we have
1962c46bc24SAlex Bennéeset aside for our guest.
1972c46bc24SAlex Bennée
1982c46bc24SAlex Bennée.. code::
1992c46bc24SAlex Bennée
2002c46bc24SAlex Bennée -blockdev driver=raw,node-name=hd,file.driver=host_device,file.filename=/dev/lvm-disk/debian-bullseye-arm64 \
2012c46bc24SAlex Bennée
2022c46bc24SAlex BennéeWe then tell QEMU to multiplex the :ref:`QEMU monitor` with the serial
2032c46bc24SAlex Bennéeport output (we can switch between the two using :ref:`keys in the
2042c46bc24SAlex Bennéecharacter backend multiplexer`). As there is no default graphical
2052c46bc24SAlex Bennéedevice we disable the display as we can work entirely in the terminal.
2062c46bc24SAlex Bennée
2072c46bc24SAlex Bennée.. code::
2082c46bc24SAlex Bennée
2092c46bc24SAlex Bennée -serial mon:stdio \
2102c46bc24SAlex Bennée -display none \
2112c46bc24SAlex Bennée
2122c46bc24SAlex BennéeFinally we override the default firmware to ensure we have some
2132c46bc24SAlex Bennéestorage for EFI to persist its configuration. That firmware is
2142c46bc24SAlex Bennéeresponsible for finding the disk, booting grub and eventually running
2152c46bc24SAlex Bennéeour system.
2162c46bc24SAlex Bennée
2172c46bc24SAlex Bennée.. code::
2182c46bc24SAlex Bennée
2192c46bc24SAlex Bennée -blockdev node-name=rom,driver=file,filename=(pwd)/pc-bios/edk2-aarch64-code.fd,read-only=true \
2202c46bc24SAlex Bennée -blockdev node-name=efivars,driver=file,filename=$HOME/images/qemu-arm64-efivars
221