Transferring files between your host and RISC-V QEMU machine is often a daunting task. typical solutions include using the 9P FS which requires host kernel level modifications, which might not always be practical. In the following sections,we will build a RISC-V Linux image using Buildroot and then boot it using QEMU. We will then configure the Linux image to use sshfs to mount the host filesystem. This will allow us to seamlessly transfer files between the host and the RISC-V QEMU machine.
I am using a clean Windows machine with WSL2 Ubuntu
22.04 as my development environment. Install basic packages with:
sudo apt update && sudo apt -y upgrade
sudo apt install -y build-essential unzip bc libncurses-dev openssh-server
SSH server will not be started by default since WSL does not bring up
systemd. I took the easy route and enabled systemd on the Ubuntu image with the following line in
$PATH includes spaces and special characters that are not compatible with Buildroot and Kconfig. To fix this, we need to add the following line to
Alternatively, you can also add the following line to your
.bashrc, or run it in your terminal in a new bash session:
export PATH=$(echo $PATH | tr -d '()[:space:]')
Restart WSL by issuing the following command in a PowerShell terminal:
Compiling RFS, Kernel and QMEU with Buildroot
- Download the latest Buildroot release from here. I am using
2023.02for this tutorial. Extract the archive and navigate to the extracted directory.
tar xvf buildroot-2023.02.tar.gz
- Configure Buildroot for RISC-V with the following command:
sshfsin Buildroot with menuconfig.
Target packages -> Filesystem and flash utilities -> sshfs (FUSE) and enable it. Save the config and exit.
FUSE(Filesystem in Userspace) support in the kernel to operate. To enable this, launch the Buildroot Linux configuration menu with:
File systems -> FUSE (Filesystem in Userspace) support and enable it to be built as an inbuilt module (
* instead of
M in menuconfig). Save the config and exit.
- Build the RISC-V Linux kernel image, RFS and QEMU with:
This will take a while to complete. Once the build is complete, you will find the RISC-V Linux kernel image, RFS and QEMU binaries in
Booting RISC-V Linux with QEMU
To launch the newly compiled system, execute the
output/images/start-qemu.sh script. This will launch QEMU with the RISC-V Linux kernel image and RFS.
The default username is
root without a password.
Mounting a host directory with sshfs
Issue the following command in the QEMU shell to mount a host directory with sshfs. Make sure that the ssh server is up and running on the host machine.
sshfs -o allow_other,default_permissions <username>@10.0.2.2:<host path> /mnt
Contents of the host directory will now be available in the QEMU shell at
10.0.2.2 is the default IP address of the host machine in the QEMU network. The Buildroot generated startup script sets up the SLIRP network for QEMU makingthe host accessible over this “special” IP address. You can read more about this here.
In this tutorial, we built a RISC-V Linux image using Buildroot and then booted it using QEMU. We then configured the Linux image to use sshfs to mount the host filesystem. This allowed us to seamlessly transfer files between the host and the RISC-V QEMU machine.