====== 在 QEMU 内运行 openEuler RISC-V 移植版 ====== 不要忘记安装最新版的 [[https://qemu.org|QEMU]]以及将 QEMU 的目录添加到环境变量里! 去 [[https://repo.openeuler.org/openEuler-preview/RISC-V/|openEuler 官网]]可以下载移植版,获取下面两个文件: * fw_payload_oe.elf (或者类似的文件) * openEuler-preview.riscv64.qcow2 第一个为用于 QEMU 启动的 kernel image,第二个为虚拟磁盘镜像。 下载之后,Linux 可以通过一个小脚本来方便的启动: #!/bin/bash qemu-system-riscv64 \ -nographic -machine virt \ -smp 2 -m 4G \ -kernel fw_payload_oe.elf \ -drive file=openEuler-preview.riscv64.qcow2,format=qcow2,id=hd0 \ -object rng-random,filename=/dev/urandom,id=rng0 \ -device virtio-rng-device,rng=rng0 \ -device virtio-blk-device,drive=hd0 \ -device virtio-net-device,netdev=usernet \ -netdev user,id=usernet,hostfwd=tcp::12055-:22 \ -append 'root=/dev/vda1 rw console=ttyS0 systemd.default_timeout_start_sec=600 selinux=0 highres=off mem=4096M earlycon' \ -bios none macOS 下启动: cmd="qemu-system-riscv64 \ -machine virt -nographic \ -display cocoa,show-cursor=on \ -smp "8" -m "16"G \ -audiodev coreaudio,id=snd0 \ -bios "fw_payload_oe_uboot_2304.bin" \ -drive file="openEuler-23.03-V1-xfce-qemu-preview.qcow2",format=qcow2,id=hd0 \ -object rng-random,filename=/dev/urandom,id=rng0 \ -device virtio-vga \ -device virtio-rng-device,rng=rng0 \ -device virtio-blk-device,drive=hd0 \ -device virtio-net-device,netdev=usernet \ -netdev user,id=usernet,hostfwd=tcp::"12055"-:22 \ -device qemu-xhci -usb -device usb-kbd -device usb-tablet -device usb-audio,audiodev=snd0" eval $cmd Windows 下通过 PowerShell 脚本启动: qemu-system-riscv64 ` -nographic -machine virt ` -smp 8 -m 16G ` -display sdl ` -kernel "fw_payload_oe_qemuvirt.elf" ` -bios none ` -drive file=openEuler-22.03-V2-xfce-qemu-preview.qcow2,format=qcow2,id=hd0 ` -device virtio-vga ` -device virtio-blk-device,drive=hd0 ` -device virtio-net-device,netdev=usernet ` -netdev user,id=usernet,hostfwd=tcp::12056-:22 ` -device qemu-xhci -usb -device usb-kbd -device usb-tablet ` -append 'root=/dev/vda1 rw console=ttyS0 swiotlb=1 loglevel=3 systemd.default_timeout_start_sec=600 selinux=0 highres=off mem=16384M earlycon' 当系统启动之后,可以在 Host 上通过 ssh 登录到运行于 QEMU 模拟器中的 openEuler OS: $ ssh -p 12055 root@localhost 默认的用户名为 ''root'',密码为 ''openEuler12#$''。 注意,以下都很老了(已经不存在这些问题),仅仅作为存档用途出现在这里。 ===== 软件源 ===== openEuler 使用的是 dnf 作为包管理器,配置文件在 ''/etc/dnf/dnf.conf''。 默认安装了 vim ,可以使用 vim 进行编辑。写入以下数据: [main] gpgcheck=1 installonly_limit=3 clean_requirements_on_remove=True best=True skip_if_unavailable=False [repository] name=openEuler-risv-v #baseurl=https://isrc.iscas.ac.cn/mirror/openeuler-sig-riscv/oe-RISCV-repo/ baseurl=https://repo.openeuler.org/openEuler-preview/RISC-V/everything/ gpgcheck=0 然后执行 ''dnf update'' 即可。 ===== 系统时间 ===== 不过在这里你可能发现失败了,因为时间不对!通过运行 ''timedatectl'' 可以发现系统时间为 2019 年…… 这里我们采用 ntp 自动授时的方法。配置文件位于 ''/etc/systemd/timesyncd.conf'',修改为以下内容: # This file is part of systemd. # # systemd is free software; you can redistribute it and/or modify it # under the terms of the GNU Lesser General Public License as published by # the Free Software Foundation; either version 2.1 of the License, or # (at your option) any later version. # # Entries in this file show the compile time defaults. # You can change settings by editing this file. # Defaults can be restored by simply deleting this file. # # See timesyncd.conf(5) for details. [Time] NTP=0.cn.pool.ntp.org 1.cn.pool.ntp.org 2.cn.pool.ntp.org 3.cn.pool.ntp.org #FallbackNTP=time1.google.com time2.google.com time3.google.com time4.google.com #RootDistanceMaxSec=5 #PollIntervalMinSec=32 #PollIntervalMaxSec=2048 接下来就运行 ntpd 服务吧: # systemctl enable systemd-timesyncd # systemctl start systemd-timesyncd # systemctl status systemd-timesyncd 最后一步是设置时区,大功告成! # ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime ===== Others ===== ''ping'' 在 ''iputils'' 包内。 ==== 公共 CI 机器上编译用户模式的 QEMU ==== 这里我们可以使用清华源来加快 git clone 的速度,然后转到最新版的分支用于构建: $ git clone https://mirrors.tuna.tsinghua.edu.cn/git/qemu.git $ cd qemu $ git checkout stable-6.1 $ ./configure --target-list=riscv64-softmmu,riscv64-linux-user --prefix=/home/misaka00251/program/riscv64-qemu $ make $ make install 上面的 prefix 可以自己定义位置,如果自定义了位置的话下面的 ''QEMU_HOME'' 也要一并修改。 在编译成功之后,记得在 ''~/.bashrc'' 内添加环境变量: export QEMU_HOME=/home/misaka00251/program/riscv64-qemu export PATH=$QEMU_HOME/bin:$PATH 随后 ''source ~/.bashrc'' 应用到当前 session,运行 ''qemu-system-riscv64 -version'' 如果出现版本号说明安装正确。 :!: 公共机器上无需再去 openEuler 官方下载相关文件,Wechat@nil 准备了一份放在了 /var/tmp/oE-priv-img 内。 ==== 我的虚拟环境没空间了 ==== 这我还真在编译 openjdk 的时候遇到了。 首先关机,然后使用 ''qemu-img info openEuler-preview.riscv64.qcow2'' 查看虚拟硬盘信息。 然后使用 ''qemu-img resize openEuler-preview.riscv64.qcow2 +64G'' 来增加你的虚拟硬盘空间。 接下来,进入系统并安装 ''parted'',输入 ''parted /dev/vda resizepart 1'',在询问结尾是多少 GB 时为了保险起见,我填写了 ''70GB''。 然后输入 ''partprobe /dev/vda'' 来重新读取分区表,最后输入 ''resize2fs /dev/vda1'' 来获得硬盘空间,结束~~~