This note is a summary of my experience of installing Ubuntu for RISC-V on Qemu on a macOS host. This is just a personal experience. There may be other ways.
For simplicity, all files will be copied in one single dedicated directory and all commands will be run from that current directory.
Initial reference: https://wiki.ubuntu.com/RISC-V/QEMU
Install qemu (using HomeBrew on macOS):
$ brew install qemu
....
$ qemu-system-riscv64 --version
QEMU emulator version 8.2.0
Copyright (c) 2003-2023 Fabrice Bellard and the QEMU Project developers
On an existing Ubuntu system (even an Intel one):
$ sudo apt install opensbi qemu-system-misc u-boot-qemu
And copy the following two files from the Ubuntu system to the virtual machine directory on macOS:
/usr/lib/riscv64-linux-gnu/opensbi/generic/fw_jump.bin
/usr/lib/u-boot/qemu-riscv64_smode/u-boot.bin
Download the lastest Ubuntu Server image for 64-bit RISC-V:
$ wget https://cdimage.ubuntu.com/releases/23.10.1/release/ubuntu-23.10-live-server-riscv64.img.gz
$ gzip -d ubuntu-23.10-live-server-riscv64.img.gz
Create a virtual disk drive for the VM (30 GB in that case):
$ qemu-img create -f raw vm-riscv-hdd.raw 30G
Just checking that all required files are present:
$ ls -l
-rw-r--r-- [...] 269440 [...] fw_jump.bin
-rw-r--r-- [...] 680568 [...] u-boot.bin
-rw-r--r-- [...] 3371171840 [...] ubuntu-23.10-live-server-riscv64.img
-rw-r--r-- [...] 32212254720 [...] vm-riscv-hdd.raw
Boot the VM on the installation image:
$ qemu-system-riscv64 \
-machine virt \
-m 4G -smp cpus=2 -nographic \
-bios fw_jump.bin \
-kernel u-boot.bin \
-netdev user,id=net0 \
-device virtio-net-device,netdev=net0 \
-drive file=ubuntu-23.10-live-server-riscv64.img,format=raw,if=virtio \
-drive file=vm-riscv-hdd.raw,format=raw,if=virtio \
-device virtio-rng-pci
The boot is quite slow (this is emulation) but works.
- Initial menu: "continue in basic mode / rich mode". Because you probably run qemu from a decent terminal window, it has the capability to display menus and colors. Select "rich mode".
- Select the installation language (typically "English"), then keyboard layout and variant (in my case: "French" and "French - French (Macintosh)").
- Choose the base for the installation. Use "Ubuntu Server".
- Network connections: DHCP should display an allocated address. Keep it, select "Done".
- Configure proxy. None in my case.
- Configure Ubuntu archive mirror. A default local URL is provided. The message "The mirror location is being tested" runs for a while, until "This mirror location passed tests". Select "Done".
- Storage configuration: Select "Use an entire disk" and deselect "Set up this disk as an LVM group" (we don't need LVM). Select "Done" and accept the proposed disk layout. Confirm "destuctive" action, select "Continue".
- Create a user and password. Select a host name, eg. "vmriscv".
- Select "Install OpenSSH server".
- Ignore "Featured snaps".
- The device setup and system installation run for a rather long time (again, this is emulation). The qemu process uses 100 to 200% CPU on the host system.
- The installation may continue with "downloading and installing security updates".
- At some point, the choice "Reboot Now" appears. Select it.
- The shutdown process takes some time. Then, the system attempts to reboot and you have to kill the qemu process.
Use the following command to boot the installed system. It is probably a good idea to keep it in a shell script.
$ qemu-system-riscv64 \
-machine virt \
-m 4G -smp cpus=8 \
-nographic \
-bios fw_jump.bin \
-kernel u-boot.bin \
-device virtio-net-device,netdev=net \
-netdev user,id=net,hostfwd=tcp::2233-:22 \
-drive file=vm-riscv-hdd.raw,format=raw,if=virtio \
-device virtio-rng-pci
Because of the hostfwd
option, the TCP port 2233 on the host is redirected to port 22 (ssh port) on the virtual machine. Therefore, logging to the VM is done this way:
$ ssh -p 2233 user@localhost
where user
is the name of the user you specified during installation.