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
openeuler_risc-v_qemu_install [2022/02/21 14:28] – Change shell misaka00251openeuler_risc-v_qemu_install [2023/04/28 02:34] (current) – Disclaimer 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 50: Line 74:
  
 默认的用户名为 ''root'',密码为 ''openEuler12#$'' 默认的用户名为 ''root'',密码为 ''openEuler12#$''
 +
 +注意,以下都很老了(已经不存在这些问题),仅仅作为存档用途出现在这里。
 +
 +===== 软件源 =====
 +
 +openEuler 使用的是 dnf 作为包管理器,配置文件在 ''/etc/dnf/dnf.conf''
 +
 +默认安装了 vim ,可以使用 vim 进行编辑。写入以下数据:
 +
 +<file conf 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/
 +baseurl=https://repo.openeuler.org/openEuler-preview/RISC-V/everything/
 +gpgcheck=0
 +</file>
 +
 +然后执行 ''dnf update'' 即可。
 +
 +===== 系统时间 =====
 +
 +不过在这里你可能发现失败了,因为时间不对!通过运行 ''timedatectl'' 可以发现系统时间为 2019 年……
 +
 +这里我们采用 ntp 自动授时的方法。配置文件位于 ''/etc/systemd/timesyncd.conf'',修改为以下内容:
 +
 +<file conf 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
 +</file>
 +
 +接下来就运行 ntpd 服务吧:
 +
 +<code>
 +# systemctl enable systemd-timesyncd
 +# systemctl start systemd-timesyncd
 +# systemctl status systemd-timesyncd
 +</code>
 +
 +最后一步是设置时区,大功告成!
 +
 +<code>
 +# ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
 +</code>
 +
 +===== Others =====
 +
 +''ping'' 在 ''iputils'' 包内。
 +
 +==== 公共 CI 机器上编译用户模式的 QEMU ====
 +
 +这里我们可以使用清华源来加快 git clone 的速度,然后转到最新版的分支用于构建:
 +
 +<code>
 +$ 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>
 +
 +上面的 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'' 来获得硬盘空间,结束~~~