QEMU学习之路(10)--- RISCV64 virt 使用Ubuntu启动
一、前言
QEMU版本:7.0.0
参考:https://canonical-ubuntu-boards.readthedocs-hosted.com/en/latest/how-to/qemu-riscv/
安装依赖:
bash
sudo apt update
sudo apt install opensbi qemu-system-misc u-boot-qemu
二、Ubuntu启动
1、下载镜像
从ubuntu官网下载预安装镜像
bash
wget https://cdimage.ubuntu.com/releases/noble/release/ubuntu-24.04.2-preinstalled-server-riscv64.img.xz
2、解压镜像
bash
xz ubuntu-24.04.2-preinstalled-server-riscv64.img.xz
3、可选项,可以使用如下命令扩展磁盘大小(文件系统也会自动调整大小):
bash
qemu-img resize -f raw ubuntu-24.04.2-preinstalled-server-riscv64.img +5G
4、使用如下命令启动
bash
qemu-system-riscv64 \
-machine virt -nographic -m 2048 -smp 4 \
-kernel /usr/lib/u-boot/qemu-riscv64_smode/uboot.elf \
-device virtio-net-device,netdev=eth0 -netdev user,id=eth0 \
-device virtio-rng-pci \
-drive file=ubuntu-24.04.2-preinstalled-server-riscv64.img,format=raw,if=virtio
三、更新Uboot
ubuntu-24.04.2镜像启动对u-boot版本有求,建议使用U-Boot 2024.01版本
1、获取uboot源码
bash
git clone https://gitee.com/mirrors/u-boot.git -b v2024.01 u-boot_2024.01
2、设置环境变量
bash
export CROSS_COMPILE=riscv64-linux-gnu-
3、配置编译选项
bash
make qemu-riscv64_smode_defconfig
4、编译uboot
bash
make -j $(nproc)
四、使用新uboot启动
使用如下命令启动
bash
/home/william/project/qemu/qemu-7.0.0/build/opt/bin/qemu-system-riscv64 \
-machine virt -nographic -m 2048 -smp 4 \
-kernel u-boot_2024.01/u-boot \
-device virtio-net-device,netdev=eth0 -netdev user,id=eth0 \
-device virtio-rng-pci \
-drive file=ubuntu-24.04.2-preinstalled-server-riscv64.img,format=raw,if=virtio
使用账户名ubuntu
登陆,默认密码是ubuntu
第一次登陆会提示修改密码