1.安装QEMU
下载地址:
https://www.qemu.org/download/
建议选择稳定版本,下载后解压,然后make
wget https://download.qemu.org/qemu-8.0.3.tar.xz
tar xjvf qemu-8.0.3.tar.xz
cd qemu-8.0.3
./configure --enable-kvm --enable-virtfs
make
--enable-virtfs 用户虚拟机和宿主机之间共享文件
2.安装u-boot-qemu
sudo apt install u-boot-qemu
3.下载Debian的riscv64 image
下载后解压,得到 image.qcow2
4.启动Qemu
qemu-system-riscv64 -machine virt -cpu rv64 -m 8G -smp 4 -nographic \
-append "console=ttyS0 rw root=/dev/vda1" \
-device virtio-blk-device,drive=hd \
-drive file=imge.qcow2,if=none,id=hd \
-device virtio-net-device,netdev=net \
-netdev user,id=net,hostfwd=tcp::2222-:22 \
-kernel /usr/lib/u-boot/qemu-riscv64_smode/uboot.elf \
-object rng-random,filename=/dev/urandom,id=rng \
-device virtio-rng-device,rng=rng \
-virtfs local,path=~/shared,mount_tag=host0,security_model=passthrough,id=host0
5.访问Debian
可直接在Qemu上登录,账号密码是 root : root