OPENWRT

Wish @By haven200
Help documents of open-wrt

OpenWrt

OpenWrt Filesystem Overview

In the OpenWrt system, the Overlay partition is a core component that ensures both system flexibility and stability.

Key Mechanism: Union Mount

It utilizes union mount technology to merge two distinct layers:

  • Read-only Filesystem: The original firmware state.
  • Writable Filesystem: Where user changes and configurations are stored.

By combining these into a single logical view, the system allows for easy modifications while maintaining a “factory reset” capability.

I. Core Functions of Overlay

1. Differential Storage and Configuration Persistence

  • Read-Only Layer (SquashFS): Stores core system files (kernel, base packages). These are immutable, preventing accidental operations from compromising system stability.
  • Writable Layer (Overlay): All user modifications—such as plugin installations and configuration changes—are stored here. This layer stacks with the read-only layer to create a “virtual read-write” view.

2. Rapid System Recovery

  • Reset Capability: The system can be restored to factory settings simply by clearing the Overlay partition, eliminating the need for a full firmware re-flash.
  • Fault Isolation: Even if the data in the Overlay partition becomes corrupted, the read-only layer ensures the system remains in a basic, bootable state.

3. Flexible Capacity Expansion

  • Space Extension: Default onboard Flash memory is often limited (e.g., 128MB). By mounting external storage (USB drives/SD cards) as an External Overlay, the available space for software installation can be significantly increased.

4. Extending Storage Lifespan

  • Write Cycle Reduction: By concentrating frequent write operations onto external storage or specific writable layers, the wear and tear on the motherboard’s onboard Flash (which has limited write cycles) is effectively minimized.

II. Specific Steps for Migration/Expansion Using tar

When preparing to mount the Overlay to an external device, a complete replication of existing data is mandatory. Using a tar pipeline is the most reliable method to preserve Linux file permissions, ownership, and symbolic links.

1. Prerequisites

  • Ensure the target device is formatted as ext4 (the filesystem with the most robust support for Linux permissions).
  • Verify that the necessary packages are installed:
    opkg update && opkg install block-mount kmod-fs-ext4

2. Executing the Copy Command

Pay close attention to the target paths to ensure data is correctly extracted to the root of the destination drive:

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
# 1. Create a temporary mount point and mount the new partition
mkdir -p /mnt/extdisk
mount /dev/sda1 /mnt/extdisk

# 2. Sync data using a tar pipeline (Recommended method)
# The -C parameter ensures the command is executed within the specific directory,
# preventing the inclusion of unnecessary parent directory paths.
tar -C /overlay -cf - . | tar -C /mnt/extdisk -xf -

# 3. Verify the replication results
ls -a /mnt/extdisk
# Note: Confirming the presence of both "upper" and "work" directories indicates a successful copy.


## Updating DNSPOD Domain Records via Shell Script
```sh
# 1. Get `Domain_ID`
┌──(kali㉿kali)-[~]
└─$ curl https://dnsapi.cn/Domain.List -d "login_token=123456,f32eb705b754e46711392bdb4f3083c2&format=json"
{"status":{"code":"1","message":"\u64cd\u4f5c\u5df2\u7ecf\u6210\u529f\u5b8c\u6210","created_at":"2025-05-15 10:47:50"},"info":{"domain_total":1,"all_total":1,"mine_total":1,"share_total":0,"vip_total":0,"ismark_total":0,"pause_total":0,"error_total":0,"lock_total":0,"spam_total":0,"vip_expire":0,"share_out_total":0},"domains":[{"id":94342009,"status":"enable","grade":"DP_Free","group_id":"1","searchengine_push":"no","is_mark":"no","ttl":"600","cname_speedup":"enable","remark":"","created_on":"2023-04-18 17:13:29","updated_on":"2025-05-12 18:55:06","server":"DP_Free","punycode":"sxuen.com","ext_status":"","src_flag":"QCLOUD","grade_ns":["brick.dnspod.net","database.dnspod.net"],"name":"sxuen.com","grade_level":2,"grade_title":"\u514d\u8d39\u7248","is_vip":"no","owner":"[email protected]","records":"12","is_grace_period":"no","vip_start_at":"0000-00-00 00:00:00","vip_end_at":"0000-00-00 00:00:00","vip_auto_renew":"no","tag_list":[]}]}
# 2. Get `Record_id`
┌──(kali㉿kali)-[~]
└─$ curl https://dnsapi.cn/Record.List -d 'login_token=123456,f32eb705b754e46711392bdb4f3083c2&format=json&domain_id=94342009&sub_domain=dev&record_type=AAAA&offset=0&length=3'
{"status":{"code":"1","message":"\u64cd\u4f5c\u5df2\u7ecf\u6210\u529f\u5b8c\u6210","created_at":"2025-05-15 10:53:37"},"domain":{"id":94342009,"name":"sxuen.com","punycode":"sxuen.com","grade":"DP_Free","owner":"[email protected]","ext_status":"","ttl":600,"min_ttl":600,"dnspod_ns":["brick.dnspod.net","database.dnspod.net"],"status":"enable","can_handle_at_ns":false},"info":{"sub_domains":"14","record_total":"1","records_num":"1"},"records":[{"id":"1927200607","ttl":"600","value":"240e:0340:0206:916a:b805:bc92:b083:1579","enabled":"1","status":"enable","updated_on":"2025-05-12 18:55:06","record_type_v1":"1","status_v1":"enabled","enabled_v1":"1","name":"dev","line":"\u9ed8\u8ba4","line_id":"0","type":"AAAA","weight":null,"monitor_status":"","remark":"","use_aqb":"no","mx":"0"}]}
# 3. Get `IP Address`
┌──(kali㉿kali)-[~]
└─$ curl -X POST https://dnsapi.cn/Record.Info -d 'login_token=123456,f32eb705b754e46711392bdb4f3083c2&format=json&domain_id=94342009&record_id=1927200607'
{"status":{"code":"1","message":"\u64cd\u4f5c\u5df2\u7ecf\u6210\u529f\u5b8c\u6210","created_at":"2025-05-15 10:56:17"},"domain":{"id":94342009,"domain":"sxuen.com","domain_grade":"DP_Free","dnspod_ns":["brick.dnspod.net","database.dnspod.net"]},"record":{"id":"1927200607","sub_domain":"dev","record_type":"AAAA","record_line":"\u9ed8\u8ba4","record_line_id":"0","value":"240e:0340:0206:916a:b805:bc92:b083:1579","weight":null,"mx":"0","ttl":"600","enabled":"1","monitor_status":"","remark":"","updated_on":"2025-05-12 18:55:06","domain_id":"94342009"}}
# 4. Get `ID of Line`
┌──(kali㉿kali)-[~]
└─$ curl -X POST https://dnsapi.cn/Record.Line.Category -d 'login_token=123456,f32eb705b754e46711392bdb4f3083c2&format=json&category_names=电信&domain_id=94342009'
{"status":{"code":"1","message":"\u64cd\u4f5c\u5df2\u7ecf\u6210\u529f\u5b8c\u6210","created_at":"2025-05-15 11:08:20"},"data":[{"line_name":"\u7535\u4fe1","line_id":"10=0","useful":true,"subgroup":[{"line_name":"电信","line_id":"10=0","useful":true,"vip":"DP_Free"},{"line_name":"安徽电信","line_id":"20=0","useful":false,"vip":"DP_Expert"},{"line_name":"北京电信","line_id":"20=2","useful":false,"vip":"DP_Expert"},{"line_name":"重庆电信","line_id":"20=4","useful":false,"vip":"DP_Expert"},{"line_name":"\u798f\u5efa\u7535\u4fe1","line_id":"20=6","useful":false,"vip":"DP_Expert"},{"line_name":"\u7518\u8083\u7535\u4fe1","line_id":"20=8","useful":false,"vip":"DP_Expert"},{"line_name":"\u5e7f\u4e1c\u7535\u4fe1","line_id":"20=10","useful":false,"vip":"DP_Expert"},{"line_name":"\u5e7f\u897f\u7535\u4fe1","line_id":"20=12","useful":false,"vip":"DP_Expert"},{"line_name":"\u8d35\u5dde\u7535\u4fe1","line_id":"20=14","useful":false,"vip":"DP_Expert"},{"line_name":"\u6d77\u5357\u7535\u4fe1","line_id":"20=16","useful":false,"vip":"DP_Expert"},{"line_name":"\u6cb3\u5317\u7535\u4fe1","line_id":"20=18","useful":false,"vip":"DP_Expert"},{"line_name":"\u6cb3\u5357\u7535\u4fe1","line_id":"20=20","useful":false,"vip":"DP_Expert"},{"line_name":"\u9ed1\u9f99\u6c5f\u7535\u4fe1","line_id":"20=22","useful":false,"vip":"DP_Expert"},{"line_name":"\u6e56\u5317\u7535\u4fe1","line_id":"20=24","useful":false,"vip":"DP_Expert"},{"line_name":"\u6e56\u5357\u7535\u4fe1","line_id":"20=26","useful":false,"vip":"DP_Expert"},{"line_name":"\u5409\u6797\u7535\u4fe1","line_id":"20=28","useful":false,"vip":"DP_Expert"},{"line_name":"\u6c5f\u82cf\u7535\u4fe1","line_id":"20=30","useful":false,"vip":"DP_Expert"},{"line_name":"\u6c5f\u897f\u7535\u4fe1","line_id":"20=32","useful":false,"vip":"DP_Expert"},{"line_name":"\u8fbd\u5b81\u7535\u4fe1","line_id":"20=34","useful":false,"vip":"DP_Expert"},{"line_name":"\u5185\u8499\u7535\u4fe1","line_id":"20=36","useful":false,"vip":"DP_Expert"},{"line_name":"\u5b81\u590f\u7535\u4fe1","line_id":"20=38","useful":false,"vip":"DP_Expert"},{"line_name":"\u9752\u6d77\u7535\u4fe1","line_id":"20=40","useful":false,"vip":"DP_Expert"},{"line_name":"\u5c71\u4e1c\u7535\u4fe1","line_id":"20=42","useful":false,"vip":"DP_Expert"},{"line_name":"\u5c71\u897f\u7535\u4fe1","line_id":"20=44","useful":false,"vip":"DP_Expert"},{"line_name":"\u9655\u897f\u7535\u4fe1","line_id":"20=46","useful":false,"vip":"DP_Expert"},{"line_name":"\u4e0a\u6d77\u7535\u4fe1","line_id":"20=48","useful":false,"vip":"DP_Expert"},{"line_name":"\u56db\u5ddd\u7535\u4fe1","line_id":"20=50","useful":false,"vip":"DP_Expert"},{"line_name":"\u5929\u6d25\u7535\u4fe1","line_id":"20=52","useful":false,"vip":"DP_Expert"},{"line_name":"\u897f\u85cf\u7535\u4fe1","line_id":"20=54","useful":false,"vip":"DP_Expert"},{"line_name":"\u65b0\u7586\u7535\u4fe1","line_id":"20=56","useful":false,"vip":"DP_Expert"},{"line_name":"\u4e91\u5357\u7535\u4fe1","line_id":"20=58","useful":false,"vip":"DP_Expert"},{"line_name":"\u6d59\u6c5f\u7535\u4fe1","line_id":"20=60","useful":false,"vip":"DP_Expert"},{"line_name":"\u534e\u5317\u7535\u4fe1","line_id":"16=0","useful":false,"vip":"DP_Expert"},{"line_name":"\u4e1c\u5317\u7535\u4fe1","line_id":"16=4","useful":false,"vip":"DP_Expert"},{"line_name":"\u534e\u4e1c\u7535\u4fe1","line_id":"16=8","useful":false,"vip":"DP_Expert"},{"line_name":"\u534e\u4e2d\u7535\u4fe1","line_id":"16=12","useful":false,"vip":"DP_Expert"},{"line_name":"\u534e\u5357\u7535\u4fe1","line_id":"16=16","useful":false,"vip":"DP_Expert"},{"line_name":"\u897f\u5357\u7535\u4fe1","line_id":"16=20","useful":false,"vip":"DP_Expert"},{"line_name":"\u897f\u5317\u7535\u4fe1","line_id":"16=24","useful":false,"vip":"DP_Expert"}],"vip":"DP_Free"}]}
# 5. Update Domain IP
┌──(kali㉿kali)-[~]
└─$ curl -X POST https://dnsapi.cn/Record.Modify -d 'login_token=123456,f32eb705b754e46711392bdb4f3083c2&format=json&domain_id=94342009&record_id=1927200607&sub_domain=dev&value=240e:340:206:6f0d:d50a:5a56:e38b:8b56&record_type=AAAA&record_line_id=10%3D0'
{"status":{"code":"1","message":"\u64cd\u4f5c\u5df2\u7ecf\u6210\u529f\u5b8c\u6210","created_at":"2025-05-15 11:10:12"},"record":{"id":1927200607,"name":"dev","value":"240e:340:206:6f0d:d50a:5a56:e38b:8b56","status":"enable","weight":null}}
# 6. Verifying the Update Result
┌──(kali㉿kali)-[~]
└─$ nslookup dev.sxuen.com
Server: 192.168.100.100
Address: 192.168.100.100#53

Non-authoritative answer:
Name: dev.sxuen.com
Address: 240e:340:206:6f0d:d50a:5a56:e38b:8b56

Third-party plugins

1. Repository Optimization

  • Update the default package repositories to a local mirror (e.g., TUNA or Aliyun) to improve download speeds.

2. Storage & Partitioning

  • Overlay Expansion: Install block-mount, fdisk, and cfdisk to expand the default Overlay partition using external storage (Extroot).

3. Container Virtualization

  • Install luci-app-dockerman to manage Docker containers via the LuCI web interface.

4. Dynamic DNS (DDNS)

  • Install luci-app-ddns and ddns-scripts-dnspod-v3 for automated DNSPod domain updates.

5. System Statistics & Monitoring

  • Install luci-app-statistics and collectd-mod-sensors to monitor system temperature and hardware performance metrics.

6. NFS Client Support

  • Install nfs-utils, kmod-fs-nfs, kmod-fs-nfs-common, and kmod-fs-nfs-v4 to enable mounting of remote network shares.

7. Development & Remote Access

  • Install git, ssh-keygen, and openssh-client for version control and secure remote connectivity.

8. NFS Server Support

  • Install nfs-server to allow the OpenWrt device to share its local storage with other devices on the network.

Implementation Guide

1. One-Liner Installation Command

Run the following commands in your SSH terminal to install all components at once:

1
2
3
4
5
6
7
8
9
10
11
# Update package database
opkg update

# Install all specified packages
opkg install block-mount fdisk cfdisk \
luci-app-dockerman \
luci-app-ddns ddns-scripts-dnspod-v3 \
luci-app-statistics collectd-mod-sensors \
nfs-utils kmod-fs-nfs kmod-fs-nfs-common kmod-fs-nfs-v4 \
git git-http openssh-keygen openssh-client \
nfs-server