RISC-V云测平台:Compiling The Fedora Linux Kernel Natively on RISC-V

news/2025/2/16 0:39:51/

图片

图片

 注释:编译Fedora,HS-2 64核RISC-V服务器比Ryzen5700x快两倍!

--- 以下是blog 正文 --- 

# Compiling The Fedora Linux Kernel Natively on RISC-V

## Fedora RISC-V Support

There is ongoing work to Fedora to support RISC-V hardware. As of right now the Fedora documentation officially only shows how to install the distribution on the SiFive HiFive Unleashed 

board. Although there is another board which is unofficially supported by Fedora. This board is the Sispeed LicheePi 4A which I have been planning on getting for Project Andre and Fedora development.

## Setting Up A Fedora Chroot Environment On The PerfXLab System

The PerfXLab RISC-V server is running Ubuntu 22.10, so getting a Fedora environment to compile the kernel in took a bit of tinkering. I knew I needed a container or a chroot environment to

be able to get into the appropriate build environment as not to run into any issues with the build or contaminate the host system.

I started out by looking for a pre-compiled RISC-V Fedora rootfs to use as my chroot environment. During my search I found a pre-built RISC-V raw image. This raw image was perfect! It was

essentially a premade rootfs originally designed for coincidentally the Licheepi 4A and T-Head variants! 

Once I downloaded the image to the PerXLab system I started mounting the raw image as a loopback device. One of the easiest ways to dissect a raw image is by doing this quick hack! I then

found the root partition (usually the largest partition) then mounted it, so I can work on chrooting into it. 

Once I got the partition mounted I started setting up the pre-requisites for a fully functioning chroot environment. I reffered to the trust Linux From Scratch book like I often do with

this type of work and started mounting the virtual kernel filesystems. 

```

# Just for ease of running the commands :)

LFS="/home/maxinehayes90/fedora_rv_mnt"

# Populate /dev

sudo mount -v --bind /dev $LFS/dev

# Mount virtual kernel filesystems

mount -v --bind /dev/pts $LFS/dev/pts

mount -vt proc proc $LFS/proc

mount -vt sysfs sysfs $LFS/sys

mount -vt tmpfs tmpfs $LFS/run

```

Now that /dev and the VKFS are mounted I could chroot into the Fedora rootfs by simply just running ```sudo chroot $LFS /bin/bash```. In the chroot I made sure to test if I had a network

connection by running a dnf search for a package. I got an error where dnf couldn't download the metadata, so I made sure to copy /etc/resolv.conf on the host to the chroot environment. I

then ran into the issue of not being able to copy it due to it being a symlink. Once I tracked down the symlink I saw that it was pointed to /run/systemd/resolve/stub-resolv.conf. I copied

this file into the chroot as /etc/resolv.conf. Success! Dnf was able to download the metadata! 

## Building The Fedora Kernel In The Chroot Environment

For Fedora there is a Koji that supplies RISC-V package builds. I went to the Koji hosted at http://fedora.riscv.rocks/koji/ and downloaded the kernel source RPM into the chroot using wget.

To build the kernel source I initially installed mock and looked for a RISC-V config. I unfortunately didn't find one it in /etc/mock. After finding that out I went with plan b by using rpmbuild. 

To build the source code with rpmbuild I first had to install the dependencies that the specfile requires using ```dnf builddep SPECS/kernel.spec```. Once I did that I was set to build the kernel! I started the build using ```time rpmbuild -bb SPECS/kernel.spec``` then waited a few minutes to see if it would error which it did after about 7 minutes. So I tried a different

version of the kernel which had the same issue. After walking away for a while I relized what the error was. I ran out of disk space in the chroot! 

The root partition I mounted and chrooted into was only a few gigabytes in size and when building the kernel I had forgotten this detail. What I did to resolve the issue was to unmount all

of the virtual kernel filesystems and /dev. I then copied the mounted rootfs to a directory on the host. After that I remounted the VKFS then chrooted back in where I restarted the build.

Once I restarted the build I sat and waited again for about 20 minutes to see if I would run into another error. When I was sure there wouldn't be the possibility of an error I walked away

and came back the next day to find it build without any issues! To my surprise the build took 1 hour and 37 minutes to complete!

## Resources

Image used: https://openkoji.iscas.ac.cn/pub/dl/riscv/T-Head/th1520_light/images/fedora-disk-minimal_thead_th1520-f38-20230511-210358.n.0-sda.raw.xz

Fedora T-Head Documentation: https://fedoraproject.org/wiki/Architectures/RISC-V/T-Head

Linux From Scratch VKFS Page: https://www.linuxfromscratch.org/lfs/view/stable/chapter07/kernfs.html

PerfXLab (Thank you Paul Wang for giving me access to the RISC-V Server!): http://www.perfxlab.com/

  • About HS-2

HS-2 RISC-V通用主板是澎峰科技与合作伙伴共同研发的一款专为开发者设计的标准mATX主板,它预装了澎峰科技为RISC-V高性能服务器定制开发的软件包,包括各种标准bencmark、支持V扩展

的GCC编译器、计算库、中间件以及多种典型服务器应用程序。

HS-2 RISC-V通用主板搭载了一颗国产RISC-V 64核处理器(SG2042)。SG2042是目前已量产的性能最高的RISC-V处理器,主要针对高性能计算领域需求设计,适用于科学计算、工程计算、AI计算、融合计算等大算力应用场景。

图片

RISC-V公共测试云平台系列文章

1. RISC-V公测平台发布 ·Stream带宽完整测试

2. RISC-V公测平台发布 · 我的世界MohistMC

3. RISC-V公测平台发布 · 第一个WEB Server“Hello RISC-V world!”

4. RISC-V公测平台发布 ·如何在SG2042上玩转k3s

5.“RISC-V成长日记” blog发布,第一个运行在RISC-V服务器上的blog?

6. RISC-V公测平台发布:如何在SG2042上玩转OpenMPI

7. RISC-V公测平台发布:Compiling The Fedora Linux Kernel Natively on RISC-V(本篇)

 


http://www.ppmy.cn/news/1016574.html

相关文章

外卖项目,登录设计,nginx反向代理,MD5明文加密

.gitignore文件里的东西是进行排除,不用git进行管理。登录设计, controller 接收并封装参数调用service方法查询数据库封装结果并响应 登录成功后,生成jwt令牌 Service层 调用mapper查询数据库密码比对返回结果Mapper 编写sql语句为什么前端不…

配置nginx负载均衡

搭建负载均衡服务的需求如下: 1 .把单台计算机无法承受的大规模并发访问或数据流量分担到多台节点设备上,分别进行处理,减少用户等待响应的时间,提升用户体验。 2. 单个重负载的运算分担到多台节点设备上做并行处理,每…

pyqt5 编写一段自定义信号和槽的示例。

使用 PyQt5 创建自定义信号和槽时,通常需要创建一个继承自 QObject 的类来作为信号的源。以下是一个简单的示例,演示了如何创建自定义信号和槽: import sys from PyQt5.QtCore import QObject, pyqtSignal, pyqtSlot from PyQt5.QtWidgets i…

SpringBoot集成websocket(3)|(websocket调用websocket采用回调方式实现数据互传)

SpringBoot集成websocket(3)|(websocket调用websocket采用回调方式实现数据互传) 文章目录 SpringBoot集成websocket(3)|(websocket调用websocket采用回调方式实现数据互传)[TOC] 前…

ffplay数据结构分析(一)

本文为相关课程的学习记录,相关分析均来源于课程的讲解,主要学习音视频相关的操作,对字幕的处理不做分析 下面我们对ffplay的相关数据结构进行分析,本章主要是对PacketQueue的讲解 struct MyAVPacketList和PacketQueue队列 ffp…

【实战】 九、深入React 状态管理与Redux机制(五) —— React17+React Hook+TS4 最佳实践,仿 Jira 企业级项目(二十)

文章目录 一、项目起航:项目初始化与配置二、React 与 Hook 应用:实现项目列表三、TS 应用:JS神助攻 - 强类型四、JWT、用户认证与异步请求五、CSS 其实很简单 - 用 CSS-in-JS 添加样式六、用户体验优化 - 加载中和错误状态处理七、Hook&…

Electron+vue3项目使用SQLite3数据库

SQLite 是一个进程内的库,实现了自给自足的、无服务器的、零配置的、事务性的 SQL 数据库引擎。它是一个零配置的数据库,这意味着与其他数据库不一样,我们不需要在系统中配置。 就像其他数据库,SQLite 引擎不是一个独立的进程&am…

Go Fyne:一种现代的,跨平台的 GUI 开发工具集

Fyne 是一个用 Go 语言写的,提供丰富,现代化的用户界面(UI)的开发工具集。Fyne 提供了一种简单而直观的方式来构建应用程序,并且注意到它是跨平台的,可以在 Windows,macOS,Linux&…