惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

量子位
Google DeepMind News
Google DeepMind News
爱范儿
爱范儿
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
NISL@THU
NISL@THU
T
Threat Research - Cisco Blogs
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
L
Lohrmann on Cybersecurity
V
Visual Studio Blog
Cyberwarzone
Cyberwarzone
D
Docker
The Hacker News
The Hacker News
C
CERT Recently Published Vulnerability Notes
Vercel News
Vercel News
Project Zero
Project Zero
S
Schneier on Security
aimingoo的专栏
aimingoo的专栏
I
Intezer
腾讯CDC
M
MIT News - Artificial intelligence
Hugging Face - Blog
Hugging Face - Blog
P
Palo Alto Networks Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
AWS News Blog
AWS News Blog
GbyAI
GbyAI
MongoDB | Blog
MongoDB | Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
V
Vulnerabilities – Threatpost
G
Google Developers Blog
N
Netflix TechBlog - Medium
The Cloudflare Blog
Microsoft Security Blog
Microsoft Security Blog
Y
Y Combinator Blog
A
Arctic Wolf
S
Securelist
酷 壳 – CoolShell
酷 壳 – CoolShell
Cisco Talos Blog
Cisco Talos Blog
Recent Announcements
Recent Announcements
C
Cyber Attacks, Cyber Crime and Cyber Security
L
LINUX DO - 热门话题
T
Threatpost
Latest news
Latest news
Blog — PlanetScale
Blog — PlanetScale
Security Latest
Security Latest
Engineering at Meta
Engineering at Meta
大猫的无限游戏
大猫的无限游戏
H
Help Net Security
The GitHub Blog
The GitHub Blog
T
Tor Project blog
P
Proofpoint News Feed

JieJiSS' Blog

为 SQLAlchemy Model 添加 type hint 和 type check 关于基于机器学习的多目标对象追踪算法的文献综述 - JieJiSS' Blog RV64 板子更换 rootfs 指南 - JieJiSS' Blog ACTF2022 safer-tg-bot-{1,2} WP - JieJiSS' Blog A RISC-V gcc pitfall revealed by a glibc update Setup an Arch Linux RISC-V Development Environment 解构赋值踩坑:神秘失踪的数据 - JieJiSS' Blog How's the GDPR (used to) related to my blog Rust is incompatible with LLVM, at least partially python-mtrpacket 在 riscv64 上编译测试不通过 - JieJiSS' Blog 快速获得 RISC-V 开发环境 - JieJiSS' Blog 在 RISC-V 上编译 Node.js 16 Redmi AirDots 3 Pro 连接电脑后蓝牙类别不正确的解决方案 为什么 ArrowFunction 不能 new - JieJiSS' Blog Bilibili 2020-10-24 CTF WriteUp - JieJiSS' Blog 对于又一种对SS流式加密的攻击(奇虎团队)的详细分析 - JieJiSS' Blog 在MacOS上配置dnscrypt-proxy(免分流) - JieJiSS' Blog 市县中心点坐标(经纬度) - JieJiSS' Blog 二项式定理及其推广公式的一种简单理解办法 - JieJiSS' Blog
Boot an Arch Linux RISC-V using qemu-system
2023-03-07 · via JieJiSS' Blog

文章目录

  1. CAUTION
  2. Method
  3. Detailed Explanation (zh)
    1. mkrootfs
    2. mkimg

CAUTION

We (distro packagers) decided to modify GCC spec to get rid of just way too many atomic symbol missing error. AFAIK debian does the same thing in the same way.

So, you may notice that some program compiles without -latomic flag, but that's not the case if you switch to some other distros. I wrote another blog post explaining this in detail.

In short: For GCC you should add -latomic if you use std::atomic<T> where sizeof(T) is lower than 4. Also apply to those __atomic_compare_exchange_2() stuff. Clang is not affected.

Method

This approach requires you to be on a non-RISC-V Arch Linux (x86_64 or aarch64, etc.) machine, because we use pacstrap and pacman.

1
2
3
4
5
6
7

sudo pacman -S arch-install-scripts git qemu-img qemu-system-riscv riscv64-linux-gnu-gcc
git clone https://github.com/CoelacanthusHex/archriscv-scriptlet.git
cd archriscv-scriptlet
./mkrootfs
./mkimg
./startqemu.sh

The default root password is archriscv. You will be asked to change the root password the first time you boot the machine. DO NOT LEAVE IT BLANK, or you won't be able to login as root user later.

If, in the last step, you find yourself stucked at [ OK ] Reached target Graphical Interface for too long, just press Ctrl-C and re-run startqemu.sh.

After booting the machine, you may need to install necessary packages:

1
sudo pacman -S git vim gcc

Detailed Explanation (zh)

mkrootfs

首先执行 /usr/share/makepkg/util.sh 来初始化当前的 bash 环境。这个脚本由 Arch Linux 的 makepkg 提供,里面有许多工具函数,例如 msg 函数可以往屏幕上打印出好看的 log。

1
. /usr/share/makepkg/util.sh

解析参数、显示帮助的部分这里略过。

创建 rootfs 的第一步是确保将会被视作 rootfs 的 / 目录的新创建的文件夹权限正确:

1
2
mkdir -p ./rootfs
sudo chown root:root ./rootfs

随后调用 pacstrap 来生成 rootfs。

1
2
3
4
5
sudo pacstrap \
-C /usr/share/devtools/pacman-extra-riscv64.conf \
-M \
./rootfs \
base

这里的 /usr/share/devtools/pacman-extra-riscv64.conf 是类似于 /etc/pacman.conf 的一个配置文件,其中声明了包括软件源在内的一些配置:

1
2
3
4
5
6
7
8
9
10
11
12
13
14



[core]
Server = https://archriscv.felixc.at/repo/$repo

[extra]
Server = https://archriscv.felixc.at/repo/$repo




[community]
Server = https://archriscv.felixc.at/repo/$repo

这里的软件源配置比较重要,是 pacstrap 魔法的一部分。实际上,在调用 pacstrap 时,传入的 base 参数就告诉 pacstrap 需要从上述源里面下载、安装 base 组里面所有的软件包,其中就包括了 linuxglibcpacman。而上述源就是 riscv64gc 架构的源,其中的软件包均面向 riscv64gc 架构编译,因此可以在 RISC-V 64 位 CPU 上的 Arch Linux 操作系统中运行。在 pacstrap 执行完毕后,base meta package 中的所有软件包都已安装完成,这时的 rootfs 已经安装了 Arch Linux 的最小发行版。

再往下,则是配置镜像源。

1
sudo sed -E -i 's|#(Server = https://riscv\.mirror\.pkgbuild\.com/repo/\$repo)|\1|' ./rootfs/etc/pacman.d/mirrorlist

https://riscv.mirror.pkgbuild.com 为 Arch Linux 维护者在 pkgbuild.com 域名上为 Arch Linux RISC-V 创建的全球镜像。如果不添加这个镜像,初始的默认源从国内访问可能较慢或干脆无法访问。

1
2
3
sudo pacman \
--sysroot ./rootfs \
--sync --clean --clean

清空 pacman 的软件包缓存。通过 --sysroot 参数指定了 rootfs。

1
sudo usermod --root $(realpath ./rootfs) --password $(openssl passwd -6 "$password") root

设置系统密码。默认为 archriscvusermod--password 接受的是密码的哈希,因此需要使用 openssl passwd -6 "$password" 算出给定的密码的哈希,再传给 usermod

1
2
3
4
sudo bsdtar --create \
--auto-compress --options "compression-level=9" \
--xattrs --acls \
-f "$filename" -C rootfs/ .

将配置完毕的 rootfs 文件夹压缩为 .tar.gz 格式,使用 --xattrs 以确保文件的 extended attribute 得到保留。压缩成功后,可以删除刚才临时创建的 rootfs 文件夹。

mkimg

TBD

来源:https://blog.jiejiss.com/