1- [1. What is Cloud Hypervisor?](#1-what-is-cloud-hypervisor) 2 - [Objectives](#objectives) 3 - [High Level](#high-level) 4 - [Architectures](#architectures) 5 - [Guest OS](#guest-os) 6- [2. Getting Started](#2-getting-started) 7 - [Install prerequisites](#install-prerequisites) 8 - [Clone and build](#clone-and-build) 9 - [Containerized builds and tests](#containerized-builds-and-tests) 10 - [Run](#run) 11 - [Cloud image](#cloud-image) 12 - [Custom kernel and disk image](#custom-kernel-and-disk-image) 13 - [Building your kernel](#building-your-kernel) 14 - [Disk image](#disk-image) 15 - [Booting the guest VM](#booting-the-guest-vm) 16- [3. Status](#3-status) 17 - [Hot Plug](#hot-plug) 18 - [Device Model](#device-model) 19 - [TODO](#todo) 20- [4. `rust-vmm` project dependency](#4-rust-vmm-project-dependency) 21 - [Firecracker and crosvm](#firecracker-and-crosvm) 22- [5. Community](#5-community) 23 - [Contribute](#contribute) 24 - [Join us](#join-us) 25 - [Security issues](#security-issues) 26 27# 1. What is Cloud Hypervisor? 28 29Cloud Hypervisor is an open source Virtual Machine Monitor (VMM) that runs on top of [KVM](https://www.kernel.org/doc/Documentation/virtual/kvm/api.txt) and the MSHV hypervisors . 30 31The project focuses on exclusively running modern, cloud workloads, on top of a limited set of hardware architectures and platforms. 32Cloud workloads refers to those that are usually run by customers inside a cloud provider. For our purposes this means modern operating systems with most I/O handled by paravirtualised devices (i.e. virtio), no requirement for legacy devices, and 64-bit CPUs. 33 34Cloud Hypervisor is implemented in [Rust](https://www.rust-lang.org/) and is based on the [rust-vmm](https://github.com/rust-vmm) crates. 35 36## Objectives 37 38### High Level 39 40- Runs on KVM or MSHV 41- Minimal emulation 42- Low latency 43- Low memory footprint 44- Low complexity 45- High performance 46- Small attack surface 47- 64-bit support only 48- CPU, memory, PCI hotplug 49- Machine to machine migration 50 51### Architectures 52 53Cloud Hypervisor supports the `x86-64` and `AArch64` architectures. There are some small differences in functionality between the two architectures (see [#1125](https://github.com/cloud-hypervisor/cloud-hypervisor/issues/1125)). 54 55### Guest OS 56 57Cloud Hypervisor supports `64-bit Linux` and Windows 10/Windows Server 2019. 58 59# 2. Getting Started 60 61We create a folder to build and run `cloud-hypervisor` at `$HOME/cloud-hypervisor` 62 63```shell 64$ export CLOUDH=$HOME/cloud-hypervisor 65$ mkdir $CLOUDH 66``` 67 68## Install prerequisites 69 70You need to install some prerequisite packages in order to build and test Cloud Hypervisor. 71Here, all the steps are based on Ubuntu, for other Linux distributions please replace the 72package manager and package name. 73 74```shell 75# Install git 76$ sudo apt install git 77# Install rust tool chain 78$ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh 79# Install build-essential 80$ sudo apt install build-essential 81# If you want to build statically linked binary please add musl target 82$ rustup target add x86_64-unknown-linux-musl 83``` 84 85## Clone and build 86 87First you need to clone and build the cloud-hypervisor repo: 88 89```shell 90$ pushd $CLOUDH 91$ git clone https://github.com/cloud-hypervisor/cloud-hypervisor.git 92$ cd cloud-hypervisor 93$ cargo build --release 94 95# We need to give the cloud-hypervisor binary the NET_ADMIN capabilities for it to set TAP interfaces up on the host. 96$ sudo setcap cap_net_admin+ep ./target/release/cloud-hypervisor 97 98# If you want to build statically linked binary 99$ cargo build --release --target=x86_64-unknown-linux-musl --all 100$ popd 101``` 102 103This will build a `cloud-hypervisor` binary under `$CLOUDH/cloud-hypervisor/target/release/cloud-hypervisor`. 104 105### Containerized builds and tests 106 107If you want to build and test Cloud Hypervisor without having to install all the 108required dependencies (The rust toolchain, cargo tools, etc), you can also use 109Cloud Hypervisor's development script: `dev_cli.sh`. Please note that upon its 110first invocation, this script will pull a fairly large container image. 111 112For example, to build the Cloud Hypervisor release binary: 113 114```shell 115$ pushd $CLOUDH 116$ cd cloud-hypervisor 117$ ./scripts/dev_cli.sh build --release 118``` 119 120With `dev_cli.sh`, one can also run the Cloud Hypervisor CI locally. This can be 121very convenient for debugging CI errors without having to fully rely on the 122Cloud Hypervisor CI infrastructure. 123 124For example, to run the Cloud Hypervisor unit tests: 125 126```shell 127$ ./scripts/dev_cli.sh tests --unit 128``` 129 130Run the `./scripts/dev_cli.sh --help` command to view all the supported 131development script commands and their related options. 132 133## Run 134 135You can run a guest VM by either using an existing cloud image or booting into your own kernel and disk image. 136 137### Cloud image 138 139Cloud Hypervisor supports booting disk images containing all needed 140components to run cloud workloads, a.k.a. cloud images. To do that we rely on 141the [Rust Hypervisor 142Firmware](https://github.com/cloud-hypervisor/rust-hypervisor-firmware) project to provide 143an ELF 144formatted KVM firmware for `cloud-hypervisor` to directly boot into. 145 146We need to get the latest `rust-hypervisor-firmware` release and also a working cloud image. Here we will use a Ubuntu image: 147 148```shell 149$ pushd $CLOUDH 150$ wget https://cloud-images.ubuntu.com/focal/current/focal-server-cloudimg-amd64.img 151$ qemu-img convert -p -f qcow2 -O raw focal-server-cloudimg-amd64.img focal-server-cloudimg-amd64.raw 152$ wget https://github.com/cloud-hypervisor/rust-hypervisor-firmware/releases/download/0.3.2/hypervisor-fw 153$ popd 154``` 155 156```shell 157$ pushd $CLOUDH 158$ sudo setcap cap_net_admin+ep ./cloud-hypervisor/target/release/cloud-hypervisor 159$ ./cloud-hypervisor/target/release/cloud-hypervisor \ 160 --kernel ./hypervisor-fw \ 161 --disk path=focal-server-cloudimg-amd64.raw \ 162 --cpus boot=4 \ 163 --memory size=1024M \ 164 --net "tap=,mac=,ip=,mask=" \ 165 --rng 166$ popd 167``` 168 169Multiple arguments can be given to the `--disk` parameter. 170 171### Custom kernel and disk image 172 173#### Building your kernel 174 175Cloud Hypervisor also supports direct kernel boot into a `vmlinux` ELF kernel. In order to support virtio-iommu we have our own development branch. You are of course able to use your own kernel but these instructions will continue with the version that we develop and test against. 176 177To build the kernel: 178 179```shell 180 181# Clone the Cloud Hypervisor Linux branch 182$ pushd $CLOUDH 183$ git clone --depth 1 https://github.com/cloud-hypervisor/linux.git -b ch-5.14 linux-cloud-hypervisor 184$ pushd linux-cloud-hypervisor 185 186# Use the cloud-hypervisor kernel config to build your kernel 187$ cp $CLOUDH/cloud-hypervisor/resources/linux-config-x86_64 .config 188$ make bzImage -j `nproc` 189$ popd 190``` 191 192The `vmlinux` kernel image will then be located at `linux-cloud-hypervisor/arch/x86/boot/compressed/vmlinux.bin`. 193 194#### Disk image 195 196For the disk image, we will use a Ubuntu cloud image that contains a root partition: 197 198```shell 199$ pushd $CLOUDH 200$ wget https://cloud-images.ubuntu.com/focal/current/focal-server-cloudimg-amd64.img 201$ qemu-img convert -p -f qcow2 -O raw focal-server-cloudimg-amd64.img focal-server-cloudimg-amd64.raw 202$ popd 203``` 204 205#### Booting the guest VM 206 207Now we can directly boot into our custom kernel and make it use the Ubuntu root partition. 208If we want to have 4 vCPUs and 1024 MBytes of memory: 209 210```shell 211$ pushd $CLOUDH 212$ sudo setcap cap_net_admin+ep ./cloud-hypervisor/target/release/cloud-hypervisor 213$ ./cloud-hypervisor/target/release/cloud-hypervisor \ 214 --kernel ./linux-cloud-hypervisor/arch/x86/boot/compressed/vmlinux.bin \ 215 --disk path=focal-server-cloudimg-amd64.raw \ 216 --cmdline "console=hvc0 root=/dev/vda1 rw" \ 217 --cpus boot=4 \ 218 --memory size=1024M \ 219 --net "tap=,mac=,ip=,mask=" \ 220 --rng 221``` 222 223The above example use the `virtio-console` device as the guest console, and this 224device may not be enabled soon enough by the guest kernel to get early kernel 225debug messages. 226 227When in need for earlier debug messages, using the legacy serial device based 228console is preferred: 229 230``` 231$ ./cloud-hypervisor/target/release/cloud-hypervisor \ 232 --kernel ./linux-cloud-hypervisor/arch/x86/boot/compressed/vmlinux.bin \ 233 --console off \ 234 --serial tty \ 235 --disk path=focal-server-cloudimg-amd64.raw \ 236 --cmdline "console=ttyS0 root=/dev/vda1 rw" \ 237 --cpus boot=4 \ 238 --memory size=1024M \ 239 --net "tap=,mac=,ip=,mask=" \ 240 --rng 241``` 242 243# 3. Status 244 245Cloud Hypervisor is under active development. The following stability guarantees are currently made: 246 247* The API (including command line options) will not be removed or changed in a 248 breaking way without a minimum of 2 releases notice. Where possible warnings 249 will be given about the use of deprecated functionality and the deprecations 250 will be documented in the release notes. 251* Point releases will be made between individual releases where there are 252 substantial bug fixes or security issues that need to be fixed. 253 254Currently the following items are **not** guaranteed across updates: 255 256* Snapshot/restore is not supported across different versions 257* Live migration is not supported across different versions 258* The following features are considered experimental and may change 259 substantially between releases: TDX, SGX. 260 261 262As of 2021-04-29, the following cloud images are supported: 263 264- [Ubuntu Bionic](https://cloud-images.ubuntu.com/bionic/current/) (cloudimg) 265- [Ubuntu Focal](https://cloud-images.ubuntu.com/focal/current/) (cloudimg) 266- [Ubuntu Groovy](https://cloud-images.ubuntu.com/groovy/current/) (cloudimg) 267- [Ubuntu Hirsute](https://cloud-images.ubuntu.com/hirsute/current/) (cloudimg) 268 269Direct kernel boot to userspace should work with a rootfs from most distributions. 270 271## Hot Plug 272 273Cloud Hypervisor supports hotplug of CPUs, passthrough devices (VFIO), `virtio-{net,block,pmem,fs,vsock}` and memory resizing. This [document](docs/hotplug.md) details how to add devices to 274a running VM. 275 276## Device Model 277 278Details of the device model can be found in this [documentation](docs/device_model.md). 279 280## TODO 281 282We are not tracking the Cloud Hypervisor TODO list from a specific git tracked file but through 283[github issues](https://github.com/cloud-hypervisor/cloud-hypervisor/issues/new) instead. 284 285# 4. `rust-vmm` project dependency 286 287In order to satisfy the design goal of having a high-performance, security-focused hypervisor the decision 288was made to use the [Rust](https://www.rust-lang.org/) programming language. 289The language's strong focus on memory and thread safety makes it an ideal candidate for implementing VMMs. 290 291Instead of implementing the VMM components from scratch, Cloud Hypervisor is importing the [rust-vmm](https://github.com/rust-vmm) 292crates, and sharing code and architecture together with other VMMs like e.g. Amazon's [Firecracker](https://firecracker-microvm.github.io/) 293and Google's [crosvm](https://chromium.googlesource.com/chromiumos/platform/crosvm/). 294 295Cloud Hypervisor embraces the rust-vmm project goals, which is to be able to share and re-use 296as many virtualization crates as possible. As such, the Cloud Hypervisor relationship with the rust-vmm 297project is twofold: 298 2991. It will use as much of the rust-vmm code as possible. Any new rust-vmm crate that's relevant to the project 300 goals will be integrated as soon as possible. 3012. As it is likely that the rust-vmm project will lack some of the features that Cloud Hypervisor needs (e.g. ACPI, 302 VFIO, vhost-user, etc), we will be using the Cloud Hypervisor VMM to implement and test them, and contribute them 303 back to the rust-vmm project. 304 305## Firecracker and crosvm 306 307A large part of the Cloud Hypervisor code is based on either the Firecracker or the crosvm projects implementations. 308Both of these are VMMs written in Rust with a focus on safety and security, like Cloud Hypervisor. 309 310However we want to emphasize that the Cloud Hypervisor project is neither a fork nor a reimplementation of any of those 311projects. The goals and use cases we're trying to meet are different. 312We're aiming at supporting cloud workloads, i.e. those modern, full Linux distribution images currently being run by 313Cloud Service Provider (CSP) tenants. 314 315Our primary target is not to support client or serverless use cases, and as such our code base already diverges 316from the crosvm and Firecracker ones. As we add more features to support our use cases, we believe that the divergence 317will increase while at the same time sharing as much of the fundamental virtualization code through the rust-vmm project 318crates as possible. 319 320# 5. Community 321 322The Cloud Hypervisor project follows the governance, and community guidelines described in 323the [Community](https://github.com/cloud-hypervisor/community) repository. 324 325## Contribute 326 327We are working on building a global, diverse and collaborative community around the Cloud Hypervisor project. 328Anyone who is interested in [contributing](CONTRIBUTING.md) to the project is welcome to participate. 329 330We believe that contributing to a open source project like Cloud Hypervisor covers a lot more than just sending 331code. Testing, documentation, pull request reviews, bug reports, feature requests, project improvement suggestions, 332etc, are all equal and welcome means of contribution. See the [CONTRIBUTING](CONTRIBUTING.md) document for more details. 333 334## Join us 335 336Get an [invite to our Slack channel](https://join.slack.com/t/cloud-hypervisor/shared_invite/enQtNjY3MTE3MDkwNDQ4LWQ1MTA1ZDVmODkwMWQ1MTRhYzk4ZGNlN2UwNTI3ZmFlODU0OTcwOWZjMTkwZDExYWE3YjFmNzgzY2FmNDAyMjI) 337and [join us on Slack](https://cloud-hypervisor.slack.com/). 338 339## Security issues 340 341Please use the GitHub security advisories feature for reporting issues: https://github.com/cloud-hypervisor/cloud-hypervisor/security/advisories/new 342