在 QEMU 内运行 openEuler RISC-V 移植版

This is an old revision of the document!


在 QEMU 内运行 openEuler RISC-V 移植版

不要忘记安装最新版的 QEMU以及将 QEMU 的目录添加到环境变量里!

openEuler 官网可以下载移植版,获取下面两个文件:

  • fw_payload_oe.elf
  • openEuler-preview.riscv64.qcow2

第一个为用于 QEMU 启动的 kernel image,第二个为虚拟磁盘镜像。

下载之后,Linux 可以通过一个小脚本来方便的启动:

run.sh
#!/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

Windows 下通过 PowerShell 脚本启动:

run.ps1
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 `
  -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

当系统启动之后,可以在 Host 上通过 ssh 登录到运行于 QEMU 模拟器中的 openEuler OS:

$ ssh -p 12055 root@localhost

默认的用户名为 root,密码为 openEuler12#$

软件源

openEuler 使用的是 dnf 作为包管理器,配置文件在 /etc/dnf/dnf.conf

默认安装了 vim ,可以使用 vim 进行编辑。写入以下数据:

dnf.conf
[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/
gpgcheck=0

然后执行 dnf update 即可。

系统时间

不过在这里你可能发现失败了,因为时间不对!通过运行 timedatectl 可以发现系统时间为 2019 年……

这里我们采用 ntp 自动授时的方法。首先为了安装 ntpd 包,我们需要手动设置一下时间,不过做这个之前先要关闭 ntp service。

# timedatectl set-ntp false
# timedatectl set-time "2022-01-01 00:00"

接下来安装 ntp 包:

# dnf install ntp

安装之后,我们需要去编辑一下配置文件,配置文件位于 /etc/ntp.conf,添加以下内容:

server ntp.aliyun.com
server ntp.ntsc.ac.cn

接下来就运行 ntpd 服务吧:

# systemctl enable ntpd
# systemdtl start ntpd
# systemctl status ntpd

最后一步是需要重新开启 timedatectl 的时间同步功能,大功告成!

# timedatectl set-ntp true
openeuler_risc-v_qemu_install.1645454835.txt.gz · Last modified: 2022/02/21 14:47 by misaka00251
CC Attribution-Share Alike 4.0 International Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 4.0 International