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

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
H
Hacker News: Front Page
P
Palo Alto Networks Blog
T
ThreatConnect
Apple Machine Learning Research
Apple Machine Learning Research
博客园_首页
T
True Tiger Recordings
P
Privacy & Cybersecurity Law Blog
B
Blog
IT之家
IT之家
Last Week in AI
Last Week in AI
F
Full Disclosure
Hacker News: Ask HN
Hacker News: Ask HN
C
Comments on: Blog
Microsoft Azure Blog
Microsoft Azure Blog
C
Cybersecurity and Infrastructure Security Agency CISA
Microsoft Security Blog
Microsoft Security Blog
博客园 - 【当耐特】
N
News and Events Feed by Topic
NISL@THU
NISL@THU
腾讯CDC
雷峰网
雷峰网
Security Latest
Security Latest
李成银的技术随笔
M
Microsoft Research Blog - Microsoft Research
L
LangChain Blog
L
Lohrmann on Cybersecurity
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
C
Check Point Blog
Y
Y Combinator Blog
Recent Announcements
Recent Announcements
博客园 - Franky
N
News | PayPal Newsroom
V
V2EX
A
About on SuperTechFans
The Register - Security
The Register - Security
月光博客
月光博客
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Google Online Security Blog
Google Online Security Blog
MyScale Blog
MyScale Blog
Cisco Talos Blog
Cisco Talos Blog
Vercel News
Vercel News
WordPress大学
WordPress大学
C
Cyber Attacks, Cyber Crime and Cyber Security
The Hacker News
The Hacker News
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
爱范儿
爱范儿
A
Arctic Wolf
L
LINUX DO - 最新话题
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More

Mythsman

Chromium + Mitmproxy 组合使用踩坑 记一次家庭科学网络架构调整 Ghost 解决 jsdelivr 资源加载慢的问题 OpenWrt+R66s 软路由入门尝鲜 爬虫浏览器的Cloudflare五秒盾处理 PDF字体乱码问题分析 记一次SSH下无法umount磁盘的问题 Linux主机性能测试方法 利用 Redsocks 解决透明代理的远程抓包问题 利用 FFmpeg 将视频转换为 GIF 操作指北 纯Docker部署Https服务——以Nextcloud为例 快手抓包问题分析 一次采耳引发的屎案 树莓派与1024x600分辨率屏幕的适配问题
树莓派4B使用arm64系统踩坑
2021-12-27 · via Mythsman

背景

由于工作原因,需要一台 arm64 的服务器测试一些功能。但是目前这个点没法快速采购到腾讯云或者百度云的arm服务器(这俩公司的arm服务器好像都只是在内测阶段,据说得2022年初才能 Release)。想了一圈发现树莓派似乎正好有 arm64 的cpu,于是去官网确认了下 Specification

Broadcom BCM2711, Quad core Cortex-A72 (ARM v8) 64-bit SoC @ 1.5GHz

看起来挺好的,于是在亚博智能店里买了个 4B ,但是买到后跑起来发现竟然不是 arm64 的,大呼上当。不过仔细一研究发现原来是原装的 Raspberry os 镜像使用的是 armhf 内核(即支持hard float 的32位 arm )。而树莓派官方其实在 2020 年已经发布了支持 arm64 内核的镜像了,参见这个 Reddit 讨论。同时也发现 arm64 的系统相比 armhf 其实也更能发挥64位cpu的能力。

既然如此,那就搞起来吧。

方案

网上冲浪了一把,发现基本有俩套解决方案:

  1. 修改 /boot/config.txt 的 arm_64bit 配置(参考官方配置文档)。
  2. 重新刷入 arm64 位的镜像。

方案1看起来更方便,方案2看起来更稳妥,于是我挨个试了下。为了验证系统架构的正确性,我也准备了几个测试方法:

  1. uname -a
  2. cat /proc/cpuinfo
  3. getconf LONG_BIT
  4. file /bin/bash
  5. cat /proc/version
  6. dpkg --print-architecture

验证

原始环境配置

首先看一下原版基于 raspios_armhf-2020-05-28 的镜像下的配置情况。

pi@raspberrypi:~ $ uname -a
Linux raspberrypi 5.10.63-v7l+ #1496 SMP Wed Dec 1 15:58:56 GMT 2021 armv7l GNU/Linux
pi@raspberrypi:~ $ cat /proc/cpuinfo
processor : 0
model name : ARMv7 Processor rev 3 (v7l)
BogoMIPS : 108.00
Features : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm crc32
CPU implementer : 0x41
CPU architecture: 7
CPU variant : 0x0
CPU part : 0xd08
CPU revision : 3
processor : 1
model name : ARMv7 Processor rev 3 (v7l)
BogoMIPS : 108.00
Features : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm crc32
CPU implementer : 0x41
CPU architecture: 7
CPU variant : 0x0
CPU part : 0xd08
CPU revision : 3
processor : 2
model name : ARMv7 Processor rev 3 (v7l)
BogoMIPS : 108.00
Features : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm crc32
CPU implementer : 0x41
CPU architecture: 7
CPU variant : 0x0
CPU part : 0xd08
CPU revision : 3
processor : 3
model name : ARMv7 Processor rev 3 (v7l)
BogoMIPS : 108.00
Features : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm crc32
CPU implementer : 0x41
CPU architecture: 7
CPU variant : 0x0
CPU part : 0xd08
CPU revision : 3
Hardware : BCM2711
Revision : d03114
Serial  : 10000000b6d307b2
Model  : Raspberry Pi 4 Model B Rev 1.4
pi@raspberrypi:~ $ getconf LONG_BIT
32
pi@raspberrypi:~ $ file /bin/bash
/bin/bash: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-armhf.so.3, for GNU/Linux 3.2.0, BuildID[sha1]=3e5e2847bbc51da2ab313bc53d4bdcff0faf2462, stripped
pi@raspberrypi:~ $ cat /proc/version
Linux version 5.10.63-v7l+ (dom@buildbot) (arm-linux-gnueabihf-gcc-8 (Ubuntu/Linaro 8.4.0-3ubuntu1) 8.4.0, GNU ld (GNU Binutils for Ubuntu) 2.34) #1496 SMP Wed Dec 1 15:58:56 GMT 2021
pi@raspberrypi:~ $ dpkg --print-architecture
armhf

基本符合预期,唯一让我一开始比较意外的就是 /proc/cpuinfo 里的 Model Name 是 ARMv7 Processor rev 3 (v7l),和官方声称的 ARM v8 并不一致。后来才明白原来这个值也是跟系统内核有关的,有时并不能真正准确的表达真是硬件的属性。这个镜像下的系统的确是32位arm无疑了。

修改环境配置

参照官网配置文档,将 /boot/config.txt 中的 arm64_bit 置位1,重启后重新进行下检测。

pi@raspberrypi:~ $ uname -a
Linux raspberrypi 5.10.63-v8+ #1496 SMP PREEMPT Wed Dec 1 15:59:46 GMT 2021 aarch64 GNU/Linux
pi@raspberrypi:~ $ cat /proc/cpuinfo
processor : 0
BogoMIPS : 108.00
Features : fp asimd evtstrm crc32 cpuid
CPU implementer : 0x41
CPU architecture: 8
CPU variant : 0x0
CPU part : 0xd08
CPU revision : 3
processor : 1
BogoMIPS : 108.00
Features : fp asimd evtstrm crc32 cpuid
CPU implementer : 0x41
CPU architecture: 8
CPU variant : 0x0
CPU part : 0xd08
CPU revision : 3
processor : 2
BogoMIPS : 108.00
Features : fp asimd evtstrm crc32 cpuid
CPU implementer : 0x41
CPU architecture: 8
CPU variant : 0x0
CPU part : 0xd08
CPU revision : 3
processor : 3
BogoMIPS : 108.00
Features : fp asimd evtstrm crc32 cpuid
CPU implementer : 0x41
CPU architecture: 8
CPU variant : 0x0
CPU part : 0xd08
CPU revision : 3
Hardware : BCM2835
Revision : d03114
Serial  : 10000000b6d307b2
Model  : Raspberry Pi 4 Model B Rev 1.4
pi@raspberrypi:~ $ getconf LONG_BIT
32
pi@raspberrypi:~ $ file /bin/bash
/bin/bash: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-armhf.so.3, for GNU/Linux 3.2.0, BuildID[sha1]=3e5e2847bbc51da2ab313bc53d4bdcff0faf2462, stripped
pi@raspberrypi:~ $ cat /proc/version
Linux version 5.10.63-v8+ (dom@buildbot) (aarch64-linux-gnu-gcc-8 (Ubuntu/Linaro 8.4.0-3ubuntu1) 8.4.0, GNU ld (GNU Binutils for Ubuntu) 2.34) #1496 SMP PREEMPT Wed Dec 1 15:59:46 GMT 2021
pi@raspberrypi:~ $ dpkg --print-architecture
armhf

结果有点出乎意料。

通过内核版本查看的cpu架构基本都能正确展示出 aarch64 的关键字,但是其实系统中除了内核之外的其他软件仍然是 32 位的版本(毕竟只是更新了内核)。而且 dpkg 默认使用的软件架构仍然是 32 位的。这意味着当前系统其实有点四不像,既有64位的东西,又有32位的东西,不用想就知道以后100%会踩坑。

同时注意到,刷了新内核之后,cpuinfo 展示硬件信息为 Hardware : BCM2835 ,而原来的硬件信息却是Hardware : BCM2711 。在 gadgetversus 里对比了一下两种芯片:

虽然 2835>2711,但其实是变成了个老版本,真的是闹不明白。。。后来在官方论坛上瞅了瞅,才发现树莓派的软件总监说这好像是因为实际上存在多个芯片类型,但是为了一些上下游兼容的逻辑,就展示了一个错的。。。

顺带吃一个瓜:

mmuaa同学在博客里分享了他的方法。pingwei同学照着弄死机了,也写了个博客,然后还去mmuaa同学的博客下面喷粪,笑死了。

重新刷入镜像

四不像的系统肯定是不要用的,于是就去官网下了Imager,又去清华镜像站里下了 最新的基于 buster (ubuntu 18.04 , debian 10) 的arm64位镜像,烧进TF卡里。装机成功后验证了下数据。

pi@raspberrypi:~ $ uname -a
Linux raspberrypi 5.10.17-v8+ #1414 SMP PREEMPT Fri Apr 30 13:23:25 BST 2021 aarch64 GNU/Linux
pi@raspberrypi:~ $ cat /proc/cpuinfo
processor : 0
BogoMIPS : 108.00
Features : fp asimd evtstrm crc32 cpuid
CPU implementer : 0x41
CPU architecture: 8
CPU variant : 0x0
CPU part : 0xd08
CPU revision : 3
processor : 1
BogoMIPS : 108.00
Features : fp asimd evtstrm crc32 cpuid
CPU implementer : 0x41
CPU architecture: 8
CPU variant : 0x0
CPU part : 0xd08
CPU revision : 3
processor : 2
BogoMIPS : 108.00
Features : fp asimd evtstrm crc32 cpuid
CPU implementer : 0x41
CPU architecture: 8
CPU variant : 0x0
CPU part : 0xd08
CPU revision : 3
processor : 3
BogoMIPS : 108.00
Features : fp asimd evtstrm crc32 cpuid
CPU implementer : 0x41
CPU architecture: 8
CPU variant : 0x0
CPU part : 0xd08
CPU revision : 3
Hardware : BCM2835
Revision : d03114
Serial  : 10000000b6d307b2
Model  : Raspberry Pi 4 Model B Rev 1.4
pi@raspberrypi:~ $ getconf LONG_BIT
64
pi@raspberrypi:~ $  file /bin/bash
/bin/bash: ELF 64-bit LSB pie executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, for GNU/Linux 3.7.0, BuildID[sha1]=b11533bde88bb45ef2891fbf3ad86c1869ed3a41, stripped
pi@raspberrypi:~ $ cat /proc/version
Linux version 5.10.17-v8+ (dom@buildbot) (aarch64-linux-gnu-gcc-8 (Ubuntu/Linaro 8.4.0-3ubuntu1) 8.4.0, GNU ld (GNU Binutils for Ubuntu) 2.34) #1414 SMP PREEMPT Fri Apr 30 13:23:25 BST 2021
pi@raspberrypi:~ $ dpkg --print-architecture
arm64

这下终于统一都是 arm64 的了,虽然 cpuinfo 还是显示的是老的芯片信息(BCM2835),不过毕竟没啥太大影响。

剩下需要注意的就是,在配置新的apt源的时候,/etc/apt/sources.list 直接配置 debian 10 的镜像即可,不要用 raspberrypi 的镜像了;/etc/apt/sources.list.d/raspi.list 里再配置下 raspberrypi 的特定源即可。