Skip to content

Commit edb229c

Browse files
committed
update
1 parent df17aba commit edb229c

23 files changed

+507
-35
lines changed

README.md

+15-3
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ https://til.adoyle.me
77

88
## 提醒
99

10-
在网页端,搜索英文建议用最上方的搜索框,体验比较好。
11-
搜索框不支持中文,搜中文信息建议用浏览器自带的搜索功能
10+
1. 在网页端,建议搜索英文用最上方的搜索框,体验比较好。搜索框不支持中文。建议搜中文用浏览器自带的搜索功能
11+
2. 文章不保证正确,请自己判断对错。如果你有不同意见,欢迎到 [Discussions](https://github.com/adoyle-h/Today-I-Learned/discussions) 提出意见
1212

1313
## 内容约定
1414

@@ -177,6 +177,7 @@ Read the [NOTICE](./NOTICE) file distributed with this work for additional infor
177177
- [查找 Overlay ID 与哪个容器相关](docker/find-which-container-includes-overlay.md)
178178
- [修正 alpine 镜像的时区问题](docker/fix-timezone-in-alpine-image.md)
179179
- [修正 Docker for mac 时区问题](docker/fix-timezone-in-docker-for-mac.md)
180+
- [host.docker.internal](docker/host-docker-internal.md)
180181
- [Docker for Mac 中磁盘文件占用过大](docker/large-disk-space-usage-in-docker-for-mac.md)
181182
- [docker macvlan](docker/macvlan.md)
182183
- [构建多架构镜像](docker/multi-arch-build.md)
@@ -289,6 +290,7 @@ Read the [NOTICE](./NOTICE) file distributed with this work for additional infor
289290
- [忽略 Git submodule](git/ignore-git-submodule.md)
290291
- [--ours vs --theirs](git/ours-vs-theirs.md)
291292
- [git proxy](git/proxy.md)
293+
- [指定分支与另一个远端仓库绑定](git/push-branch-for-another-remote.md)
292294
- [git shallow clone](git/shallow-clone.md)
293295
- [Git sign-off](git/sign-off.md)
294296

@@ -333,6 +335,7 @@ Read the [NOTICE](./NOTICE) file distributed with this work for additional infor
333335
- [EMMC](hardware/emmc.md)
334336
- [固件 (Firmware)](hardware/firmware.md)
335337
- [Home Assistant](hardware/home-assistant.md)
338+
- [ET X08 鼠标](hardware/mouse-et-x08.md)
336339
- [网件 R6900 刷梅林固件](hardware/netgear-R6900-asuswrt-merlin.md)
337340
- [网络交换机](hardware/network-switch.md)
338341
- [无线电波 (Radio Waves)](hardware/radio-waves.md)
@@ -411,6 +414,7 @@ Read the [NOTICE](./NOTICE) file distributed with this work for additional infor
411414
- [用户线程,内核线程,CPU 超线程技术](linux/about-multi-thread.md)
412415
- [用户增加用户组](linux/add-group-to-user.md)
413416
- [adduser 与 useradd](linux/adduser-and-useradd.md)
417+
- [硬盘电源管理](linux/advanced-power-management.md)
414418
- [ag 和 rg](linux/ag-and-rg.md)
415419
- [Alfred 找不到文件](linux/alfred-cannot-find-files.md)
416420
- [alpine 的 /sbin/init](linux/alpine-sbin-init.md)
@@ -525,6 +529,7 @@ Read the [NOTICE](./NOTICE) file distributed with this work for additional infor
525529
- [进程亲和性 (Processor Affinity)](linux/processor-affinity.md)
526530
- [命令行中提示用户 Yes/No](linux/read-prompt.md)
527531
- [rm 命令](linux/rm.md)
532+
- [旋转终端屏幕](linux/rotate-console-screen.md)
528533
- [rsync 与 scp](linux/rsync-and-scp.md)
529534
- [rsyslog](linux/rsyslog.md)
530535
- [用别的用户运行命令](linux/run-command-with-different-user.md)
@@ -541,6 +546,7 @@ Read the [NOTICE](./NOTICE) file distributed with this work for additional infor
541546
- [strace](linux/strace.md)
542547
- [sudo and su](linux/sudo-and-su.md)
543548
- [sudoer](linux/sudoer.md)
549+
- [sysctl](linux/sysctl.md)
544550
- [syslinux](linux/syslinux.md)
545551
- [Linux 系统调用](linux/system-call.md)
546552
- [tailf](linux/tailf.md)
@@ -576,8 +582,10 @@ Read the [NOTICE](./NOTICE) file distributed with this work for additional infor
576582

577583
### Systemd
578584

579-
- [systemd 网络启动流程](linux/systemd/network.md)
585+
- [systemd-mount](linux/systemd/mount.md)
586+
- [systemd-network](linux/systemd/network.md)
580587
- [networking.service](linux/systemd/networking-service.md)
588+
- [systemd-path](linux/systemd/path.md)
581589
- [systemd-resolved](linux/systemd/resolved.md)
582590
- [systemd](linux/systemd/systemd.md)
583591
- [systemd-timesyncd](linux/systemd/timesyncd.md)
@@ -602,6 +610,7 @@ Read the [NOTICE](./NOTICE) file distributed with this work for additional infor
602610

603611
## Mac
604612

613+
- [MacOS 通过命令行修改 IP 地址](mac/change-ip-address-via-cmd.md)
605614
- [Mac 的 DNS 问题](mac/dns-troubles-in-mac.md)
606615
- [多网卡在 Mac 系统的问题](mac/double-network-card-problems-in-mac.md)
607616
- [Mac 下按住键盘不能输出重复的字符](mac/hold-down-key-cannot-keep-print-character.md)
@@ -746,6 +755,7 @@ Read the [NOTICE](./NOTICE) file distributed with this work for additional infor
746755
- [Chrome 小技巧](others/chrome-tricks.md)
747756
- [复制粘贴好过手写](others/copy-paste-better-than-handwriting.md)
748757
- [Mac 文件系统的剪切快捷键](others/cut-in-mac-file-system.md)
758+
- [数据恢复工具](others/data-recovery-tool.md)
749759
- [YAML 中的 Date 类型陷阱](others/date-trap-in-yaml.md)
750760
- [MacOS 彻底删除搜狗输入法](others/delete-sogou-input-in-macos.md)
751761
- [dropbear](others/dropbear.md)
@@ -762,6 +772,7 @@ Read the [NOTICE](./NOTICE) file distributed with this work for additional infor
762772
- [Hyper.js 中文问题](others/hyper-js-chinese-problems.md)
763773
- [无法在 Tmux 显示图片](others/imgcat-not-work-in-tmux.md)
764774
- [Jekyll](others/jekyll.md)
775+
- [jellyfin 中文字体](others/jellyfin-chinese-font.md)
765776
- [Jinja2](others/jinja2.md)
766777
- [Language Server Protocol](others/language-server-protocol.md)
767778
- [Makefile](others/makefile.md)
@@ -780,6 +791,7 @@ Read the [NOTICE](./NOTICE) file distributed with this work for additional infor
780791
- [Markdown 里写反引号](others/reverse-quote-in-markdown.md)
781792
- [rsync](others/rsync.md)
782793
- [Semver](others/semver.md)
794+
- [SSL 证书校验失败](others/ssl-cert-verify-failed.md)
783795
- [SSL 证书](others/ssl-cert.md)
784796
- [停止词 (Stop Words)](others/stop-words.md)
785797
- [mac 里的 tmux 内无法用 sublime 打开文件](others/subl-in-tmux-on-mac.md)

_docs/intro.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ https://til.adoyle.me
33

44
## 提醒
55

6-
在网页端,搜索英文建议用最上方的搜索框,体验比较好。
7-
搜索框不支持中文,搜中文信息建议用浏览器自带的搜索功能
6+
1. 在网页端,建议搜索英文用最上方的搜索框,体验比较好。搜索框不支持中文。建议搜中文用浏览器自带的搜索功能
7+
2. 文章不保证正确,请自己判断对错。如果你有不同意见,欢迎到 [Discussions](https://github.com/adoyle-h/Today-I-Learned/discussions) 提出意见
88

99
## 内容约定
1010

docker/host-docker-internal.md

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# host.docker.internal
2+
3+
`host.docker.internal` 是 Docker 容器可访问的特殊域名。它指向宿主机的内部 IP。用途是在容器内访问宿主机 IP。
4+
5+
`gateway.docker.internal` 指向 docker daemon 的 gateway IP。
6+
7+
详见 https://docs.docker.com/desktop/networking/#i-want-to-connect-from-a-container-to-a-service-on-the-host
8+
9+
这在 orbstack 也依然可以用。详见 https://docs.orbstack.dev/docker/network#connecting-to-servers-on-mac

docker/rootless-containerd.md

+22
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,25 @@
1919
rootless containerd 进程的配置不使用 `/etc/containerd/config.toml`,而是使用 `${XDG_CONFIG_HOME}/containerd`。(详见 containerd-rootless.sh,它有一行 `mount --bind "${XDG_CONFIG_HOME}/containerd" "/etc/containerd"`
2020

2121
因此创建默认配置文件需要这样 `containerd config default > ~/.config/containerd/config.toml`
22+
23+
## 容器内的非 root 用户没权限读写 volume 文件
24+
25+
有些镜像会修改默认用户,这会导致容器内读写宿主机的 volume 文件时报错没权限。
26+
这是因为 uid/gid 映射到宿主机上不是宿主机用户的 uid/gid。有的时候它的 UID 会是 100999。
27+
28+
据我实测,容器内 uid 与宿主机 uid 的映射关系:
29+
30+
| 容器内 uid | 宿主机 uid |
31+
| ------------ | ----- |
32+
| 1000 | 100999 |
33+
| 1100 | 101099 |
34+
| 9999 | 109998 |
35+
36+
宿主机 uid = 容器内 uid + 100000 -1
37+
38+
### 解决方法
39+
40+
将容器 uid 和 gid 都置为 0,表示 root 用户。`docker run -u 0:0 image cmd`
41+
42+
如果用 compose.yaml,则在 service 下设置 `user: 0:0`。参考 [schema/compose-spec.json](https://github.com/compose-spec/compose-spec/blob/d958c4e3678bbd9aaa4b8368110f47d6d60f123e/schema/compose-spec.json#L362)
43+

git/push-branch-for-another-remote.md

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# 指定分支与另一个远端仓库绑定
2+
3+
## 场景
4+
5+
Fork 别人的库后,我想 `git fetch` 从上游仓库拉去代码,`git push` 的时候推到我的仓库。不用每次命令行打一大串参数。
6+
7+
## 方法
8+
9+
在本地项目执行下面的操作。
10+
11+
1. 添加自己的远端仓库 `git remote add my [email protected]:my/repo.git`
12+
2. 创建新分支 `git branch a`
13+
3. 编辑的 `.git/config` 文件,添加下面这段代码。
14+
15+
```
16+
[branch "a"]
17+
remote = my
18+
merge = refs/heads/a
19+
```
20+
21+
修改后你的 `.git/config` 大概是这样:
22+
23+
```
24+
[core]
25+
...
26+
[remote "origin"]
27+
url = https://github.com/someone/repo
28+
fetch = +refs/heads/*:refs/remotes/origin/*
29+
[branch "main"]
30+
remote = origin
31+
merge = refs/heads/main
32+
[remote "my"]
33+
url = [email protected]:my/repo.git
34+
fetch = +refs/heads/*:refs/remotes/a/*
35+
[branch "a"]
36+
remote = my
37+
merge = refs/heads/a
38+
```
39+
40+
这样在分支 a 上,执行 `git push` 会推到自己的远端 my。执行 `git fetch` 会从 origin 拉取源代码。
41+
并且不影响其他分支。
42+
43+
## 场景二
44+
45+
有时候需要所有分支只往自己的仓库 push,但 pull 从原仓库拉。
46+
47+
只需要编辑 `.git/config`,在 `remote "origin"` 里加一行 `pushurl` 即可。
48+
49+
```
50+
[remote "origin"]
51+
url = https://github.com/someone/repo
52+
pushurl = [email protected]:my/repo.git
53+
```

hardware/mouse-et-x08.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# ET X08 鼠标
2+
3+
这块静音鼠标我用了很多年,买了好几个。静音效果极好,握持手感好,性价比极高。
4+
缺点是比较重,回报率太低,不能用来玩 FPS 游戏。
5+
6+
记一个可能鲜有人知的小知识:鼠标的回报率可以在 125hz/250hz 之间切换。同时按住鼠标右键和滚轮键 5 秒左右,红灯闪烁,就切换成功。

linux/advanced-power-management.md

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# 硬盘电源管理
2+
3+
英文名 Advanced Power Management,简称 APM。
4+
5+
## hdparm
6+
7+
## SG_IO: bad/missing sense data
8+
9+
```sh
10+
> sudo hdparm -S 241 /dev/sda
11+
12+
/dev/sda:
13+
setting standby to 241 (30 minutes)
14+
SG_IO: bad/missing sense data, sb[]:
15+
```
16+
17+
解决方法:使用 [hd-idle](https://github.com/adelolmo/hd-idle) 或者 [sdparm](https://linux.die.net/man/8/sdparm)
18+
19+
## 西部数据绿盘的电源管理
20+
21+
https://wiki.archlinuxcn.org/zh/Hdparm#%E8%A5%BF%E9%83%A8%E6%95%B0%E6%8D%AE%E7%BB%BF%E7%9B%98%E7%9A%84%E7%94%B5%E6%BA%90%E7%AE%A1%E7%90%86

linux/arch-linux.md

+11
Original file line numberDiff line numberDiff line change
@@ -1 +1,12 @@
11
# arch linux
2+
3+
## signature from "... <[email protected]>" is marginal trust
4+
5+
在安装包的时候可能出现签名不对导致错误
6+
7+
```
8+
error: failed to commit transaction (invalid or corrupted package)
9+
Errors occurred, no packages were upgraded.
10+
```
11+
12+
解决方法:尝试更新 keyring `sudo pacman -Sy archlinux-keyring`

linux/boot-loader.md

+9-5
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,13 @@
1818

1919
### 常见的 bootloader
2020

21-
- [GNU GRUB](./grub.md)
22-
- [uboot](https://www.denx.de/wiki/U-Boot/)
23-
- [syslinux](https://wiki.syslinux.org/wiki/index.php?title=The_Syslinux_Project)
21+
- [GNU GRUB](./grub.md): 用于 Linux 系统
22+
- [uboot](https://www.denx.de/wiki/U-Boot/): 用于嵌入式设备。
23+
- [breed](https://breed.hackpascal.net/): 中国人 Weijie Gao 做的闭源 bootloader。用于嵌入式设备。2022 年停止维护。
24+
- [mcuboot](https://github.com/mcu-tools/mcuboot): 用于 32 位 MCU 的 bootloader。
25+
- [syslinux](https://wiki.syslinux.org/wiki/index.php?title=The_Syslinux_Project): bootloader 套装。常用来从硬盘(包括 MS-DOS FAT 文件系统)、USB、光盘或网络引导启动 Linux 系统。它包括 syslinux, isolinux, pxelinux, extlinux, memlinux 等工具。
2426
- [Etherboot (gPXE)](http://etherboot.org/wiki/): 从网络启动的 bootloader
25-
- [systemd-boot](https://wiki.archlinux.org/title/Systemd-boot)
26-
- [limine](https://github.com/limine-bootloader/limine)
27+
- [limine](https://github.com/limine-bootloader/limine): 比较新的 bootloader
28+
- [OpenCore bootloader](https://github.com/acidanthera/OpenCorePkg): 黑苹果系统的破解 bootloader,专门用于启动 MacOS。
29+
- [rust-osdev/bootloader](https://github.com/rust-osdev/bootloader): 用 Rust 实现的 Bootloader。可以关注一下。
30+
- [systemd-boot](https://wiki.archlinux.org/title/Systemd-boot): 不太用到

linux/device-mapper.md

+26-2
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,39 @@ Device Mapper 是 Linux 内核提供的一种从逻辑设备到物理设备的
1111
- `udevadm info -a -n /dev/xxx`
1212
- `udevadm monitor` 监听设备变化
1313

14-
## /etc/udev/rules.d/*.rules
14+
## udev rule
1515

16-
根据获取的设备信息,编写 udev 规则。规则通常保存在 /etc/udev/rules.d 目录下的文件中。这些文件的名称应该是以两位数字开头,后接描述规则的文本,扩展名为 .rules。数字表示规则的优先级,数字越低,优先级越高。
16+
根据获取的设备信息,编写 udev 规则。
17+
18+
自定义规则放在 /etc/udev/rules.d/*.rules
19+
软件包以及系统自带的规则放在 /usr/lib/udev/rules.d/*.rules
20+
若有同名规则,/etc/udev 的优先级更高。
21+
22+
.rules 文件的名称应该是以两位数字开头,后接描述规则的文本,扩展名为 .rules。数字表示规则的优先级,数字越低,优先级越高。
23+
24+
25+
修改 rules 文件后,需要重载 udev。
1726

1827
```sh
1928
sudo udevadm control --reload
2029
sudo udevadm trigger
2130
```
2231

32+
## 不允许在 udev 规则中访问网络或执行 mount
33+
34+
`man udev` 写着:
35+
36+
> Note that running programs that access the network or mount/unmount filesystems is not allowed inside of udev rules, due to the default sandbox that is enforced on systemd-udevd.service.
37+
38+
[arch linux 文档](https://wiki.archlinux.org/title/Udev#Mounting_drives_in_rules)也警告说不要在 udev 规则中调用 mount。
39+
40+
有两个原因:
41+
42+
1. 默认情况下,systemd 使用单独的 “mount namespace” 运行 systemd-udevd.service (参见 namespaces(7))。这意味着 mounts 对系统的其余部分是不可见的。
43+
2. 从 udev 启动的进程在几秒钟后被终止。对于 FUSE 文件系统,例如 NTFS-3G,mount 会启动一个用户空间进程来处理文件系统内部; 当这被终止时,如果你尝试访问文件系统,你会得到 Transport endpoint not connected 错误。
44+
45+
解决方法:使用 systemd-automount 或者 udisks2 来管理外接 USB 设备。
46+
2347
## 命令
2448

2549
- dmsetup

linux/iptables.md

+64-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,69 @@ https://firewalld.org/
3030
- [从实现上对比 iptables 和 nftables](https://blog.csdn.net/dog250/article/details/41526421) ([链接备份](https://web.archive.org/web/20200216024821/https://blog.csdn.net/dog250/article/details/41526421))
3131
- https://wiki.nftables.org/wiki-nftables/index.php/Netfilter_hooks
3232

33+
### nft list ruleset 输出空白
34+
35+
这是因为 nftables 和 iptables 不共享规则数据。如果 `nft list ruleset` 输出了 iptables 里的规则,那是因为你用的 nft 命令其实是 iptables-nft。
36+
37+
详见下面两篇文章
38+
39+
- [Redhat Developers - iptables: The two variants and their relationship with nftables](https://developers.redhat.com/blog/2020/08/18/iptables-the-two-variants-and-their-relationship-with-nftables)([链接备份](https://web.archive.org/web/20240130101206/https://developers.redhat.com/blog/2020/08/18/iptables-the-two-variants-and-their-relationship-with-nftables#the_iptables_rules_appear_in_the_nftables_rule_listing))
40+
- [RED HAT BLOG - Using iptables-nft: a hybrid Linux firewall](https://www.redhat.com/en/blog/using-iptables-nft-hybrid-linux-firewall) ([链接备份](https://web.archive.org/web/20230910012341/https://www.redhat.com/en/blog/using-iptables-nft-hybrid-linux-firewall))
41+
42+
43+
44+
### iptables 版本
45+
46+
`iptables -V` 如果显示 `iptables vX.Y.Z (legacy)`,说明用的是原生的 iptables。
47+
如果是 `iptables vX.Y.Z (nf_tables)`,则用的是 iptables-nft。
48+
49+
也可以从软链接看出,
50+
51+
```sh
52+
ls -al $(which iptables)
53+
54+
/usr/bin/iptables -> xtables-legacy-multi # legacy iptables
55+
/usr/bin/iptables-nft -> xtables-nft-multi # nft iptables
56+
```
57+
58+
```
59+
+--------------+ +--------------+ +--------------+
60+
| iptables | | iptables | | nft | USER
61+
| legacy | | nft | | (nftables) | SPACE
62+
+--------------+ +--------------+ +--------------+
63+
| | |
64+
====== | ===== KERNEL API ======= | ======= | =====================
65+
| | |
66+
+--------------+ +--------------+
67+
| iptables | | nftables | KERNEL
68+
| API | | API | SPACE
69+
+--------------+ +--------------+
70+
| | |
71+
| | |
72+
+--------------+ | | +--------------+
73+
| xtables |--------+ +-----| nftables |
74+
| match | | match |
75+
+--------------+ +--------------+
76+
```
77+
78+
### iptables-nft
79+
80+
iptables-nft 只是 iptables 过渡到 nftables 的中间产物,让用户用 iptables 的命令行交互操作 nftables api。
81+
然而 iptables-nft 并不完全等价于 nftables。
82+
83+
### 把 iptables 转换成 nftables 规则
84+
85+
```sh
86+
# 先导出 iptables 规则
87+
sudo iptables-save > iptables.dump
88+
sudo ip6tables-save > ip6tables.dump
89+
# 转换成 nftasbles 规则,并写入 nftables 启动配置
90+
iptables-restore-translate -f iptables.dump > /etc/nftables/ruleset-from-iptables.nft
91+
ip6tables-restore-translate -f ip6tables.dump > /etc/nftables/ruleset-from-ip6tables.nft
92+
```
93+
94+
详见 https://wiki.nftables.org/wiki-nftables/index.php/Moving_from_iptables_to_nftables
95+
3396
## UFW
3497

3598
[UFW - Uncomplicated Firewall](https://help.ubuntu.com/community/UFW)
@@ -83,7 +146,7 @@ WantedBy=multi-user.target
83146

84147
## 其他
85148

86-
iptables 的可读性和操作效率不如 nftables,强烈推荐 nftables。
149+
iptables 的可读性和执行效率不如 nftables,强烈推荐 nftables。
87150

88151
ip6tables 是 IPv6 版本的 iptables。
89152

0 commit comments

Comments
 (0)