Fast VM with crosvm
crosvm can be used to run a blazing fast Android VM on a Linux host with GPU acceleration, negligible overhead and close to native performance.
The Android window feels smoother than ever before.
It can configured to use udmabuf, minigbm and wayland for a incredibly efficient rendering pipeline with zero copy display from guest to host wayland server.
It doesn’t work as expected out of the box, so we will have to apply some patches to fix mouse input.
Follow the instructions on https://crosvm.dev/book/building_crosvm/linux.html to set up the environment.
Then switch to last known working commit for the patches:
Apply patch to fix mouse input
Build crosvm with virgl support enabled
If minigbm build is giving errors, patch the Makefile as below. source
The executable will be in ./target/release/crosvm
Remove the CROSVM_USE_SYSTEM_VIRGLRENDERER=1
flags if build fails or you are using an ancient linux distro with older versions of libgbm or virglrenderer.
It cannot render to screen without using the right gralloc/hwc options.
The android.img was prepared using the script.
Add SETUPWIZARD=0 to kernel parameters (—params ”..”) to bypass Android setup wizard.
Networking
https://crosvm.dev/book/running_crosvm/example_usage.html#add-networking-support
Add --net tap-name=crosvm_tap
to the crosvm cmdline.
A static IP configuration is required inside the Android VM to connect to the network. However Android does not have settings to configure static IP for ethernet connections. We can use VirtWifi feature of Android-x86 as a workaround.
Add VIRT_WIFI=1 to kernel cmdline parameters to enable this feature.
Then connect to VirtWifi network from Android settings. Select Static IP and set IP Address to 192.168.10.2 and gateway to 192.168.10.1
Troubleshooting
- Colors are inverted: Turn on invert colors in Android Settings > Accessibility as a workaround or compile minigbm and virglrenderer with minigbm allocation enabled and link with crosvm binary.
- crosvm crashes with virtio-gpu error: Remove
udmabuf=true
from crosvm cmdline, udmabuf is not supported by all GPUs.
Venus Vulkan driver
After applying the following patch, the embedded virglrenderer library is compiled with minigbm allocation. This is required on the host for venus.
Patching virglrenderer source is also required to link against libminigbm built by cargo.
Setting the appropriate CFLAGS for your GPU allows minigbm to use native DRI backend, which also fixes the color issue. However it may not work on all GPUs.
Find virgl_render_server
in build directory
Include vulkan=true
in the list of comma separated gpu flags in crosvm cmdline and specify path to virgl_render_server
found earlier.
Enable serial console
Add androidboot.enable_console=1
to kernel cmdline parameters.
For reference
crosvm command lines extracted from certain versions of Google products.