通过systemd service启动的程序无法写文件
编译安装 NetworkManager 之后,网络功能瘫痪。提示 read-only file system
:
$ nmcli device wifi rescan
$ nmcli device wifi connect HBC-WiFi
Error: Failed to add/activate new connection: failure adding connection:
error writing to file '/usr/etc/NetworkManager/system-connections/HBC-WiFi.nmconnection':
failed to create file /usr/etc/NetworkManager/system-connections/HBC-WiFi.nmconnection.QZNRI1:read-only file system
但是直接使用命令启动 NetworkManager 时没有这个现象,命令可以正常执行。
sudo NetworkManager --no-daemon
原因是 NetworkManager.service
中的配置包含 ProtectSystem=true
。此配置项使进程以只读模式挂载 /usr
与 /boot
目录。参考: systemd.exec
导致这个问题的原因是编译 NetworkManager 时,设置了 --prefix=/usr
。正确的配置应该是 --prefix=/
。
APT 更新时忽略指定的包
因为网络原因,系统升级时遇到某个包下载失败导致系统无法升级
保持包版本不更新:
sudo apt-mark hold <package>
取消保持包版本:
sudo apt-mark unhold <package>
Jetson Nano 系统安装配置
- 从 Jetson Download Center 下载 系统镜像
- 使用镜像烧录软件(如 Rufus 等)将镜像烧录到内存卡上。
- 将内存卡插到 Jetson 上,插电自动开机,配置都使用默认值即可。
- Jetson 的镜像预装了 CUDA,但是运行
nvcc
会提示找不到,将/usr/local/cuda/bin/
加入 PATH 环境变量即可。
Linux Namespace 说明
Linux Namespace 是 Linux 内核的一组功能,它对内核资源进行分区,以便一组进程看到一组资源,而另一组进程看到一组不同的资源。
目前 Linux 支持 8 种命名空间:
命名空间 | 说明 | 内核版本 |
---|---|---|
Mount Namespace | 挂载命名空间,用于隔离文件系统 | 2.4.19 |
UNIX Time-Sharing Namespace | UTS 命名空间,用于隔离主机名等 | 2.6.19 |
Inter-Process Communication Namespace | IPC 命名空间,用于隔离管道、共享内存等 | 2.6.19 |
Process ID Namespace | PID 命名空间,用于隔离进程号 | 2.6.24 |
Network Namespace | 网络命名空间,用于隔离、网络 | 2.6.24 |
User Namespace | 用户命名空间,用于隔离用户 | 3.8 |
CGroup Namespace | CGroup 命名空间,用于隔离 GGroup | 4.6 |
Time Namespace | 时间命名空间,用于隔离时间 | 5.6 |
Linux 无线网络带宽低的问题
将 /etc/modprobe.d/iwlwifi.conf
文件中的 11n_disable=1
改为 11n_disable=0
,然后重启系统。
制作deb包
安装工具
sudo apt-get install build-essential
sudo apt-get install debmake
配置作者的邮箱和名字
export DEBEMAIL="hubenchang0515@outlook.com"
export DEBFULLNAME="PlanC"
生成 debian
目录
debmake -n
双系统时差问题
Linux 默认把 RTC 时间当作 UTC 时间,而 Windows 默认把 RTC 时间当作本地时间。
因此解决办法就是把 Linux 的 RTC 时间设为本地时间,或者把 Windows 的 RTC 时间设为 UTC 时间。
把 Linux 的 RTC 时间设为本地时间的命令为:
timedatectl set-local-rtc 1
这么做会产生一个警告:
Warning: The system is configured to read the RTC time in the local time zone.
This mode cannot be fully supported. It will create various problems
with time zone changes and daylight saving time adjustments. The RTC
time is never updated, it relies on external facilities to maintain it.
If at all possible, use RTC in UTC by calling
'timedatectl set-local-rtc 0'.
把 Windows 的 RTC 时间设为 UTC 时间的命令为:
Reg add HKLM\SYSTEM\CurrentControlSet\Control\TimeZoneInformation /v RealTimeIsUniversal /t REG_DWORD /d 1
在树莓派上配置 Clash 代理
编译 clash 源码
git clone https://github.com/Dreamacro/clash.git
cd clash
go build
sudo cp clash /usr/bin
如果遇到依赖包无法下载的问题,可以配置 GOPROXY,参考 goproxy.io。
$ export GOPROXY=https://proxy.golang.com.cn,direct
如果遇到
package embed is not in GOROOT
的问题, 这是因为 debian bullseye 的 golang 版本为 1.15,而 embed 是 1.16 版本新增的。可以安装 bullseye-backports 的版本。
$ apt policy golang-go golang-go: Installed: 2:1.15~1 Candidate: 2:1.15~1 Version table: 2:1.19~1~bpo11+1 100 100 https://mirrors.tuna.tsinghua.edu.cn/debian bullseye-backports/main arm64 Packages 100 /var/lib/dpkg/status *** 2:1.15~1 500 500 https://mirrors.tuna.tsinghua.edu.cn/debian bullseye/main arm64 Packages $ sudo apt install golang-go=2:1.19~1~bpo11+1 golang-src=2:1.19~1~bpo11+1
编辑配置文件
配置文件的文件名默认为 config.yaml
,可以放在任何路径。本文放在 /etc/clash
目录中。
启动 clash
$ clash -d /etc/clash
如果遇到
Can't find MMDB, start download
并且下载失败的问题,可以手动下载并放到配置文件目录中。$ wget https://cdn.jsdelivr.net/gh/Dreamacro/maxmind-geoip@release/Country.mmdb -P /etc/clash/
配置 systemd service
创建 /usr/lib/systemd/system/clash.service
文件:
如果要配置为用户级服务,则文件路径为
/usr/lib/systemd/user/clash.service
。后续命令需要附加
--user
选项,且不使用sudo
。
[Unit]
Description=Clash proxy
After=syslog.target systemd-user-sessions.service
[Service]
Type=simple
ExecStart=/usr/bin/clash -d /etc/clash
ExecStop=pkill clash
Restart=on-failure
RestartSec=2
[Install]
WantedBy=multi-user.target
更新配置
$ sudo systemctl daemon-reload
启动 clash
$ sudo systemctl start clash.service
查看启动是否成功
$ sudo systemctl status clash.service
设置自动启动
$ sudo systemctl enable clash.service
配置代理
gsettings
$ gsettings set org.gnome.system.proxy mode manual
$ gsettings set org.gnome.system.proxy.http host localhost
$ gsettings set org.gnome.system.proxy.http port 7890
$ gsettings set org.gnome.system.proxy.http enabled true
$ gsettings set org.gnome.system.proxy use-same-proxy true
环境变量
echo 'export all_proxy=localhost:7890' >> ~/.bashrc
在没有网络的环境下配置 VS Code SSH Remote
VS Code SSH Remote 连接时需要在远程主机上下载 VS Code Server,没有网络时无法自动下载,需要手动下载并复制到正确的路径中去。
点击 VS Code菜单栏 Help->About
,查看当前客户端版本的 <Commit-ID>
:
Version: 1.73.1
Commit: 6261075646f055b99068d3688932416f2346dd3b
Date: 2022-11-09T03:54:53.913Z
Electron: 19.0.17
Chromium: 102.0.5005.167
Node.js: 16.14.2
V8: 10.2.154.15-electron.0
OS: Linux x64 5.15.0-53-generic
Sandboxed: No
根据 <Commit-ID>
下载对应版本的 VS Code Server:
https://vscode.cdn.azure.cn/stable/<Commit-ID>/vscode-server-<OS-Name>-<ARCH>.tar.gz
例如:
https://vscode.cdn.azure.cn/stable/6261075646f055b99068d3688932416f2346dd3b/vscode-server-linux-arm64.tar.gz
将其解压并命名为 <Commit-ID>
,然后复制到 ~/.vscode-server/bin/
目录中。
退出进程的常用信号
参考: GNU libc
$ kill -l
1) SIGHUP 2) SIGINT 3) SIGQUIT 4) SIGILL 5) SIGTRAP
6) SIGABRT 7) SIGBUS 8) SIGFPE 9) SIGKILL 10) SIGUSR1
11) SIGSEGV 12) SIGUSR2 13) SIGPIPE 14) SIGALRM 15) SIGTERM
16) SIGSTKFLT 17) SIGCHLD 18) SIGCONT 19) SIGSTOP 20) SIGTSTP
21) SIGTTIN 22) SIGTTOU 23) SIGURG 24) SIGXCPU 25) SIGXFSZ
26) SIGVTALRM 27) SIGPROF 28) SIGWINCH 29) SIGIO 30) SIGPWR
31) SIGSYS 34) SIGRTMIN 35) SIGRTMIN+1 36) SIGRTMIN+2 37) SIGRTMIN+3
38) SIGRTMIN+4 39) SIGRTMIN+5 40) SIGRTMIN+6 41) SIGRTMIN+7 42) SIGRTMIN+8
43) SIGRTMIN+9 44) SIGRTMIN+10 45) SIGRTMIN+11 46) SIGRTMIN+12 47) SIGRTMIN+13
48) SIGRTMIN+14 49) SIGRTMIN+15 50) SIGRTMAX-14 51) SIGRTMAX-13 52) SIGRTMAX-12
53) SIGRTMAX-11 54) SIGRTMAX-10 55) SIGRTMAX-9 56) SIGRTMAX-8 57) SIGRTMAX-7
58) SIGRTMAX-6 59) SIGRTMAX-5 60) SIGRTMAX-4 61) SIGRTMAX-3 62) SIGRTMAX-2
63) SIGRTMAX-1 64) SIGRTMAX
退出信号:
SIGTERM
- 有礼貌的请求进程正常退出。进程应当按部就班地清理资源并正常终止。关机过程中会触发这个信号。SIGQUIT
- 强力的要求进程退出。进程应当快速清理资源并退出。可以通过Ctrl
+\
触发。SIGKILL
- 强制杀死进程。这个信号不能被阻塞。
不是退出信号但通常用于退出的信号:
SIGHUP
- 终端挂断。关闭终端、退出SSH等操作会触发这个信号。SIGINT
- 中断。可以通过Ctrl
+C
触发。
其它常用信号:
SIGSTOP
- 暂停程序执行。和SIGKILL
一样,不能被阻塞,可以通过Ctrl
+Z
触发。SIGCONT
- 恢复程序执行。可以通过fg
命令触发。
另外常用来退出当前程序的 Ctrl
+ D
发送的是 EOF
,而不是信号。