Rate This Document
Findability
Accuracy
Completeness
Readability

Compiling QEMU and Applying the Feature

The QEMU VM memory hotplug feature only supports QEMU 6.2.0. Obtain the QEMU 6.2.0 source code, apply the patch file for QEMU VM memory hotplug, and compile the QEMU source code. The memory hotplug feature is successfully applied.

The feature installation involves system file modification. By default, all operations during the installation are performed by the root user. If you are a non-root user, ensure that you have corresponding permissions.

  1. Compile and install the dependency packages required by QEMU.
    yum -y install gcc gcc-c++ automake make python3 bzip2-devel zlib-devel glib2-devel pixman-devel librbd-devel openssl-devel spice*
  2. Obtain the QEMU source code that matches openEuler 22.03 LTS SP4.
    git clone -b v6.2.0 --depth=1 https://git.qemu.org/git/qemu.git
  3. Create a branch of the QEMU source code and switch the branch to the v6.2.0 version.
    cd qemu
    git branch v6.2.0_patched v6.2.0
    git checkout v6.2.0_patched
  4. Ensure that the QEMU source code directory is at the same level as the patch file (for enabling the feature) directory, and upload the patch file to the compilation environment.

    For details about how to obtain the patch file, see Table 2.

  5. In the QEMU source directory, apply the patch file to the QEMU source code.
    1. Check the latest commit record of the original QEMU v6.2.0.
      git log -n 2
    2. Check whether the patch file Add-Support-for-numa-being-initialized-with-mem-0-an.patch can be successfully applied to the current code library. Configure the actual patch file path as required and ensure that the corresponding patch file exists.
      git apply --check ../Add-Support-for-numa-being-initialized-with-mem-0-an.patch

      If no error is returned, the patch file is compatible with the current code library for normal application.

    3. Apply the patch file to the current branch.
      git am ../Add-Support-for-numa-being-initialized-with-mem-0-an.patch
    4. After applying the patch file, check the latest commit record again.
      git log -n 2

      If the latest commit record is updated, the patch file is successfully applied.

      If git apply is used to apply the patch file, no new commit record is created. If no error message is returned, the patch file is successfully applied.

      Once the patch file is successfully applied, the QEMU source code in the current directory already contains the QEMU VM memory hotplug feature. Prepare to compile QEMU.

  6. Compile QEMU.
    rm -rf build && mkdir build
    cd build/
    ../configure --disable-werror --enable-spice --enable-spice-protocol  --target-list=aarch64-softmmu --cc="gcc" --extra-cflags="-Wno-error" --disable-docs --enable-virtfs --enable-numa
    make -j 64

    In the preceding command, make -j 64 indicates that 64 threads are executed at the same time. You can adjust this value based on the number of CPU cores or available resources.

  7. Install and deploy QEMU in the build directory.
    make install

    After QEMU is deployed, the QEMU VM memory hotplug feature has been successfully applied in the environment. After the feature is applied, it is enabled by default.

    When using an XML file to define a VM, you need to add the <emulator> node under the <devices> node in the XML file and point the path of <emulator> to the QEMU executable file installed just now. In this example, add the following content:

    <emulator>/usr/local/bin/qemu-system-aarch64</emulator>