Environment Preparation

Usage

  • StratoVirt can run on VMs with the x86_64 or AArch64 processor architecture.
  • You are advised to compile, debug, and deploy StratoVirt on openEuler 22.03 LTS.
  • StratoVirt can run with non-root permissions.

Environment Requirements

The following are required in the environment for running StratoVirt:

  • /dev/vhost-vsock device (for implementing MMIO)
  • nmap tool
  • Kernel and rootfs images

Preparing Devices and Tools

  • To run StratoVirt, the MMIO device must be implemented. Therefore, before running StratoVirt, ensure that the /dev/vhost-vsock device exists.

    Check whether the device exists.

    shell
    $ ls /dev/vhost-vsock
    /dev/vhost-vsock

    If the device does not exist, run the following command to generate it:

    shell
    modprobe vhost_vsock
  • To use QMP commands, install the nmap tool first. After configuring the Yum source, run the following command to install the tool:

    shell
    # yum install nmap

Preparing Images

Creating the Kernel Image

StratoVirt of the current version supports only the PE kernel image of the x86_64 and AArch64 platforms. The kernel image in PE format can be generated by using the following method:

  1. Run the following commands to obtain the kernel source code of openEuler:

    shell
    git clone https://gitee.com/openeuler/kernel.git
    cd kernel
  2. Run the following command to check and switch to the kernel version openEuler-22.03-LTS:

    shell
    git checkout openEuler-22.03-LTS
  3. Configure and compile the Linux kernel. You are advised to use the recommended configuration file). Copy the file to the kernel directory, rename it to .config, and run the make olddefconfig command to update to the latest default configuration (otherwise, you may need to manually select options for subsequent compilation). Alternatively, you can run the following command to configure the kernel as prompted. The system may display a message indicating that specific dependencies are missing. Run the yum install command to install the dependencies as prompted.

    shell
    make menuconfig
  4. Run the following command to create and convert the kernel image to the PE format. The converted image is vmlinux.bin.

    shell
    make -j vmlinux && objcopy -O binary vmlinux vmlinux.bin
  5. If you want to use the kernel in bzImzge format on the x86 platform, run the following command:

    shell
    make -j bzImage

Creating the Rootfs Image

The rootfs image is a file system image. When StratoVirt is started, the ext4 image with init can be loaded. To create an ext4 rootfs image, perform the following steps:

  1. Prepare a file with a proper size (for example, create a file with the size of 10 GB in /home).

    shell
    cd /home
    dd if=/dev/zero of=./rootfs.ext4 bs=1G count=10
  2. Create an empty ext4 file system on this file.

    shell
    mkfs.ext4 ./rootfs.ext4
  3. Mount the file image. Create the /mnt/rootfs directory and mount rootfs.ext4 to the directory as user root.

    shell
    $ mkdir /mnt/rootfs
    # Return to the directory where the file system is created, for example, **/home**.
    $ cd /home
    $ sudo mount ./rootfs.ext4 /mnt/rootfs && cd /mnt/rootfs
  4. Obtain the latest alpine-mini rootfs of the corresponding processor architecture.

    • If the AArch64 processor architecture is used, you can get the latest rootfs from the alpine. For example, alpine-minirootfs-3.21.0-aarch64.tar.gz, the reference commands are as follows:
    shell
    wget http://dl-cdn.alpinelinux.org/alpine/latest-stable/releases/aarch64/alpine-minirootfs-3.21.0-aarch64.tar.gz
    tar -zxvf alpine-minirootfs-3.21.0-aarch64.tar.gz
    rm alpine-minirootfs-3.21.0-aarch64.tar.gz
    • If the x86_64 processor architecture is used, you can get the latest rootfs from the alpine. For example, alpine-minirootfs-3.21.0-x86_64.tar.gz, the reference commands are as follows:
    shell
    wget http://dl-cdn.alpinelinux.org/alpine/latest-stable/releases/x86_64/alpine-minirootfs-3.21.0-x86_64.tar.gz
    tar -zxvf alpine-minirootfs-3.21.0-x86_64.tar.gz
    rm alpine-minirootfs-3.21.0-x86_64.tar.gz
  5. Run the following commands to create a simple /sbin/init for the ext4 file image:

    shell
    $ rm sbin/init; touch sbin/init && cat > sbin/init <<EOF
    #! /bin/sh
    mount -t devtmpfs dev /dev
    mount -t proc proc /proc
    mount -t sysfs sysfs /sys
    ip link set up dev lo
    
    exec /sbin/getty -n -l /bin/sh 115200 /dev/ttyS0
    poweroff -f
    EOF
    
    sudo chmod +x sbin/init
  6. Unmount the rootfs image.

    shell
    cd /home; umount /mnt/rootfs

    The rootfs is created successfully. You can use the ext4 rootfs image file rootfs.ext4, which is stored in the /home directory.

Obtaining Firmware Required for Standard Boot

Firmware refers to the device driver stored in a device. An OS can be booted in standard boot mode only through firmware. Currently, StratoVirt supports standard boot based on the Unified Extensible Firmware Interface (UEFI) only in the x86_64 and AArch64 architectures.

EDK II is open source software that implements the UEFI standard. StratoVirt uses EDK II as the standard boot firmware, and therefore you need to obtain the EDK II firmware binary, which can be installed by yum commands.

Run the following command in the x86_64 architecture:

shell
sudo yum install -y edk2-ovmf

Run the following command in the AArch64 architecture:

shell
sudo yum install -y edk2-aarch64

The EDK II firmware binary contains two files: one is used to save executable code, and the other is used to save boot configuration information. After the installation is complete, in the x86_64 architecture, the firmware file OVMF_CODE.fd and firmware configuration file OVMF_VARS.fd are saved in the /usr/share/edk2/ovmf directory. In the AArch64 architecture, the firmware file QEMU_EFI-pflash.raw and firmware configuration file vars-template-pflash.raw are saved in the /usr/share/edk2/aarch64 directory.