再次在 OrangePi 5 Plus 上安装 Redroid,并启用 GPU 加速

发布于 2 天前  21 次阅读


前言

之前曾经写过一篇文章,讲如何在 Linux 6.1 的 OPi5+上面安装 Redroid ,但是由于在此版本的内核上,并没有直接可用的GPU驱动,于是尝试在 Linux 5.10 内核(因为总有被害妄想症感觉官方的镜像会被塞些奇奇怪怪的东西,但是又想有官方内核的GPU支持,我采取了安装 Armbian 之后安装自己编译的香橙派官方内核的办法)上运行 Redroid ,在更改过内核参数并重新编译之后,我确实得到了一个有显卡驱动的 Redroid 容器,并且在上面挂了很长时间的明日方舟。

之后有段时间,想通过香橙派的网卡来做一个软路由,但是在做了很多准备之后却倒在了 ufw 上,使用 ufw enable 时候出现:

➜  Redroid-1 ufw enable
Command may disrupt existing ssh connections. Proceed with operation (y|n)? y
ERROR: problem running ufw-init
iptables-restore v1.8.7 (nf_tables): Couldn't load match `limit':No such file or directory
Error occurred at line: 63
Try `iptables-restore -h' or 'iptables-restore --help' for more information.
iptables-restore v1.8.7 (nf_tables): unknown option "--log-prefix"
Error occurred at line: 24
Try `iptables-restore -h' or 'iptables-restore --help' for more information.
ip6tables-restore v1.8.7 (nf_tables): Couldn't load match `rt':No such file or directory
Error occurred at line: 24
Try `ip6tables-restore -h' or 'ip6tables-restore --help' for more information.
ip6tables-restore v1.8.7 (nf_tables): unknown option "--log-prefix"
Error occurred at line: 24
Try `ip6tables-restore -h' or 'ip6tables-restore --help' for more information.
Problem running '/etc/ufw/before.rules'
Problem running '/etc/ufw/user.rules'
Problem running '/etc/ufw/before6.rules'
Problem running '/etc/ufw/user6.rules'

并且树莓派的所有网络接口都断开了,于是使用更底层的 nftables 来控制。这样凑活了一段时间,始终感觉这样的一个残缺的内核用起来膈应,今天有时间,想着试试刷入官方的镜像,并设置了是否使用我的内核的对照试验,发现果然是我的内核有问题。重新查看内核参数之后我发现,一些 Netfilter/Iptables 的模块默认的参数中使用了模块 <M> 而不是直接编译进内核 <Y>。虽说通过强制加载模组的办法确实能够解决大部分的问题,但是总感觉会缺少一些稳定性和便携性。在再次修改内核参数之后,问题真的得到了解决,ufw 恢复正常了,Redroid也基本可以直接启动了(官方内核不能直接启动,而我的内核之前总是会有莫名其妙的bug)。将此内核安装到我的 Armbian 系统之后,ufw 果然恢复了,Redroid 启动 logcat 也没有报错了。为了记录一下这次经历,我将如何快速的使用 OrangePi 5 Plus 官方 5.10 内核镜像安装 GPU加速的 Redroid 的教程记录在此。

安装镜像

去参考香橙派的文档以各种你感觉舒适的方式安装官方的镜像到你的 OrangePi 5 Plus 上,内核选择旧版的 5.10。

安装内核

前往 https://github.com/SnowSwordScholar/orangepi-build/releases/tag/RK3588-V1.1 下载或者自己构建内核,会有三个文件,使用 sudo apt install ./filename 的办法全部安装上。

配置 Redroid 需要的模组

新建并编辑 /etc/modules-load.d/redroid.conf

nf_conntrack
nf_nat
ip_tables
iptable_filter
iptable_nat
iptable_mangle
iptable_raw
xt_mark
xt_connmark
xt_comment
xt_conntrack
xt_TCPMSS
xt_quota2
xt_bpf
xt_statistic
xt_SET
xt_addrtype

安装 Docker

过程可以问Bing/Google/各种 AI ,不过似乎香橙派官方的系统已经内置了 Docker

拉镜像

找个希望放置 Redroid 数据的地方,新建文件夹,之后新建文件 docker-compose.yml

services:
  redroid:
    image: cnflysky/redroid-rk3588:lineage-20
    container_name: redroid-gpu-1
    restart: unless-stopped
    privileged: true
    ports:
      - "35555:5555"
    volumes:
      - "./data:/data"
    command:
      - "androidboot.redroid_width=1080"
      - "androidboot.redroid_height=1920"
      - "androidboot.redroid_fps=120"
      # uncomment following line to enable magisk
      - "androidboot.redroid_magisk=1"

      # uncomment following line to enable fake wifi
      - "androidboot.redroid_fake_wifi=1"

      # see https://source.android.com/docs/setup/create/new-device PRODUCT_CHARACTERISTICS
      - "ro.build.characteristics=default"

你可以更具 Redroid 的文档自行编辑参数。此处镜像使用了 cnflysky 已经编译好的镜像,为他的开源精神点赞。

之后使用 sudo docker compose up -d 进行启动

从 Docker 容器里面拉驱动

sudo docker exec redroid-gpu-1 tar -C /vendor/etc/firmware/ -c mali_csffw.bin > ~/mali_csffw.tar
sudo tar -xvf ~/mali_csffw.tar -C /lib/firmware/
sudo chmod 644 /lib/firmware/mali_csffw.bin

重启并完成

使用 sudo reboot 重启。

现在,你的 Redroid 已经有了所有启动所需要的条件,你可以使用下面的命令快速的连接到你的 Redroid 容器

adb connect orangepi5plus.lan:35555 | scrcpy --serial=orangepi5plus.lan:35555 --audio-source=playback --audio-dup --video-bit-rate 30M

如果仍然无法正常启动,你可以尝试 docker compose down ,删除 data 目录之后重新重新 docker compose up -d 。如果还有问题,你可以将这篇博客网址和你遇到的问题发给 AI 来寻求解决方案。如果确认有问题,欢迎在文章下面留言讨论