当前位置: 首页 > news >正文

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

图片

图片

 注释:编译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.lryc.cn/news/120689.html

相关文章:

  • Vim学习(三)—— Git Repo Gerrit
  • 论坛项目之用户部分
  • golang内存对齐
  • 【CheatSheet】Python、R、Julia数据科学编程极简入门
  • 【golang】怎样判断一个变量的类型?
  • 怎么学习AJAX相关技术? - 易智编译EaseEditing
  • JDK、JRE、JVM:揭秘Java的关键三者关系
  • 【reactNative混合安卓开发~使用问题持续更】
  • OCR的发明人是谁?
  • 笔记本电脑连上WiFi之后的IP为什么会变?如何让它不变固定住?
  • 【数学建模】--因子分析模型
  • RAM不够?CUBEIDE使用CCMRAM
  • npm ERR! code ERESOLVEnpm ERR! ERESOLVE unable to resolve dependency tree
  • 使用 prometheus client SDK 暴露指标
  • Jmeter之BeanShell取出参数进行四则运算,并判断是否正确
  • PYTHON 斗地主发牌 (简易版)
  • CSS文本裁剪
  • ClickHouse常见的引擎和使用
  • 构建之法 - 软件工程实践教学:一线教师的13问
  • 联调 matlab 遇到的一些事儿
  • 时序预测 | Matlab实现基于GRNN广义回归神经网络的电力负荷预测模型
  • 3.2 Tomcat基础
  • 认识http的方法、Header、状态码以及简单实现一个http的业务逻辑
  • Faiss在windows下安装和使用
  • 【JavaEE进阶】SpringBoot项目的创建
  • c++二进制转化十进制代码(小数)
  • 07_ansible, 条件选择、加载客户事件、在roles和includes上面应用’when’语句、条件导入、基于变量选择文件和模版、注册变量
  • 4个简化IT服务台任务的ChatGPT功能
  • 群晖7.X版安装cpolar内网穿透
  • [保研/考研机试] KY183 素数 北京航空航天大学复试上机题 C++实现