刘芮妍 發表於 2023-8-8 19:07:00

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

<p><img src="https://img2023.cnblogs.com/blog/3253146/202308/3253146-20230808190501197-1216106765.png"></p>
<p>&nbsp;</p>
<p><img src="https://img2023.cnblogs.com/blog/3253146/202308/3253146-20230808190515605-495948093.png"></p>
<p>&nbsp;</p>
<p><strong>注释:编译Fedora,HS-2 64核RISC-V服务器比Ryzen5700x快两倍!</strong></p>
<p><span>--- 以下是blog 正文 ---</span></p>
<p># Compiling The Fedora Linux Kernel Natively on RISC-V</p>
<p>## Fedora RISC-V Support</p>
<p>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&nbsp;</p>
<p>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.</p>
<p>&nbsp;</p>
<p>## Setting Up A Fedora Chroot Environment On The PerfXLab System</p>
<p>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</p>
<p>be able to get into the appropriate build environment as not to run into any issues with the build or contaminate the host system.</p>
<p>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</p>
<p>essentially a premade rootfs originally designed for coincidentally the Licheepi 4A and T-Head variants!&nbsp;</p>
<p>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</p>
<p>found the root partition (usually the largest partition) then mounted it, so I can work on chrooting into it.&nbsp;</p>
<p>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</p>
<p>this type of work and started mounting the virtual kernel filesystems.&nbsp;</p>
<p>```</p>
<p>&nbsp;</p>
<p># Just for ease of running the commands :)</p>
<p>LFS="/home/maxinehayes90/fedora_rv_mnt"</p>
<p># Populate /dev</p>
<p>sudo mount -v --bind /dev $LFS/dev</p>
<p>&nbsp;</p>
<p># Mount virtual kernel filesystems</p>
<p>mount -v --bind /dev/pts $LFS/dev/pts</p>
<p>mount -vt proc proc $LFS/proc</p>
<p>mount -vt sysfs sysfs $LFS/sys</p>
<p>mount -vt tmpfs tmpfs $LFS/run</p>
<p>```</p>
<p>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</p>
<p>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</p>
<p>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</p>
<p>this file into the chroot as /etc/resolv.conf. Success! Dnf was able to download the metadata!&nbsp;</p>
<p>&nbsp;</p>
<p>## Building The Fedora Kernel In The Chroot Environment</p>
<p>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.</p>
<p>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.&nbsp;</p>
<p>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</p>
<p>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!&nbsp;</p>
<p>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</p>
<p>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.</p>
<p>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</p>
<p>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!</p>
<p>&nbsp;</p>
<p>## Resources</p>
<p>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</p>
<p>Fedora T-Head Documentation: https://fedoraproject.org/wiki/Architectures/RISC-V/T-Head</p>
<p>Linux From Scratch VKFS Page: https://www.linuxfromscratch.org/lfs/view/stable/chapter07/kernfs.html</p>
<p>PerfXLab (Thank you Paul Wang for giving me access to the RISC-V Server!): http://www.perfxlab.com/</p>
<ul class="list-paddingleft-1">
<li>About HS-2</li>
</ul>
<p class="js_darkmode__text__1">HS-2 RISC-V通用主板是澎峰科技与合作伙伴共同研发的一款专为开发者设计的标准mATX主板,它预装了澎峰科技为RISC-V高性能服务器定制开发的软件包,包括各种标准bencmark、支持V扩展</p>
<p class="js_darkmode__text__1"><span>的GCC编译器、计算库、中间件以及多种典型服务器应用程序。</span></p>
<p class="js_darkmode__text__2">HS-2 RISC-V通用主板搭载了一颗国产RISC-V 64核处理器(SG2042)。SG2042是目前已量产的性能最高的RISC-V处理器,主要针对高性能计算领域需求设计,适用于科学计算、工程计算、AI计算、融合计算等大算力应用场景。</p>
<p><img src="https://img2023.cnblogs.com/blog/3253146/202308/3253146-20230808190550894-1499612213.png"></p>
<p>&nbsp;</p>
<ul class="list-paddingleft-1">
<li>
<p><strong>加入我们的RISC-V社区</strong></p>
</li>
</ul>
<p>1. 发邮件到 riscvinfo@perfxlab.com 进行申请</p>
<p>2. 加入微信讨论群:加iYuta-R2为好友后可拉入群</p>
<p>3. 加入QQ讨论群:906962594(RVBoards·Only RISC-V)</p>
<p><img src="https://img2023.cnblogs.com/blog/3253146/202308/3253146-20230808190636245-269154080.png"></p>
<p>&nbsp;</p>
<p class="js_darkmode__15" data-style="outline: 0px; font-family: system-ui, -apple-system, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif; letter-spacing: 0.544px;text-align: center;">&nbsp;</p>
<ul class="list-paddingleft-1">
<li>
<p><strong>关于RISC-V公共测试平台</strong></p>
<p><img src="https://img2023.cnblogs.com/blog/3253146/202308/3253146-20230808190653447-2012264433.png"></p>
<p>&nbsp;</p>
</li>
</ul>
<p>&nbsp;&nbsp;&nbsp;&nbsp;<span><span>RISC-V高性能处理器公共测试云平台 ·快速使用指南,<span>下载链接:<span>https://www.kdocs.cn/l/cmnYcyFIlVRx</span></span></span></span></p>
<ul class="list-paddingleft-1">
<li>
<p><strong>"RISC-V成长日志"BLOG</strong></p>
</li>
</ul>
<p>这是第一个运行在RISC-V服务器上的正式BLOG,它记录RISC-V社区的一些关于成长的动态。欢迎收藏!</p>
<p><strong>htpp://blog.rvv.top:8002</strong></p>
<ul class="list-paddingleft-1">
<ul class="list-paddingleft-1">
<li>
<p><strong>RISC-V公共测试云平台系列文章</strong></p>
</li>
<li><span><span class="js_darkmode__text__52">1.&nbsp;<span><span class="js_darkmode__text__53">RISC-V公测平台发布 ·Stream带宽完整测试</span></span><br></span></span></li>
<li>
<p class="js_darkmode__6" data-style="margin-bottom: 8px; outline: 0px; font-family: system-ui, -apple-system, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif; letter-spacing: 0.544px; "><span class="js_darkmode__text__54">2.&nbsp;<span><span class="js_darkmode__text__55">RISC-V公测平台发布 · 我的世界MohistMC</span></span><br></span></p>

</li>
<li>
<p class="js_darkmode__7" data-style="margin-bottom: 8px; outline: 0px; font-family: system-ui, -apple-system, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif; letter-spacing: 0.544px; "><span class="js_darkmode__text__56">3.&nbsp;RISC-V<span><span><span class="js_darkmode__text__58">公测平台发布 · 第一个WEB Server“Hello RISC-V world!”</span></span></span></span></p>

</li>
<li>
<p class="js_darkmode__8" data-style="margin-top: 8px; margin-bottom: 8px; outline: 0px; font-family: system-ui, -apple-system, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif; letter-spacing: 0.544px; "><span class="js_darkmode__text__59">4.&nbsp;RISC-V公测平台发布 ·如何在SG2042上玩转k3s</span></p>

</li>
<li>
<p class="js_darkmode__9" data-style="margin-top: 8px; margin-bottom: 8px; outline: 0px; font-family: system-ui, -apple-system, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif; letter-spacing: 0.544px; "><span><span class="js_darkmode__text__61">5<span class="js_darkmode__text__62">.&nbsp;<span class="js_darkmode__text__63">“RISC-V成长日记” blog发布,第一个运行在RISC-V服务器上的blog?</span></span></span></span></p>

</li>
<li>
<p class="js_darkmode__10" data-style="margin-top: 8px; margin-bottom: 8px; outline: 0px; font-family: system-ui, -apple-system, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif; letter-spacing: 0.544px; "><span class="js_darkmode__text__64">6.&nbsp;RISC-V公测平台发布:如何在SG2042上玩转OpenMPI</span></p>

</li>
<li>
<p class="js_darkmode__10" data-style="margin-top: 8px; margin-bottom: 8px; outline: 0px; font-family: system-ui, -apple-system, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif; letter-spacing: 0.544px; ">7. RISC-V公测平台发布:Compiling The Fedora Linux Kernel Natively on RISC-V(本篇)</p>
<p class="js_darkmode__10" data-style="margin-top: 8px; margin-bottom: 8px; outline: 0px; font-family: system-ui, -apple-system, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif; letter-spacing: 0.544px; ">欢迎投稿,发送至riscvinfo@perfxlab.com</p>

</li>

</ul>
</ul>
<p>&nbsp;</p><br><br>
来源:https://www.cnblogs.com/lsxd/p/17615182.html
頁: [1]
查看完整版本: RISC-V云测平台:Compiling The Fedora Linux Kernel Natively on RISC-V