2023-07-10 22:50:24 +08:00
|
|
|
#+TITLE: 在 NanoPi R2S 上运行 FreeBSD/OpenBSD
|
|
|
|
#+DATE: <2023-07-10 一>
|
|
|
|
|
|
|
|
曾经有两个树莓派, Pi3 因为碰水, Zero 因为腐蚀, 都报废了
|
|
|
|
|
|
|
|
我想在 R2S 上运行 BSD, 因为:
|
2023-07-13 11:17:37 +08:00
|
|
|
1) it's cool 2) base system 足够, 只需要安装少量包 3) 简洁, 适合小设备
|
2023-07-10 22:50:24 +08:00
|
|
|
|
|
|
|
* 艰辛的历程
|
|
|
|
- 带上手套防止腐蚀, 用螺丝刀和弯头镊子 (文具盒里随手使用) 撬开外壳
|
|
|
|
- 缝合了一个 OpenBSD 镜像, 用 Arduino Uno 当串口连接 UART, 输出毫无意义的字符
|
|
|
|
- 运行 OpwnWRT, 依旧输出垃圾
|
|
|
|
- 运行 Armbian, 依旧输出垃圾, 弹了一会琴后开始思考是不是串口出错了
|
2023-07-13 11:17:37 +08:00
|
|
|
- 翻箱倒柜找到一个 USB Mini-B 线用于 山寨版 Arduino Nano (CH340 芯片)
|
2023-07-10 22:50:24 +08:00
|
|
|
- 重新烧写 OpenBSD 镜像, 成功启动, 但键盘无法输入, 无法安装
|
|
|
|
- 缝合 FreeBSD 镜像, 成功启动, ssh 登录 (user/passwd:freebsd), 耶!
|
|
|
|
- 合上外壳
|
|
|
|
|
|
|
|
** 关于镜像制作
|
|
|
|
- [[https://personalbsd.org][PersonalBSD.org]] 但是构建过程不知道, 不敢用
|
|
|
|
- [[https://asciinema.org/a/381979][asciinema: NanoPi r2s RK3328 with FreeBSD 13-CURRENT]]
|
|
|
|
- [[https://asciinema.org/a/381973][asciinema: NanoPi r2s RK3328 with OpenBSD 6]]
|
|
|
|
|
|
|
|
总的来说就是:
|
|
|
|
#+BEGIN_SRC sh
|
|
|
|
dd if=FreeBSD-13.2-RELEASE-arm64-aarch64-ROCK64.img of=root.img bs=1M
|
|
|
|
dd if=usr/lib/linux-u-boot-edge-nanopi-r2s_22.05.3_arm64/idbloader.bin of=root.img seek=64 conv=notrunc
|
|
|
|
dd if=usr/lib/linux-u-boot-edge-nanopi-r2s_22.05.3_arm64/uboot.img of=root.img seek=16384 conv=notrunc
|
|
|
|
dd if=usr/lib/linux-u-boot-edge-nanopi-r2s_22.05.3_arm64/trust.bin of=root.img seek=24576 conv=notrunc
|
|
|
|
doas dd if=root.img of=/dev/sda
|
|
|
|
#+END_SRC
|
|
|
|
|
|
|
|
|
|
|
|
* 开始
|
|
|
|
- 中国用户第一件事先换源: [[https://mirror.bjtu.edu.cn/help/freebsd/][bjtu FreeBSD 镜像]]
|
|
|
|
- 然后像之前 [[./whatif_openbsd.org][OpenBSD]] 一样还是装机必备软件, 因为是服务器所以没几个
|
|
|
|
#+BEGIN_SRC sh
|
|
|
|
pkg install neofetch oksh sudo git fzf frp
|
|
|
|
#+END_SRC
|
|
|
|
- 改密码, =/usr/local/etc/sudoers=
|
|
|
|
不用 doas 因为 persist 选项只在 OpenBSD 上可用
|
|
|
|
- 主机名, 路由器配置 DHCP 静态 IP, 本机 =/etc/hosts= 加入主机名解析
|
|
|
|
#+BEGIN_SRC sh
|
|
|
|
hostname freebsd-r2s
|
|
|
|
vi /etc/rc.conf
|
|
|
|
#+END_SRC
|
|
|
|
- 改 shell 配置, [[https://github.com/dongdigua/configs/blob/main/.profile.in][基本还是之前那样]]
|
2023-07-13 11:17:37 +08:00
|
|
|
- HZ? 在 Linux 上降低 HZ 是能减少能耗的, 但这里至少温度没降, 先改成 250 吧
|
2023-07-10 22:50:24 +08:00
|
|
|
|
|
|
|
* 第一个服务: gopher
|
|
|
|
#+BEGIN_SRC sh
|
|
|
|
su
|
2023-07-13 11:17:37 +08:00
|
|
|
# freecolor 用于 https://github.com/dongdigua/dongdigua.github.io/blob/main/gmi/docker/cgi/stat.cgi
|
|
|
|
pkg add gophernicus freecolor
|
2023-07-10 22:50:24 +08:00
|
|
|
vi /etc/inetd.conf
|
|
|
|
echo 'inetd_enable="YES"' >> /etc/rc.conf
|
|
|
|
mkdir /var/gopher
|
|
|
|
# don't also chown nobody group so it belongs to wheel group
|
|
|
|
chown nobody /var/gopher
|
|
|
|
chmod 775 /var/gopher
|
|
|
|
service inetd onestart
|
|
|
|
#+END_SRC
|
|
|
|
|
2023-07-13 11:17:37 +08:00
|
|
|
* frpc daemon
|
2023-07-10 22:50:24 +08:00
|
|
|
frp 这完意好啊, 但是 [[https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1030841][Debian 搁置了挺长时间]]也没加入
|
|
|
|
我作为 RHEL7 入坑 Linux 的用户, 没有体验过 systemd 之前的服务管理, 这里可以体验一把.
|
2023-07-13 11:17:37 +08:00
|
|
|
本来以为还得学 rc 脚本, 结果把同目录的 frps 改改就行了
|
|
|
|
别忘了把 gophernicus 的 host 和 port 改成远程主机的
|
|
|
|
|
|
|
|
** SSH 命根子
|
|
|
|
有时想加一个端口转发, 然后一 restart, SSH 也断了, 所以应该把 SSH 转发分开来单独一个服务
|
|
|
|
|
|
|
|
* git 服务器
|
|
|
|
本来想弄个 ssh git 和 cgit, 但仔细考虑感觉没有啥用, 我的 repo 都托管在我朋友的服务器上.
|
|
|
|
又想弄个 sourcehut, 但真的太麻烦了.
|
|
|
|
那不如弄个 gitea, 测试一下一些奇怪的功能, 再做一份镜像.
|
|
|
|
很重要的一点: =HTTP_ADDR= 应设置成 0.0.0.0
|
|
|
|
|
|
|
|
这种比较大的服务可以放在 jail 里, 参考 Absolute FreeBSD
|
|
|
|
|
2023-07-15 12:20:59 +08:00
|
|
|
* jail(8)
|
|
|
|
通用 jail 设置:
|
|
|
|
** 主机
|
|
|
|
=/etc/jail.conf=
|
|
|
|
#+BEGIN_SRC conf
|
|
|
|
exec.clean;
|
|
|
|
exec.start="sh /etc/rc";
|
|
|
|
exec.stop="sh /etc/rc.shutdown";
|
|
|
|
mount.devfs;
|
|
|
|
#+END_SRC
|
|
|
|
|
|
|
|
** in-jail
|
|
|
|
=/etc/crontab= 取消 save-entropy 和 adjkerntz
|
|
|
|
=/etc/rc.conf= 进程越少越好, 似乎我不需要 sendmail
|
|
|
|
#+BEGIN_SRC conf
|
|
|
|
sendmail_submit_enable="NO"
|
|
|
|
sendmail_outbound_enable="NO"
|
|
|
|
sendmail_msp_queue_enable="NO"
|
|
|
|
#+END_SRC
|
|
|
|
|
2023-07-13 11:17:37 +08:00
|
|
|
* TODO microbin
|
2023-07-15 12:20:59 +08:00
|
|
|
足够 micro, 不需要 jail
|
2023-07-13 11:17:37 +08:00
|
|
|
FreeBSD 还没更新 2.0 的 [[https://microbin.eu/docs/installation-and-configuration/configuration/#microbin_data_dir][MICROBIN_DATA_DIR]], 等更新再弄吧.
|
|
|
|
暂时就手动启动
|
|
|
|
|
|
|
|
* Gemini
|
|
|
|
曾经我的 Gemini 是用 Docker 跑在朋友的服务器上, 但是一出问题调试很费劲.
|
|
|
|
现在有个稳定的服务器, 就可以本地跑, 省去许多麻烦.
|
|
|
|
|
|
|
|
依旧使用 jail
|
2023-07-10 22:50:24 +08:00
|
|
|
#+BEGIN_SRC sh
|
2023-07-13 11:17:37 +08:00
|
|
|
su
|
|
|
|
pkg -j gemini install gmid git # python39 and perl5 are included in git
|
|
|
|
jexec -U root gemini git clone https://github.com/dongdigua/dongdigua.github.io.git --depth 1 /dongdigua.github.io
|
|
|
|
jexec -U root gemini sh
|
2023-07-10 22:50:24 +08:00
|
|
|
#+END_SRC
|
2023-07-13 11:17:37 +08:00
|
|
|
then run in sh:
|
|
|
|
#+BEGIN_SRC sh
|
|
|
|
cd /dongdigua.github.io
|
|
|
|
git config --global filter.dater.smudge 'perl -pe "\$last_date = `git log --pretty=format:\\"%ad\\" -1`;s/\\\$Date\\\$/\\\$Date: \$last_date\\\$/"'
|
|
|
|
git config --global filter.dater.clean 'perl -pe "s/\\\$Date[^\\\$]*\\\$/\\\$Date\\\$/"'
|
|
|
|
openssl req -x509 -newkey rsa:4096 -nodes \
|
|
|
|
-out /usr/local/etc/ssl/gmid/localhost.crt \
|
|
|
|
-keyout /usr/local/etc/ssl/gmid/localhost.key \
|
|
|
|
-subj "/CN=localhost"
|
2023-07-10 22:50:24 +08:00
|
|
|
|
2023-07-13 11:17:37 +08:00
|
|
|
openssl req -x509 -newkey rsa:4096 -nodes \
|
|
|
|
-out /usr/local/etc/ssl/gmid/example.com.crt \
|
|
|
|
-keyout /usr/local/etc/ssl/gmid/example.com.key \
|
|
|
|
-subj "/CN=example.com"
|
2023-07-10 22:50:24 +08:00
|
|
|
|
2023-07-13 11:17:37 +08:00
|
|
|
# disable save-entropy and adjkerntz
|
|
|
|
vi /etc/crontab
|
|
|
|
#+END_SRC
|
2023-07-10 22:50:24 +08:00
|
|
|
|
2023-07-13 11:17:37 +08:00
|
|
|
=/usr/local/etc/gmid.conf=:
|
|
|
|
#+BEGIN_SRC conf
|
|
|
|
user "_gmid"
|
|
|
|
|
|
|
|
server "freebsd-r2s" {
|
|
|
|
root "/dongdigua.github.io"
|
|
|
|
cert "/usr/local/etc/ssl/gmid/localhost.crt"
|
|
|
|
key "/usr/local/etc/ssl/gmid/localhost.key"
|
|
|
|
|
|
|
|
cgi "/cgi/*"
|
|
|
|
default type "text/plain"
|
|
|
|
}
|
|
|
|
|
|
|
|
server "example.com" {
|
|
|
|
root "/dongdigua.github.io"
|
|
|
|
cert "/usr/local/etc/ssl/gmid/example.com.crt"
|
|
|
|
key "/usr/local/etc/ssl/gmid/example.com.key"
|
|
|
|
|
|
|
|
cgi "/cgi/*"
|
|
|
|
default type "text/plain"
|
|
|
|
}
|
|
|
|
#+END_SRC
|
|
|
|
|
|
|
|
=/etc/periodic/daily/update-git=:
|
|
|
|
#+BEGIN_SRC sh
|
|
|
|
#! /bin/sh
|
|
|
|
|
|
|
|
cd /dongdigua.github.io
|
|
|
|
git pull --rebase
|
|
|
|
python misc/mdlist2gmi.py > posts.gmi
|
|
|
|
cp -r gmi/docker/cgi .
|
|
|
|
rm index.gmi
|
|
|
|
git checkout -- index.gmi
|
|
|
|
#+END_SRC
|
2023-07-10 22:50:24 +08:00
|
|
|
|
2023-07-15 12:20:59 +08:00
|
|
|
* pf
|
|
|
|
我唯一能控制机器的方式就是 SSH, 使用 pf 可能会有危险.
|
|
|
|
反正服务器是在内网, 只有少数服务通过转发暴露出去.
|
|
|
|
|
|
|
|
* ipfs
|
|
|
|
*提示: =ipfs= 在 FreeBSD 上叫 =ipfs-go=, 不要和已有的程序搞混了*
|
|
|
|
今天我发现 Z Library 开始把书放在 IPFS 上了, 我就想起来要不自己架设个节点.
|
|
|
|
|
2023-07-10 22:50:24 +08:00
|
|
|
* Ref
|
2023-07-13 11:17:37 +08:00
|
|
|
- [[https://feng.si/posts/2019/06/freebsd-and-risc-v-the-future-of-open-source-iot-ecosystem/][FreeBSD 与 RISC-V: 开源物联网生态系统的未来]]
|
2023-07-15 12:20:59 +08:00
|
|
|
- [[https://lists.freebsd.org/archives/freebsd-arm/2021-June/000149.html][freebsd-arm: FriendlyARM NanoPi R2S board support.]]
|
2023-07-10 22:50:24 +08:00
|
|
|
- [[https://hauweele.net/~gawen/blog/?p=2662][FreeBSD on NanoPi R2S]] 提到网络有时会卡住, 我也遇到了
|
2023-07-13 11:17:37 +08:00
|
|
|
- 关于 systemd 有个不错的视频: [[https://www.bilibili.com/video/BV1oo4y1x7Nw][【人肉精翻】systemd的悲剧]] [[https://youtu.be/o_AIw9bGogo][YouTube]]
|