Skip to content

Instantly share code, notes, and snippets.

@jonathanpallant
Last active March 27, 2025 15:56
Show Gist options
  • Save jonathanpallant/3a348d54bcd0449aadd4357383fda0d8 to your computer and use it in GitHub Desktop.
Save jonathanpallant/3a348d54bcd0449aadd4357383fda0d8 to your computer and use it in GitHub Desktop.

On your AArch64 host machine:

wget https://gist.githubusercontent.com/theboreddev/5f79f86a0f163e4a1f9df919da5eea20/raw/f546faea68f4149c06cca88fa67ace07a3758268/QEMU_EFI-a096471-edk2-stable202011.tar.gz
tar xvf QEMU_EFI-a096471-edk2-stable202011.tar.gz
wget https://cdimage.debian.org/images/cloud/bookworm/20250316-2053/debian-12-nocloud-arm64-20250316-2053.qcow2
qemu-img resize debian-12-nocloud-arm64-20250316-2053.qcow2 +32G
# On non-AArch64 machines try `-cpu cortex-a53` instead of `-cpu host -accel hvf`
qemu-system-aarch64 -m 8G -M virt -cpu host -accel hvf -bios QEMU_EFI.fd -drive if=none,file=debian-12-nocloud-arm64-20250316-2053.qcow2,id=hd0 -device virtio-blk-device,drive=hd0 -device e1000,netdev=net0 -netdev user,id=net0,hostfwd=tcp:127.0.0.1:5555-:22 -nographic -smp 8

On your x86-64 host machine (use -accel kvm on Linux, and -accel whpx on Windows):

wget https://cdimage.debian.org/images/cloud/bookworm/20250316-2053/debian-12-nocloud-amd64-20250316-2053.qcow2
qemu-img resize debian-12-nocloud-amd64-20250316-2053.qcow2 +32G
qemu-system-x86_64 -m 8G -M q35 -accel whpx -hda debian-12-nocloud-amd64-20250316-2053.qcow2 -device e1000,netdev=net0 -netdev user,id=net0,hostfwd=tcp:127.0.0.1:5555-:22 -nographic -smp 8

If you're on Windows you might want to add -serial telnet:localhost:4321,server,wait. Then you can use PuTTY to telnet to localhost:4321, which avoids issues with ANSI support in the Windows terminal.

Inside your QEMU virtual machine (login as 'root' with no password):

apt update
apt install fdisk
cfdisk /dev/vda # sort partitions, resize root, write, quit
reboot
# log in again
resize2fs /dev/vda2
apt install build-essential libssl-dev python3 flex bison bc libncurses-dev gawk openssl libssl-dev libelf-dev libudev-dev libpci-dev libiberty-dev autoconf llvm clang lld git openssh-server
nano /root/.ssh/authorized_keys # paste in your public SSH key

You can do this over SSH (ssh root@localhost -p 5555), or over the previous serial port session

curl https://sh.rustup.rs | bash
. "$HOME/.cargo/env"
rustup component add rust-src
cargo install --locked bindgen-cli
curl -O https://cdn.kernel.org/pub/linux/kernel/v6.x/linux-6.14.tar.xz
tar xvf linux-6.14.tar.xz
cd linux-6.14
make LLVM=1 rustavailable
make LLVM=1 defconfig 
make LLVM=1 menuconfig  # General setup / [*] Rust support
make LLVM=1 -j8
make LLVM=1 modules_install
make LLVM=1 install
reboot
# log in again - now you are on Linux 6.14, with Rust support
git clone https://github.com/Rust-for-Linux/rust-out-of-tree-module
cd rust-out-of-tree-module
git checkout 15de8569df46e16f4940b52c91ee8f6bfbe5ab22
make KDIR=../linux-6.14 LLVM=1
insmod ./rust_out_of_tree.ko
# observe kernel output on serial console
rmmod rust_out_of_tree
# observe more kernel output on serial console
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment