1# Custom VM
2
3## Headless VMs
4
5If your VM is headless (i.e. console in/out is the primary way of interacting
6with it), you can spawn it by passing a JSON config file to the
7VirtualizationService via the `vm` tool on a rooted AVF-enabled device. If your
8device is attached over ADB, you can run:
9
10```shell
11cat > vm_config.json <<EOF
12{
13  "kernel": "/data/local/tmp/kernel",
14  "initrd": "/data/local/tmp/ramdisk",
15  "params": "rdinit=/bin/init"
16}
17EOF
18adb root
19adb push <kernel> /data/local/tmp/kernel
20adb push <ramdisk> /data/local/tmp/ramdisk
21adb push vm_config.json /data/local/tmp/vm_config.json
22adb shell "/apex/com.android.virt/bin/vm run /data/local/tmp/vm_config.json"
23```
24
25The `vm` command also has other subcommands for debugging; run
26`/apex/com.android.virt/bin/vm help` for details.
27
28# Terminal app
29## Graphical environment (Wayland, VNC)
30By installing Wayland compositor and VNC backend, you can enable graphical environment.
31One of the options is `sway`, `wayvnc` and `xwayland`(if necessary).
32
33```
34sudo apt install sway wayvnc xwayland
35WLR_BACKENDS=headless WLR_LIBINPUT_NO_DEVICES=1 sway
36WAYLAND_DISPLAY=wayland-1 wayvnc 0.0.0.0 # or use port forwarding
37```
38
39And then, connect to 192.168.0.2:5900(or localhost:5900) with arbitrary VNC client.
40Or, `novnc`(https://github.com/novnc/noVNC/releases). For `novnc` you need to install
41`novnc`, and run `<novnc_path>/utils/novnc_proxy`, and then connect to `http://192.168.0.2:6080/vnc.html`
42(or `localhost:6080` if port forwarding is enabled.)
43
44`weston` with VNC backend might be another option, but it isn't available in
45Debian package repository for bookworm.
46
47## Hardware accelration
48If the file `/sdcard/linux/virglrenderer` exists on the device, it enables VirGL for VM.
49This requires enabling ANGLE for the Terminal app. (https://chromium.googlesource.com/angle/angle.git/+/HEAD/doc/DevSetupAndroid.md)
50