OpenWrt 系列优化 2 雅典娜
扩容存储
刷机的时候是可选root分区大小的,剩下的空间是没有分配的。直接分配挂载就可。
- 创建分区
fdisk /dev/mmcblk0
n # 值默认都可以
# Command (m for help): n
# Partition number (27,28, default 27):
# First sector (7741474-241663991, default 7743488):
# Last sector, +/-sectors or +/-size{K,M,G,T,P} (7743488-241663991, default 241661951):
# Created a new partition 27 of type 'Linux filesystem' and of size 111.5 GiB.
w # 保存分区变更
# Command (m for help): w
# The partition table has been altered.
# Syncing disks.
再从 fdisk -l
看,那个分区警告也没了
The backup GPT table is not on the end of the device. This problem will be corrected by write.
- 用
f2fs
格式化分区
mkfs.f2fs /dev/mmcblk0p27
F2FS-tools: mkfs.f2fs Ver: 1.16.0 (2023-04-11)
Info: Disable heap-based policy
Info: Debug level = 0
Info: Trim is enabled
Info: Segments per section = 1
Info: Sections per zone = 1
Info: sector size = 512
Info: total sectors = 233918464 (114218 MB)
Info: zone aligned segment0 blkaddr: 512
Info: format version with
"Linux version 6.6.58 (runner@fv-az1247-605) (aarch64-openwrt-linux-musl-gcc (OpenWrt GCC 13.3.0 r0-48ee922) 13.3.0, GNU ld (GNU Binutils) 2.42) #0 SMP PREEMPT Fri Oct 25 09:07:06 2024"
Info: [/dev/mmcblk0p27] Discarding device
Info: Secure Discarded 0 MB
Info: Overprovision ratio = 0.430%
Info: Overprovision segments = 245 (GC reserved = 239)
Info: format successful
- 通过LuCI挂载
1. 系统 -> 挂载点 -> 添加
2. UUID 选择 (111.5G)
3. 挂载到 /opt
4. 保存并应用
- 可以通过
df -h
看到挂载成功
Filesystem Size Used Available Use% Mounted on
/dev/root 40.0M 40.0M 0 100% /rom
tmpfs 439.8M 44.2M 395.6M 10% /tmp
/dev/loop0 2.0G 170.4M 1.8G 8% /overlay
overlayfs:/overlay 2.0G 170.4M 1.8G 8% /
tmpfs 512.0K 0 512.0K 0% /dev
/dev/mmcblk0p27 111.5G 958.0M 110.6G 1% /opt
分区布局
lsblk
# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
# 这里是日常使用部分
loop0 7:0 0 2G 0 loop /overlay
# 整个 emmc
mmcblk0 179:0 0 115.2G 0 disk
├─mmcblk0p1 179:1 0 768K 0 part
├─mmcblk0p2 179:2 0 256K 0 part
├─mmcblk0p3 179:3 0 256K 0 part
├─mmcblk0p4 179:4 0 1.8M 0 part
├─mmcblk0p5 179:5 0 1.8M 0 part
├─mmcblk0p6 179:6 0 256K 0 part
├─mmcblk0p7 179:7 0 256K 0 part
├─mmcblk0p8 179:8 0 256K 0 part
├─mmcblk0p9 179:9 0 256K 0 part
├─mmcblk0p10 179:10 0 256K 0 part
├─mmcblk0p11 179:11 0 256K 0 part
├─mmcblk0p12 179:12 0 256K 0 part
├─mmcblk0p13 179:13 0 640K 0 part
├─mmcblk0p14 179:14 0 640K 0 part
├─mmcblk0p15 179:15 0 512K 0 part
├─mmcblk0p16 179:16 0 6M 0 part
├─mmcblk0p17 179:17 0 6M 0 part
├─mmcblk0p18 179:18 0 2G 0 part /rom
├─mmcblk0p19 179:19 0 4M 0 part
├─mmcblk0p20 179:20 0 60M 0 part
├─mmcblk0p21 179:21 0 4M 0 part
├─mmcblk0p22 179:22 0 20M 0 part
├─mmcblk0p23 179:23 0 512K 0 part
├─mmcblk0p24 179:24 0 87.3M 0 part
├─mmcblk0p25 179:25 0 1G 0 part
└─mmcblk0p26 179:26 0 512M 0 part
# 启动分区
mmcblk0boot0 179:32 0 4M 1 disk
mmcblk0boot1 179:64 0 4M 1 disk
扩容后
mmcblk0 179:0 0 115.2G 0 disk
├─.......
└─mmcblk0p27 179:27 0 111.5G 0 part
备份和恢复
a. Overlay
如果在没有重刷固件的情况下,我建议仅对 /overlay 进行打包并备份
https://www.v2ex.com/t/131986#r_1326334
# 备份
tar -czvf /tmp/overlay_backup.tar.gz /overlay
# 恢复
rm -rvf /overlay/*
cd / && tar -xzvf /tmp/overlay_backup.tar.gz
b. firmware
# 查看 firmware 分区所对应的 mtd 设备
cat /proc/mtd
# 比如:
dev: size erasesize name
mtd0: 00040000 00020000 "u-boot"
mtd1: 00040000 00020000 "u-boot-env"
mtd2: 00040000 00020000 "caldata"
mtd3: 00080000 00020000 "pot"
mtd4: 00200000 00020000 "language"
mtd5: 00080000 00020000 "config"
mtd6: 00300000 00020000 "traffic_meter"
mtd7: 00200000 00020000 "kernel"
mtd8: 07700000 00020000 "ubi"
mtd9: 07900000 00020000 "firmware"
mtd10: 00040000 00020000 "caldata_backup"
# 这里就是mtd9
# 备份固件文件 firmware_backup.bin,在 /tmp 目录下
dd if=/dev/mtd9 of=/tmp/firmware_backup.bin
# 恢复该固件, 将 firmware_backup.bin 上传至 /tmp,恢复完成路由器会自行重启
mtd -r write /tmp/firmware_backup.bin firmware
c. 通用 NOR 备份
https://openwrt.org/zh/docs/guide-user/installation/generic.backup
Rust compile
- 平台应该选择
aarch64-unknow-linux-musl
- windows 平台在编译的时候可能会报一个错,修改以下内容到
~/.cargo/config.toml
- 编译
cargo build --release --target aarch64-unknown-linux-musl
# https://stackoverflow.com/questions/63739813/error-linker-cc-not-found-when-cross-compiling-a-rust-project-from-windows
[target.aarch64-unknow-linux-musl]
rustflags = ["-C", "linker-flavor=ld.lld"]
F2FS
https://wiki.archlinux.org/title/F2FS
Conclusion
immortalwrt 和 OpenWrt 都是非常优秀的 OS,也带来了很多有意思的折腾,有很多先进的理念都在里面。在折腾的过程中非常有意思。
包括但不限于:
- loop device (losetup)
- f2fs
- overlayfs
- u-boot
- nftables
- aarch64-musl
本文参考: