Launching X11 RISC-V applications on QEMU (Debian)

$ mmdebstrap --architectures=riscv64 --variant=minbase --include="debian-ports-archive-keyring" sid /tmp/riscv64-chroot "deb http://deb.debian.org/debian-ports/ sid main" "deb http://deb.debian.org/debian-ports/ unreleased main" -v
$ cat >/tmp/qemu-riscv64 <<EOF
package qemu-user-static
type magic
offset 0
magic \x7f\x45\x4c\x46\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xf3\x00
mask \xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff
interpreter /usr/bin/qemu-riscv64-static
EOF
$ sudo update-binfmts --import /tmp/qemu-riscv64
# apt update
# apt install x11-apps
# apt install xss-lock nm-tray x11vnc xvfb i3 ifupdown less iputils-ping network-manager iproute2 init vim
cookie=`mktemp`
alias startVNC="xvfb-run -f \"$cookie\" -s \"-screen 0 1280x800x24\" -n 1 i3 & x11vnc -auth \"$cookie\" -display :1"
$ sudo chroot /tmp/riscv64-chroot
# Update package information
apt-get update
# Set up basic networking
cat >>/etc/network/interfaces <<EOF
auto lo
iface lo inet loopback

auto eth0
iface eth0 inet dhcp
EOF
# Set root password
passwd
# Disable the getty on hvc0 as hvc0 and ttyS0 share the same console device in qemu.
ln -sf /dev/null /etc/systemd/system/serial-getty@hvc0.service
# Install kernel and bootloader infrastructure
apt-get install linux-image-riscv64 u-boot-menu
# Install and configure ntp tools
apt-get install openntpd ntpdate
sed -i 's/^DAEMON_OPTS="/DAEMON_OPTS="-s /' /etc/default/openntpd
# Configure syslinux-style boot menu
cat >>/etc/default/u-boot <<EOF
U_BOOT_PARAMETERS="rw noquiet root=/dev/vda1"
U_BOOT_FDT_DIR="noexist"
EOF
u-boot-update
exit
# virt-make-fs --partition=gpt --type=ext4 --size=40G /tmp/riscv64-chroot/ rootfs-riscv.img
qemu-system-riscv64 -nographic -machine virt -smp 4 -m 6.5G  -bios /usr/lib/riscv64-linux-gnu/opensbi/generic/fw_jump.elf  -kernel /usr/lib/u-boot/qemu-riscv64_smode/uboot.elf  -object rng-random,filename=/dev/urandom,id=rng0 -device virtio-rng-device,rng=rng0  -append "console=ttyS0 rw root=/dev/vda1"  -device virtio-blk-device,drive=hd0 -drive file=rootfs-riscv.img,format=raw,id=hd0  -device virtio-net-device,netdev=eth0 -netdev user,id=eth0,hostfwd=tcp::22222-:22,hostfwd=tcp::5900-:5900
qemu-system-riscv64 
-nographic
-machine virt
-smp 4
-m 6.5G
-bios /usr/lib/riscv64-linux-gnu/opensbi/generic/fw_jump.elf
-kernel /usr/lib/u-boot/qemu-riscv64_smode/uboot.elf
-object rng-random,filename=/dev/urandom,id=rng0
-device virtio-rng-device,rng=rng0
-append "console=ttyS0 rw root=/dev/vda1"
-device virtio-blk-device,drive=hd0
-drive file=rootfs-riscv.img,format=raw,id=hd0
-device virtio-net-device,netdev=eth0
-netdev user,id=eth0,hostfwd=tcp::22222-:22,hostfwd=tcp::5900-:5900
$ startVNC

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store