Running QEMU Virtual Machine on Github Codespaces

Create a new codespace:

1
gh codespace create

Generate SSH config:

1
2
gh codespace ssh --config > ~/.ssh/codespaces
printf 'Match all\nInclude ~/.ssh/codespaces\n' >> ~/.ssh/config

Connect to the codespace:

1
ssh cs.<codespace name>.<branch>

Run these commands in your codespace:

1
2
3
4
5
# Install QEMU
sudo apt install qemu-system-x86
# Set up kvm group
sudo groupadd -rg 109 kvm
sudo adduser codespace kvm

Relogin(or you will get permission denied on /dev/kvm) and run QEMU on the codespace:

1
qemu-system-x86_64 -enable-kvm -display vnc=:0 <other parameters>

Open SSH tunnel in a new terminal:

1
ssh cs.<codespace name>.<branch> -L <local port>:localhost:5900 -N

Finally, use a VNC client to connect to 127.0.0.1:<local port>.