How to Run Linux on RISC-V with QEMU Emulator

RISC-V open-source architecture is starting to become more and more interesting thanks to the growing RISC-V hardware & software ecosystem, and with the recent release of HiFive Unleashed, we even have a board capable of running Linux. The only problem: it costs $999.

But luckily, it’s possible to experiment with Linux on RISC-V without extra hardware, just using your current PC. Imperas offers a commercial solution working on both Windows and Linux that relies on busybear-linux RISC-V Linux root filesystem comprised of busybox and dropbear SSH server. The rootfs also works with QEMU, so I tried it in Ubuntu 16.04.

The instructions on Github are quite easy to follow. My computer is powered by an AMD FX8350 processor coupled with 16GB RAM, and the whole process took around 2 hours, so better use the fastest computer possible. It also requires around 26 GB of storage on your build machine.

First, let’s create a working directory, and retrieve the RISC-V toolchain:

Now we can now build the RISC-V newlib & Linux toolchains) after installing some dependencies:

We’ll also need to build qemu for RISC-V

The next three steps will build the rootfs, Linux 4.14 kernel, and the bootloader, but there are optional since you could just as well as download the binary releases.

  • Build busybear-linux

  • Build RISC-V Linux

  • Build BBL (Berkeley Boot Loader):

If we’re going to use the release files instead:

You’d normally want to setup Linux bridged networking, and I tried, but failed and ran out of time. I added the following lines to /etc/network/interfaces in my computer:

and create two scripts in the current directory

  • ifup

  • ifdown

But I did not get it to work in a reasonable time. Studying QEMU Networking page on Arch Linux in details should help. [Update: See comments’ section for SSH access using the Fedora RISC-V image instead]

Nevertheless I could still run Linux on RISC-V with QEMU using the following command:

The boot takes just over one second to our minimal rootfs. Here’s the boot log:

We can login with root using password “busybear” without quote.

Type halt to turn off Linux and QEMU:

Share this:

Support CNX Software! Donate via cryptocurrencies or become a Patron on Patreon

ROCK Pi 4C Plus
Notify of
The comment form collects your name, email and content to allow us keep track of the comments placed on the website. Please read and accept our website Terms and Privacy Policy to post a comment.
5 years ago

Thanks for the very useful article!

5 years ago

You are also welcome to use Fedora RISC-V stage 4 image with thousands of packages compiled natively and available via DNF. Find the latest disk images and instructions (special riscv-qemu package is available via Copr repository):

There is also a 2 part article on LWN. The first part was posted a couple of days ago and Fedora specific one should be posted next week.

5 years ago

“ucbvax” … is that a joke referring to University of California Berkeley VAX?

5 years ago

MTTCG works up to 8 cores (QEMU can utilize 8 cores/threads on your host machine) thus you can speed up compilations of your beloved packages (if missing).

If something is missing or not working properly you can report on IRC #fedora-riscv on FreeNode.

jonatan okagao
5 years ago

Many thanks for this useful tutorial!

I have faced a minor issue that the kernel can’t finish his boot process because of a problem in mounting the file system, I got the error message:
can’t open /dev/ttyS0: No such file or directory
The solution was to enable the following options in the configuration:
To enable these options:
make ARCH=riscv menuconfig
>Device Drivers > Generic Driver Options:
[*] Maintain a devtmpfs filesystem to mount at /dev
[*] Automount devtmpfs at /dev, after the kernel mounted the rootfs

2 years ago

i am facing the same issue, but i didnt understand the solution for this, please help me.
CONFIG_DEVTMPFS_MOUNT=y these two lines in linux.congif file then also getting same error.

3 years ago

Hi Jean, Thanks for the article, which is very useful for the beginners exploring RISC-V, while following steps above in Ubuntu 16.04 i got following errors, can you please suggest some fix. i gave the following final command sudo qemu-system-riscv64 -nographic -machine virt  -kernel bbl -append “root=/dev/vda ro console=ttyS0”  -drive file=busybear.bin,format=raw,id=hd0  -device virtio-blk-device,drive=hd0  -netdev type=tap,script=./ifup,downscript=./ifdown,id=net0  -device virtio-net-device,netdev=net0 I got the following errors and warnings bridge br0 does not exist! qemu-system-riscv64: warning: No -bios option specified. Not loading a firmware. qemu-system-riscv64: warning: This default will change in a future QEMU release. Please use the -bios option to avoid breakages when this happens. qemu-system-riscv64: warning: See QEMU’s… Read more »

3 years ago

actually bbl directory is there at riscv-pk directory and I am running command at busybear-linux directory, then i copied bbl folder to busybear-linux directory and gave command again at busybear-linux directory again getting error like this

bridge br0 does not exist!
qemu-system-riscv64: warning: No -bios option specified. Not loading a firmware.
qemu-system-riscv64: warning: This default will change in a future QEMU release. Please use the -bios option to avoid breakages when this happens.
qemu-system-riscv64: warning: See QEMU’s deprecation documentation for details.
qemu-system-riscv64: could not load kernel ‘bbl’
bridge br0 does not exist!

busybear-linux qemu release riscv-gnu-toolchain riscv-linux riscv-pk(my folder structure)

3 years ago

This is the only channel to contact you, Is there any other channel to contact you, to clarify my doubts and bring risc-v up on Linux with QEMU, I would be grateful if you help me.
Thanks in Advance

Khadas VIM4 SBC