RockOS KVM 示例
RockOS 支持基于 H 扩展(RISC-V Hypervisor Extension)的 KVM 虚拟化。
目前已经验证可用的系统包括:
- Ubuntu 24.04.1 LTS & 24.10
- openEuler 24.03 LTS & 24.09
- FreeBSD 14.1-RELEASE
- Debian testing netinst CD
演示环境
- 系统版本:RockOS github
- Ubuntu 预安装镜像:http://cdimage.ubuntu.com/releases/24.10/release/ubuntu-24.10-preinstalled-server-riscv64.img.xz
- openEuler 24.09 QEMU: http://repo.openeuler.org/openEuler-24.09/virtual_machine_img/riscv64/
- FreeBSD 14.1-RELEASE: http://download.freebsd.org/releases/VM-IMAGES/14.1-RELEASE/riscv64/Latest/
- Debian testing netinst CD: http://cdimage.debian.org/cdimage/weekly-builds/riscv64/iso-cd/debian-testing-riscv64-netinst.iso
- Debian sid cloud image: http://cdimage.debian.org/images/cloud/sid/daily/latest/debian-sid-nocloud-riscv64-daily.qcow2
- 系统默认已预装
qemu-system-riscv64
- 需要手动安装
wget
或curl
等下载工具以下载镜像 - 软件源内提供了
u-boot-qemu
和qemu-efi-riscv64
,如有需要可手动安装
若下载速度慢可以考虑更换其它镜像源。
步骤
由于 QEMU 目前不支持在启用了 KVM 的情况下加载 M Mode 固件(见 此处注释),目前可行的几种方式如下:
- 使用
u-boot-qemu
包提供的u-boot.elf
- Ubuntu 和 FreeBSD 可用此方法启动。
- 使用其它固件
- 如 openEuler RISC-V 随系统镜像一同分发的 EDK II 固件。
qemu-efi-riscv64
包也提供 EDK II 固件。
- 手动指定
-initrd
-kernel
-append
参数- Ubuntu 可用此方法启动。
- 系统自带的 Busybox KVM Demo 也是基于此方式启动。
- 根据 FreeBSD 文档,FreeBSD 也可使用此方式启动。
- 未测试,本文未演示。
在开始前,需要先手动加载 KVM 内核模块(开机默认未加载):
sudo modprobe kvm
获取所需软件包:
sudo apt update; sudo apt install -y wget u-boot-qemu qemu-efi-riscv64
方法一:使用 u-boot-qemu 软件包提供的 U-Boot
以 Ubuntu 预安装服务器镜像、FreeBSD 和 Debian netinst CD 为例。
Ubuntu
wget http://cdimage.ubuntu.com/releases/24.10/release/ubuntu-24.10-preinstalled-server-riscv64.img.xz
xz -dkv -T0 ubuntu-24.10-preinstalled-server-riscv64.img.xz
sudo qemu-system-riscv64 --enable-kvm -M virt -cpu host -m 2048 -smp 2 -nographic \
-device virtio-net-device,netdev=eth0 -netdev user,id=eth0 \
-device virtio-rng-pci \
-kernel /usr/lib/u-boot/qemu-riscv64_smode/uboot.elf \
-drive file=ubuntu-24.10-preinstalled-server-riscv64.img,format=raw,if=virtio
默认用户名和密码均为 ubuntu
。
Ubuntu 的预安装镜像在首次启动时会提示修改密码,按提示操作即可。
FreeBSD
wget http://download.freebsd.org/releases/VM-IMAGES/14.1-RELEASE/riscv64/Latest/FreeBSD-14.1-RELEASE-riscv-riscv64.qcow2.xz
xz -dkv -T0 FreeBSD-14.1-RELEASE-riscv-riscv64.qcow2.xz
sudo qemu-system-riscv64 --enable-kvm -M virt -cpu host -m 2048 -smp 2 -nographic \
-device virtio-net-device,netdev=eth0 -netdev user,id=eth0 \
-device virtio-rng-pci \
-kernel /usr/lib/u-boot/qemu-riscv64_smode/uboot.elf \
-drive file=FreeBSD-14.1-RELEASE-riscv-riscv64.qcow2,format=qcow2,if=virtio
可使用默认的 root
用户免密码登录。
Debian cloud
Debian sid 已经提供了 qcow2 格式的硬盘镜像。
wget http://cdimage.debian.org/images/cloud/sid/daily/latest/debian-sid-nocloud-riscv64-daily.qcow2
sudo qemu-system-riscv64 --enable-kvm -M virt -cpu host -m 2048 -smp 2 -nographic \
-device virtio-net-device,netdev=eth0 -netdev user,id=eth0 \
-device virtio-rng-pci \
-kernel /usr/lib/u-boot/qemu-riscv64_smode/uboot.elf \
-drive file=debian-sid-nocloud-riscv64-daily.qcow2,format=qcow2,if=virtio
Debian testing netinst CD
wget http://cdimage.debian.org/cdimage/weekly-builds/riscv64/iso-cd/debian-testing-riscv64-netinst.iso
qemu-img create -f qcow2 debian.qcow2 16G
sudo qemu-system-riscv64 --enable-kvm -M virt -cpu host -m 2048 -smp 2 -nographic \
-boot d -cdrom debian-testing-riscv64-netinst.iso \
-device virtio-net-device,netdev=eth0 -netdev user,id=eth0 \
-device virtio-rng-pci \
-kernel /usr/lib/u-boot/qemu-riscv64_smode/uboot.elf \
-drive file=debian.qcow2,format=qcow2,if=virtio
执行以上命令,会创建一个 16G 大小的 qcow2 硬盘镜像,并启动至 Debian 安装程序。
系统安装结束后,正常关闭虚拟机,删除启动选项中的 -boot d -cdrom debian-testing-riscv64-netinst.iso \
部分,即可开机进入安装后的系统。