# Create secondary virtual machine

This section provides the steps for creating virtual machine (VM)
images using the Qualcomm Linux build system.

To use a virtual machine with Qualcomm Linux, ensure that the image recipes include the
virtual machine manager (VMM) tools, and generate the Guest VM kernel and root file system images.

The following procedure provides a step-by-step guide for the following:

> 
> 
> - Include essential VMM tools, such as `crosvm` and `qemu`
> in the image recipes already defined in Qualcomm Linux.
> - Use commands to build Guest VM kernel and root file system images.
> - Use commands to launch the Guest VM.

## Set up the development machine

1. Install clang on the host development machine.

    To install clang on the host development machine, run the following command:

sudo apt install clang-11
        Copy to clipboard
2. Enable the meta-rust layer in the Qualcomm Linux environment.

    The meta-rust layer provides Rust compiler (rustc) and package
manager (cargo) to compile crosvm, which is implemented in the Rust
language.

    Add the meta-rust layer to EXTRALAYERS in the
`meta-qcom-distro/conf/bblayers.conf` file.

    Open the `conf/bblayers.conf` file and add the layer path to `EXTRALAYERS` variable as follows:

EXTRALAYERS ?= " \
        ${WORKSPACE}/layers/meta-rust \
        "
        Copy to clipboard
3. Include Rust from meta-rust in build.

    Create the `meta-qcom-distro/conf/distro/include/rust_version.inc` file with the following content:

# include this in your distribution to easily switch between versions
        # just by changing RUST_VERSION variable
        
        RUST_VERSION ?= "1.73.0"
        
        PREFERRED_VERSION_cargo ?= "${RUST_VERSION}"
        PREFERRED_VERSION_cargo-native ?= "${RUST_VERSION}"
        PREFERRED_VERSION_libstd-rs ?= "${RUST_VERSION}"
        PREFERRED_VERSION_rust ?= "${RUST_VERSION}"
        PREFERRED_VERSION_rust-cross-${TARGET_ARCH} ?= "${RUST_VERSION}"
        PREFERRED_VERSION_rust-llvm ?= "${RUST_VERSION}"
        PREFERRED_VERSION_rust-llvm-native ?= "${RUST_VERSION}"
        PREFERRED_VERSION_rust-native ?= "${RUST_VERSION}"
        Copy to clipboard

    Include the `rust_version.inc` file in the
`meta-qcom-distro/conf/distro/qcom-wayland.conf` file
as follows:

require conf/distro/include/rust_version.inc
        Copy to clipboard

## Add crosvm tool to Qualcomm Linux images

To add the crosvm tool to the images built by Qualcomm Linux, edit the `meta-qcom-distro/recipes-products/packagegroups/packagegroup-qcom-vm-host.bb` package group recipe file and add the following code block:

RDEPENDS:packagegroup-qcom-vm-host:append:qcom-custom-bsp = "\
       crosvm \
       "
    Copy to clipboard

## Build the image recipe and the Guest VM images

1. To build an existing Qualcomm Linux image recipe, run the `bitbake <image>` command. This includes the crosvm tool in the image generated.
For example, for `qcom-console-image` run the following command:

bitbake qcom-console-image
        Copy to clipboard
2. To build a Guest VM image, run the following command:

bitbake multiconfig:qcom-guestvm:qcom-guestvm-image
        Copy to clipboard

### Guest VM artifacts

After the Guest VM image is successfully created, you can find the following artifacts:

> 
> 
> 1. The Guest VM build command creates a folder named `tmp-qcom-guestvm-glibc` for the Guest VM image.
> 2. The Guest VM kernel and rootfs images are generated in the `tmp-qcom-guestvm-glibc/deploy/images/<machine-name>` directory.
> 3. The `tmp-qcom-guestvm-glibc/deploy/images/<machine-name>/Image` file is the Guest VM kernel image.
> 4. The `tmp-qcom-guestvm-glibc/deploy/images/<machine-name>/qcom-guestvm-image-<machine-name>.ext4` file is the Guest VM root file system image.
> 5. After flashing the images created by the `bitbake <image>` command and booting up the device, copy the Guest VM kernel and root file system images to the device, for example, under the `/var/gunyah` directory.

## Launch Guest VM

1. To launch Guest VM, use the crosvm VMM tool.
2. In the following command, the Guest VM kernel and the root file system images are from the `/var/gunyah` directory on the device.

crosvm --log-level=debug --no-syslog run --disable-sandbox --hypervisor gunyah --protected-vm-without-firmware \
        --serial=type=stdout,hardware=virtio-console,console,stdin,num=1 --serial=type=stdout,hardware=serial,earlycon,num=1 \
        --root /var/gunyah/qcom-guestvm-image-qcs9100-ride-sx.ext4 --no-balloon --no-rng --params \
        "earlyprintk=serial panic=0" /var/gunyah/Image
        Copy to clipboard

    - The `--root /var/gunyah/qcom-guestvm-image-qcs9100-ride-sx.ext4` option specifies the path to the root file system for the Guest VM.
    - The last parameter `/var/gunyah/Image` is passed to the `crosvm` tool that specifies the path to the kernel image.

For more information, see [Enable virtualization](https://docs.qualcomm.com/bundle/publicresource/topics/80-70020-3/virtualization.html).

Last Published: Jul 02, 2025

[Previous Topic
Persist partition](https://docs.qualcomm.com/bundle/publicresource/80-70020-27/topics/persist_partition.md) [Next Topic
OTA update for Qualcomm Linux](https://docs.qualcomm.com/bundle/publicresource/80-70020-27/topics/ota_update_for_qualcomm_linux.md)