RK3588在Armbian上运行PIKVM

项目运行环境

  • 硬件环境:HinLink H88K | Armbian
  • 参考借鉴:fruity-pikvm | ustreamer命令手册 | One-KVM文档
  • 简单说明:将设备HDMI接到H88K的HDMI IN接口,用一条 Type-C公头--USB-A公头线,Type-C公头插入H88K的OTG口(Type-C供电接口旁边那个全功能的Type-C接口),USB-A公头插到设备USB接口中

简单安装方法

  1. 本项目依赖 Python 3.10,可以选择预装了 Python 3.10 的发行版,例如 Ubuntu jammy

  2. 根据项目手册安装

1
2
3
4
sudo apt install -y git
git clone http://github.com/jacobbar/fruity-pikvm
cd fruity-pikvm
sudo ./install.sh
  1. 由于本项目的ustreamer不支持rk3588的NV24等,用支持NV24的替换掉它们
1
2
3
4
5
6
sudo apt install build-essential libevent-dev libjpeg-dev libbsd-dev
git clone -b rk3588-b https://github.com/Vincent056/ustreamer.git
cd ustreamer && make

cp src/ustreamer.bin /usr/bin/ustreamer
cp src/ustreamer-dump.bin /usr/bin/ustreamer-dump
  1. 修改 /etc/kvmd/main.yaml 配置中的 kvmd-videovideo0
1
2
3
4
5
6
7
8
9
10
# 修改kvmd-video为video0
- "--device=/dev/kvmd-video"

# 然后就可以尝试启动了,默认用户名:admin,密码:admin,无2FA代码
sudo systemctl restart kvmd # 重启KVMD
sudo systemctl stop kvmd # 停止KVMD
sudo systemctl disable --now kvmd-webterm # 禁用web终端

kvmd-otg start
kvmd --run

高级安装方法

  1. 安装依赖及本项目包
1
2
3
4
sudo apt update
sudo apt install -y nginx tesseract-ocr tesseract-ocr-eng janus libevent-dev libgpiod-dev
wget https://github.com/jacobbar/fruity-pikvm/releases/download/debfile/fruity-pikvm_0.2_arm64.deb
sudo dpkg -i fruity-pikvm_0.2_arm64.deb
  1. 由于本项目依赖 Python 3.10,如果你用的是预装 Python 3.10 的发行版如 Ubuntu jammy,那么可以直接跳过下面编译Python这步

  2. 如果你系统发行版预装的Python为其它版本(例如:bookworm预装版本为3.11),那么请自行编译所需Python版本

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
sudo apt update
sudo apt install build-essential uuid-dev xz-utils zlib1g-dev tk-dev \
libssl-dev libffi-dev libbz2-dev liblzma-dev libreadline-dev \
libsqlite3-dev libgdbm-dev libgdbm-compat-dev libncurses-dev

wget https://www.python.org/ftp/python/3.10.9/Python-3.10.9.tgz
tar xzf Python-3.10.9.tgz
cd Python-3.10.9

./configure --enable-optimizations --prefix=/usr/local # 默认安装位置为:/usr/local
make -j$(nproc)
sudo make altinstall # 跳过创建python链接和手册页链接的操作

sudo rm /usr/sbin/python
sudo ln -s /usr/local/bin/python3.10 /usr/sbin/python
sudo bash -c "echo '/usr/local/lib/python3.10/kvmd-packages' > /usr/local/lib/python3.10/site-packages/kvmd.pth"

# 如果运行 kvmd -m 时提示 No module named 'kvmd' 那么按下面解决
# 在 /usr/local/lib/python3.10/site-packages/kvmd.pth 文件中添加如下一行(即kvmd-packages路径)
# echo "/usr/local/lib/python3.10/kvmd-packages" > /usr/local/lib/python3.10/site-packages/kvmd.pth

# 或者修改变量来临时启动PiKVM命令
# export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python3.10/kvmd-packages/
  1. 编译支持RK3588中HDMIRX所需的NV24格式支持的ustreamer程序
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# 既可简单的使用动态编译
git clone -b rk3588-b https://github.com/Vincent056/ustreamer.git
cd ustreamer && make
cp src/ustreamer.bin /usr/bin/ustreamer
cp src/ustreamer-dump.bin /usr/bin/ustreamer-dump


# 也可选择如下的静态编译方法
1. 在Armbian上静态编译需要安装如下:
sudo apt install build-essential libevent-dev libjpeg-dev libbsd-dev libmd-dev

2. 在Alpine下静态编译需要安装如下:
apk add gcc make libc-dev libevent-dev libevent-static libjpeg-turbo-dev libjpeg-turbo-static libbsd-dev libbsd-static libmd-dev

3. 修改src/Makefile第16行
_LDFLAGS = $(LDFLAGS) -static
_COMMON_LIBS = -l:libm.a -l:libjpeg.a -l:libpthread.a -l:librt.a
_USTR_LIBS = $(_COMMON_LIBS) -l:libevent.a -l:libevent_pthreads.a -l:libbsd.a -l:libmd.a

4. 去除调试信息来减肥
strip src/ustreamer.bin src/ustreamer-dump.bin

5. 查看动态连接程序依赖的库
readelf -a src/ustreamer.bin | grep "NEEDED"

6. 用编译的支持NV24格式的替换掉本项目中不支持的版本
cp src/ustreamer.bin /usr/bin/ustreamer
cp src/ustreamer-dump.bin /usr/bin/ustreamer-dump

7. 测试程序是否正常(通过设备 IP:8080 访问,默认端口8080)
ustreamer --device=/dev/video0 --host=0.0.0.0 --port=80

端口账户密码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# 修改端口请编辑如下文件,将相关端口修改为所需端口(80端口会重定向到443)然后重启服务即可
# /etc/kvmd/nginx/listen-http.conf
listen 80;
listen [::]:80;

# /etc/kvmd/nginx/listen-https.conf
listen 443 ssl http2;
listen [::]:443 ssl http2;


# 添加用户后请输入密码
sudo kvmd-htpasswd set UserName

# 删除用户
sudo kvmd-htpasswd del admin

# 列出所有用户
sudo kvmd-htpasswd list

#重启服务,使修改立刻生效
sudo systemctl restart kvmd kvmd-nginx

通过VNC连接

1
2
3
4
5
6
7
8
9
# Windows可以使用开源的TigerVNC来连接,输入IP和账号密码后(默认为admin/admin)就能连接了
# 不过安卓(AVNC)端需要强制使用Avncuth(即安全性不能使用自动)才能成功连接(默认端口5900)
systemctl enable kvmd-vnc
systemctl start kvmd-vnc

# VNC密码的修改需手动在文件 /etc/kvmd/vncpasswd 修改或添加密码映射
# 添加内容为 自定义VNC密码 -> WEB账户:WEB密码 如下为示例:
admin -> admin:admin
passwd -> UserName:PassWord

模拟插入U盘

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# 应用补丁需要为MSD功能挂载一个分区,通过U盘设备模拟功能可以进行远程挂载镜像,进行重装系统。这里使用IMG镜像代替分区
dd if=/dev/zero of=/root/disk.img bs=1M count=1024
mkfs.ext4 /root/disk.img

# 将新建的IMG镜像分区挂载项添加到 /etc/fstab 中
/root/disk.img /var/lib/kvmd/msd ext4 nodev,nosuid,noexec,rw,errors=remount-ro,data=journal,X-kvmd.otgmsd-root=/var/lib/kvmd/msd,X-kvmd.otgmsd-user=kvmd 0 0

# 到 /etc/kvmd/override.yaml 将msd选项由 disabled 修改为 otg
kvmd:
msd:
type: otg

# 挂载分区并应用补丁
mount /root/disk.img
cd /usr/local/lib/python3.10/kvmd-packages/
wget -O /tmp/3.198msd.patch https://github.com/jacobbar/fruity-pikvm/raw/main/patches/3.198msd.patch
patch -s -p0 < /tmp/3.198msd.patch

# 如果打开网页发现没有出现MSD的话,需要重启主机或重启服务
sudo systemctl restart kvmd-otg kvmd

网络唤醒支持

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# 首先获取被控机网卡的MAC地址记录下来(格式为linux小写)
# 然后编辑 /etc/kvmd/override.yaml 添加如下内容(请注意格式缩进,否则会导致服务启动失败)
# 完成后重启服务:sudo systemctl restart kvmd

kvmd:
msd:
type: disabled

gpio:
drivers:
wol_server1:
type: wol
mac: 12:34:56:78:90:ab
scheme:
wol_server1:
driver: wol_server1
pin: 0
mode: output
switch: false
view:
table:
- ["#Win32 PC", "wol_server1|Send Wake-on-LAN"]

启用文本识别

1
2
3
# 文本识别功能是默认开启的不过没有中文语言包。下列命令可以安装中文语言包:
sudo apt install tesseract-ocr-chi-sim
sudo systemctl restart kvmd

将其打DEB包

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# 现在来将其打包成支持RK3588的DEB包,以便后续分发部署
# 因为打包前文件是什么用户所有和权限,打包后就是什么样的,所以建议全程用root用户执行

# 解包fruity-pikvm到指定文件夹
dpkg-deb -X fruity-pikvm_0.2_arm64.deb pikvm/

# 解包 DEBIAN/ 等文件到指定文件夹
dpkg-deb -e fruity-pikvm_0.2_arm64.deb pikvm/DEBIAN/

# 替换ustreamer为支持rk3588的版本,再修改采集设备为 /dev/video0
dpkg-deb -b pikvm/ fruity-pikvm_rk3588_arm64.deb


###########################################################
# 编译Python并将其打成DEB包
tar -xzvf Python-3.10.9.tgz && cd Python-3.10.9/
./configure --enable-optimizations --prefix=/home/leux/Python/usr/local
make -j$(nproc)
make altinstall
mkdir /home/leux/Python/DEBIAN/

# 该Python包的软件信息
cat << EOF > /home/leux/Python/DEBIAN/control
Package: python3.10
Version: 3.10.9-1
Architecture: arm64
Maintainer: leux <leux@xxx.org>
Description: The Python Language (Version 3.10.9)
EOF

# 安装之后运行的脚本
cat << EOF > /home/leux/Python/DEBIAN/postinst
#! /bin/sh

ln -sf /usr/local/bin/python3.10 /usr/sbin/python
echo "/usr/local/lib/python3.10/kvmd-packages" > /usr/local/lib/python3.10/site-packages/site-packages.pth
EOF

# 卸载之前运行的脚本
cat << EOF > /home/leux/Python/DEBIAN/prerm
#! /bin/sh

rm /usr/sbin/python
rm /usr/local/lib/python3.10/site-packages/site-packages.pth
EOF

cd /home/leux/
chmod 755 /home/leux/Python/DEBIAN/prerm # 需要执行权限
chmod 755 /home/leux/Python/DEBIAN/postinst # 需要执行权限
dpkg -b Python/ python3.10_arm64.deb # 将其制作成包

sudo apt install -y nginx tesseract-ocr tesseract-ocr-eng janus libevent-dev libgpiod-dev
dpkg -i fruity-pikvm_rk3588_arm64.deb # 安装制作的包
dpkg -i python3.10_arm64.deb # 安装制作的包

# 注意:pikvm与python安装完重启后再登录,否则有可能因为otg问题而无法访问