Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Last revisionBoth sides next revision
openeuler_risc-v_qemu_install [2022/02/21 14:47] – Add time settings w/ ntp misaka00251openeuler_risc-v_qemu_install [2023/04/28 02:32] – Add macOS & fix links misaka00251
Line 3: Line 3:
 不要忘记安装最新版的 [[https://qemu.org|QEMU]]以及将 QEMU 的目录添加到环境变量里! 不要忘记安装最新版的 [[https://qemu.org|QEMU]]以及将 QEMU 的目录添加到环境变量里!
  
-去 [[https://repo.openeuler.org/openEuler-preview/RISC-V/Image/|openEuler 官网]]可以下载移植版,获取下面两个文件:+去 [[https://repo.openeuler.org/openEuler-preview/RISC-V/|openEuler 官网]]可以下载移植版,获取下面两个文件:
  
-  * fw_payload_oe.elf +  * fw_payload_oe.elf (或者类似的文件)
   * openEuler-preview.riscv64.qcow2   * openEuler-preview.riscv64.qcow2
  
Line 26: Line 26:
   -append 'root=/dev/vda1 rw console=ttyS0 systemd.default_timeout_start_sec=600 selinux=0 highres=off mem=4096M earlycon' \   -append 'root=/dev/vda1 rw console=ttyS0 systemd.default_timeout_start_sec=600 selinux=0 highres=off mem=4096M earlycon' \
   -bios none   -bios none
 +</file>
 +
 +macOS 下启动:
 +
 +<file powershell run.sh>
 +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
 </file> </file>
  
Line 33: Line 54:
 qemu-system-riscv64 ` qemu-system-riscv64 `
   -nographic -machine virt `   -nographic -machine virt `
-  -smp -m 4G +  -smp -m 16G ` 
-  -kernel fw_payload_oe.elf ` +  -display sdl 
-  -drive file=openEuler-preview.riscv64.qcow2,format=qcow2,id=hd0 `+  -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-blk-device,drive=hd0 `
   -device virtio-net-device,netdev=usernet `   -device virtio-net-device,netdev=usernet `
-  -netdev user,id=usernet,hostfwd=tcp::12055-:22 ` +  -netdev user,id=usernet,hostfwd=tcp::12056-:22 
-  -append 'root=/dev/vda1 rw console=ttyS0 systemd.default_timeout_start_sec=600 selinux=0 highres=off mem=4096M earlycon' +  -device qemu-xhci -usb -device usb-kbd -device usb-tablet 
-  -bios none+  -append 'root=/dev/vda1 rw console=ttyS0 swiotlb=1 loglevel=3 systemd.default_timeout_start_sec=600 selinux=0 highres=off mem=16384M earlycon'
 </file> </file>
  
Line 67: Line 91:
 [repository] [repository]
 name=openEuler-risv-v name=openEuler-risv-v
-baseurl=https://isrc.iscas.ac.cn/mirror/openeuler-sig-riscv/oe-RISCV-repo/+#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 gpgcheck=0
 </file> </file>
Line 77: Line 102:
 不过在这里你可能发现失败了,因为时间不对!通过运行 ''timedatectl'' 可以发现系统时间为 2019 年…… 不过在这里你可能发现失败了,因为时间不对!通过运行 ''timedatectl'' 可以发现系统时间为 2019 年……
  
-这里我们采用 ntp 自动授时的方法。首先了安装 ntpd 包,我们需要手动设置一时间,不过做这个之前先要关闭 ntp service。+这里我们采用 ntp 自动授时的方法。配置文件位于 ''/etc/systemd/timesyncd.conf'',修改内容:
  
-<code+<file conf timesyncd.conf
-timedatectl set-ntp false + This file is part of systemd. 
-timedatectl set-time "2022-01-01 00:00" +
-</code>+#  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.
  
-接下来安装 ''ntp''+[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 
 +</file> 
 + 
 +接下来就运行 ntpd 服务吧
  
 <code> <code>
-dnf install ntp+systemctl enable systemd-timesyncd 
 +# systemctl start systemd-timesyncd 
 +# systemctl status systemd-timesyncd
 </code> </code>
  
-安装之,我们需要去编辑下配置文件,配文件位于 ''/etc/ntp.conf''添加以下内容:+后一步是设时区大功告成!
  
 <code> <code>
-server ntp.aliyun.com +# ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
-server ntp.ntsc.ac.cn+
 </code> </code>
  
-接下来就运行 ntpd 服务吧:+===== Others =====
  
-<code> +''ping'' 在 ''iputils'' 包内。
-# systemctl enable ntpd +
-# systemdtl start ntpd +
-# systemctl status ntpd +
-</code>+
  
-一步是需要重开启 timedatectl 时间同步功能,大功告成!+==== 公共 CI 机器上编译用户模式的 QEMU ==== 
 + 
 +这里我们可以使用清华源来加快 git clone 的速度,然转到最分支用于构建:
  
 <code> <code>
-# timedatectl set-ntp true+$ 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
 </code> </code>
 +
 +上面的 prefix 可以自己定义位置,如果自定义了位置的话下面的 ''QEMU_HOME'' 也要一并修改。
 +
 +在编译成功之后,记得在 ''~/.bashrc'' 内添加环境变量:
 +
 +<file bashrc .bashrc>
 +export QEMU_HOME=/home/misaka00251/program/riscv64-qemu
 +export PATH=$QEMU_HOME/bin:$PATH
 +</file>
 +
 +随后 ''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'' 来获得硬盘空间,结束~~~