diff --git a/src/content/posts/2024-01/imgs/qemu900.jpg b/src/content/posts/2024-01/imgs/qemu900.jpg new file mode 100644 index 0000000000000000000000000000000000000000..3e75535b4ad0902f78b5a77b997b7cdd51c36d75 Binary files /dev/null and b/src/content/posts/2024-01/imgs/qemu900.jpg differ diff --git "a/src/content/posts/2024-01/imgs/\345\205\250\351\203\250\347\274\226\350\257\221.jpg" "b/src/content/posts/2024-01/imgs/\345\205\250\351\203\250\347\274\226\350\257\221.jpg" new file mode 100644 index 0000000000000000000000000000000000000000..764033e8d5ed74bf6f5de5724a3dd78bd3bb3abb Binary files /dev/null and "b/src/content/posts/2024-01/imgs/\345\205\250\351\203\250\347\274\226\350\257\221.jpg" differ diff --git "a/src/content/posts/2024-01/imgs/\346\212\245\351\224\2311.png" "b/src/content/posts/2024-01/imgs/\346\212\245\351\224\2311.png" new file mode 100644 index 0000000000000000000000000000000000000000..8abca1c569f28fbf315894add37d2cda7da7d583 Binary files /dev/null and "b/src/content/posts/2024-01/imgs/\346\212\245\351\224\2311.png" differ diff --git "a/src/content/posts/2024-01/imgs/\346\212\245\351\224\2312.png" "b/src/content/posts/2024-01/imgs/\346\212\245\351\224\2312.png" new file mode 100644 index 0000000000000000000000000000000000000000..7b5a494cfac62b6a942f1c12e90497886ae93af8 Binary files /dev/null and "b/src/content/posts/2024-01/imgs/\346\212\245\351\224\2312.png" differ diff --git "a/src/content/posts/2024-01/imgs/\346\212\245\351\224\2313.png" "b/src/content/posts/2024-01/imgs/\346\212\245\351\224\2313.png" new file mode 100644 index 0000000000000000000000000000000000000000..faa094a92d210939898ece60b6bb1d8283baa519 Binary files /dev/null and "b/src/content/posts/2024-01/imgs/\346\212\245\351\224\2313.png" differ diff --git "a/src/content/posts/2024-01/imgs/\346\212\245\351\224\2314.png" "b/src/content/posts/2024-01/imgs/\346\212\245\351\224\2314.png" new file mode 100644 index 0000000000000000000000000000000000000000..487a75fdcdb272d2a360ee08a8b1211b7f391e10 Binary files /dev/null and "b/src/content/posts/2024-01/imgs/\346\212\245\351\224\2314.png" differ diff --git a/src/content/posts/2024-01/zmy_update_qemu9_and_run_riscv_openEuler2403.md b/src/content/posts/2024-01/zmy_update_qemu9_and_run_riscv_openEuler2403.md new file mode 100644 index 0000000000000000000000000000000000000000..37559bd488971f8ead948ea52fffdb51cf8dd9ec --- /dev/null +++ b/src/content/posts/2024-01/zmy_update_qemu9_and_run_riscv_openEuler2403.md @@ -0,0 +1,238 @@ +--- +title: 升级QEMU9.0.0和安装运行openEuler-24.03 +author: 张明烨 +pubDate: 2024-06-18 +categories: ['2024 年第一期'] +description: '将QEMU更新到9.0.0版本和安装openEuler-24.03镜像,并在QEMU上以riscv64的环境运行。' +--- + + + +## 一、QEMU 9.0.0编译安装 + +由于项目需要openEuler 2403 RISC-V 64环境,一般情况下没有riscv64的物理环境,所以选择在QEMU的riscv64虚拟环境下运行openEuler 2403 RISC-V 64。但是 + +``` +为了支持 UEFI ,需使用 8.1 版本以上的 QEMU。 + +编译时需要安装 libslirp 依赖库(包名根据发行版不同而不同,openEuler 为 libslirp-devel)并添加 --enable-slirp 参数。 +``` + +所以需要更新版本的QEMU来支持运行。 + +## QEMU + +QEMU(Quick Emulator)是一款免费开源模拟器,其与Bochs,PearPC类似,但拥有高速(配合KVM)、跨平台的特性。 + +QEMU是一个托管的虚拟机,它使用动态二进制转换技术来模拟处理器,并且提供多种硬件和外设模型,这使它能够运行多种未修改的客户机操作系统,能与KVM配合以接近本地速度运行虚拟机(接近真实电脑的速度)。 + +## 查询QEMU版本 + +```shell +qemu-riscv64 -version +qemu-system-riscv64 -version +``` + +本人版本之前为6.2.0 + +## 源码获取 + +源码获取依旧有两种方式: + +- [QEMU](https://www.qemu.org/)官网直接下载 +- 通过`wget`在终端上下载(推荐) + +```shell +wget https://download.qemu.org/qemu-9.0.0.tar.xz +tar xvJf qemu-9.0.0.tar.xz +``` + +解压后 + +![](./imgs/qemu900.jpg) + +## 安装依赖 + +目前本人环境为`Ubuntu22.04 LTS`,以防万一先安装一些依赖 + +```shell +sudo apt install autoconf automake autotools-dev curl libmpc-dev libmpfr-dev libgmp-dev \ + gawk build-essential bison flex texinfo gperf libtool patchutils bc \ + zlib1g-dev libexpat-dev git \ + libglib2.0-dev libfdt-dev libpixman-1-dev \ + libncurses5-dev libncursesw5-dev +``` + +在qemu9.0.0目录中打开终端,先运行配置文件检查依赖 + +```shell +./configure --enable-slirp +``` + +报错1: + +![](./imgs/报错1.png) + +解决方法: + +```shell +sudo apt install python3-venv +``` + +报错2: + +![](./imgs/报错2.png) + +解决方法: + +```shell +sudo apt install ninja-build +``` + +报错3: + +![](./imgs/报错3.png) + +解决方法: + +```shell +sudo apt install flex +``` + +报错4: + +![](./imgs/报错4.png) + +解决方法: + +```shell +sudo apt install bison +``` + +## 编译安装 + +默认会编译全部架构 + +```shell +./configure --enable-slirp +sudo make +``` + +![](./imgs/全部编译.jpg) + +可以选择部分编译安装,节约时间和硬盘 + +```shell +./configure --target-list=riscv64-softmmu,riscv64-linux-user --enable-slirp +sudo make +``` + +注意--enable-slirp是必要的,否则运行openEuler 2403时会出现network backend ‘user‘ is not compiled into this binary + +## 修改环境变量(重要) + +之前有通过apt的方式下载QEMU的,编译安装完QEMU9.0.0后查看版本还是没有变化。需要添加环境变量来指明软件路径。QEMU9.0.0编译安装完后,我将build文件夹下的所有内容cp在/opt/qemu。 + +使用VIM编辑$HOME/.bashrc + +```shell +vim $HOME/.bashrc +``` + +或在用户主目录~下 + +```shell +vim .bashrc +``` + +在最后一行加入并保存退出,其中QEMU的路径为/opt/qemu + +```shell +export PATH="$HOME/workspace/tools/gcc/bin:/opt/qemu:$PATH" +``` + +格式为 + +```shell +export PATH="路径1:路径2:$PATH" +``` + +注意:不要删$PATH,否则shell用不了。 + +重启或者source ~/.bashrc,然后检查版本 + +```shell +qemu-riscv64 -version +qemu-riscv64 version 9.0.0 + +qemu-system-riscv64 -version +QEMU emulator version 9.0.0 +``` + + + +## 二、在QEMU运行openEuler 2403 RISC-V 64 + +## 获取镜像 + +镜像地址是https://mirror.iscas.ac.cn/openeuler-sig-riscv/openEuler-RISC-V/testing/2403LTS-test/v1/QEMU/ + +```shell +wget https://mirror.iscas.ac.cn/openeuler-sig-riscv/openEuler-RISC-V/testing/2403LTS-test/v1/QEMU/openEuler-24.03-V1-base-qemu-testing-uefi.qcow2.zst + +zstd -d openEuler-24.03-V1-base-qemu-testing-uefi.qcow2.zst +``` + +## 获取启动脚本 + +```shell +wget https://mirror.iscas.ac.cn/openeuler-sig-riscv/openEuler-RISC-V/testing/2403LTS-test/v1/QEMU/start_vm_uefi.sh +``` + +## 获取uefi固件 + +```shell +wget https://mirror.iscas.ac.cn/openeuler-sig-riscv/openEuler-RISC-V/testing/2403LTS-test/v1/QEMU/RISCV_VIRT_CODE.fd + +wget https://mirror.iscas.ac.cn/openeuler-sig-riscv/openEuler-RISC-V/testing/2403LTS-test/v1/QEMU/RISCV_VIRT_VARS.fd +``` + +QEMU启动脚本一些参数说明: + +- -m 或 —m:指定虚拟机的内存大小。例如,-m 2G 表示分配2GB的内存给虚拟机。 +- -smp:指定虚拟机的处理器数量和拓扑结构。例如,-smp 4 表示使用4个处理器。 +- -cpu:指定虚拟机使用的CPU型号或架构。例如,-cpu host 表示使用宿主机的CPU。 +- -device:指定虚拟机添加和配置虚拟设备。例如,-device virtio-net表示添加一个VirtIO网络设备。 +- -bios:指定虚拟机的BIOS文件。例如,-bios /usr/lib/riscv64-linux-gnu/opensbi/generic/fw_jump.elf +- -kernel:指定要用作虚拟机内核的镜像文件。例如,-kernel /usr/lib/u-boot/qemu-riscv64_smode/uboot.elf +- -virtfs:-virtfs [tag|mount_tag][,driver[,mount_options]], 用于配置虚拟文件系统,virtfs允许将主机文件系统的目录或文件与虚拟机进行共享,以便虚拟机可以访问和操作这些文件 +- -hda 或 -drive:指定虚拟机的硬盘镜像文件或设备。例如,-hda disk.img 表示使用名为 disk.img 的硬盘镜像文件作为虚拟机的主硬盘。 +- -cdrom:指定虚拟机的光驱设备,可以用于加载ISO镜像文件。例如,-cdrom os.iso 表示使用名为 os.iso 的ISO镜像文件作为光驱。 +- -boot:指定虚拟机的启动顺序。例如,-boot c 表示从硬盘启动,-boot d 表示从光驱启动。 +- -net:配置虚拟机的网络设置。例如,-net nic 表示为虚拟机添加一个网络适配器,-net user 表示使用用户模式网络栈。 +- -vnc:启用VNC远程访问功能。例如,-vnc :1 表示在端口5901上启动VNC服务器。 +- -usb:启用虚拟机的USB支持。例如,-usb 表示启用USB控制器。 +- -snapshot:启用快照模式,允许创建和恢复虚拟机的快照。 -monitor:启动一个与虚拟机交互的监控控制台。例如,-monitor stdio 表示将监控控制台输出重定向到标准输入/输出。 +- -nographic:参数用于在无图形化界面的模式下运行虚拟机 +- -name:为虚拟机指定一个名称 + +## 启动 + +根据需要在启动脚本设置-m和-smp,然后启动脚本 + +```shell +chmod +x start_vm_uefi.sh +./start_vm_uefi.sh +``` + +用户名:root + +密码:openEuler12#$ + +## 三、参考 + +[RISC-V-QEMU (openeuler.org)](https://docs.openeuler.org/zh/docs/24.03_LTS/docs/Installation/RISC-V-QEMU.html) + +[RISC-V Toolchain And QEMU9.0源码编译 (eulixos.com)](https://learning.eulixos.com/posts/2024-01/chenmiao_riscv_qemu_compile/) + +[编译qemu-9.0.0_编译安装qemu9.0-CSDN博客](https://blog.csdn.net/weixin_54452942/article/details/137103546) \ No newline at end of file