refactor: change eMMC layout - 3G overlay + data partition for Docker

expand-overlay now splits eMMC into:
- p3 (3GB): overlay filesystem (system + configs)
- p4 (~54GB): ext4 data partition -> /mnt/data/docker

Docker data-root auto-configured to /mnt/data/docker on first boot.
This commit is contained in:
xiexiaobao 2026-06-27 15:29:33 +08:00
parent 920956975c
commit 30354fe40e
3 changed files with 66 additions and 20 deletions

View File

@ -18,15 +18,17 @@ include $(INCLUDE_DIR)/package.mk
define Package/expand-overlay
SECTION:=utils
CATEGORY:=Utilities
TITLE:=Auto-expand overlay partition on first boot
DEPENDS:=+sfdisk +e2fsprogs
TITLE:=eMMC partition layout: 3G overlay + data partition
DEPENDS:=+sfdisk +e2fsprogs +block-mount
PKGARCH:=all
endef
define Package/expand-overlay/description
Auto-resize the NanoPi R6C eMMC overlay partition (mmcblk2p3)
to fill all remaining unallocated space on first boot.
Two-stage: uci-defaults resizes partition table, init.d resizes filesystem.
First-boot eMMC partition layout for NanoPi R6C:
- p3 (3GB): overlay filesystem (system/config)
- p4 (~54GB): data partition (mounted at /mnt/data, for Docker)
Stage 1 (uci-defaults): resizes p3 to 3GB, creates p4.
Stage 2 (init.d): resizes p3 fs, formats & mounts p4.
endef
define Build/Configure

View File

@ -1,25 +1,59 @@
#!/bin/sh /etc/rc.common
# /etc/init.d/expand-overlay
# Stage 2: Resize filesystem to match expanded partition.
# Stage 2: Resize p3 filesystem, format & mount p4, configure Docker.
# Runs at START=99, after overlay is mounted and most services started.
START=99
boot() {
local flag="/etc/resize2fs.done"
[ -f "$flag" ] && return 0
local p4flag="/etc/data-partition.done"
# Wait for stage1 to finish (uci-defaults running before us)
local i=0
while [ ! -f "/etc/expand-overlay.done" ] && [ $i -lt 30 ]; do
sleep 1
i=$((i + 1))
done
# ---- Stage 2a: Resize p3 filesystem ----
if [ ! -f "$flag" ]; then
# Wait for stage1 (uci-defaults) to finish
local i=0
while [ ! -f "/etc/expand-overlay.done" ] && [ $i -lt 30 ]; do
sleep 1
i=$((i + 1))
done
[ ! -f "/etc/expand-overlay.done" ] && return 0
if [ -f "/etc/expand-overlay.done" ]; then
resize2fs /dev/mmcblk2p3 2>/dev/null
touch "$flag"
fi
fi
# ---- Stage 2b: Format and mount p4 data partition ----
if [ ! -f "$p4flag" ]; then
# Check if p4 is marked with RESET (needs formatting)
if dd if=/dev/mmcblk2p4 bs=5 count=1 2>/dev/null | grep -qF "RESET"; then
# Format p4 as ext4
mkfs.ext4 -F -L data /dev/mmcblk2p4 2>/dev/null
fi
# Mount p4 to /mnt/data
mkdir -p /mnt/data
mount /dev/mmcblk2p4 /mnt/data 2>/dev/null
# Create Docker directory on data partition
mkdir -p /mnt/data/docker
# Point Docker to data partition
uci -q set dockerd.globals.data_root="/mnt/data/docker"
uci -q commit dockerd
# Add to fstab for auto-mount on future boots
if ! grep -q "mmcblk2p4" /etc/config/fstab 2>/dev/null; then
block detect > /dev/null 2>&1
# block detect creates entries, we update the last one
local idx=$(( $(uci show fstab | grep -c "fstab.@mount") - 1 ))
[ "$idx" -ge 0 ] && uci -q set fstab.@mount[$idx].target="/mnt/data"
uci -q commit fstab
fi
touch "$p4flag"
fi
# Resize filesystem
resize2fs /dev/mmcblk2p3 2>/dev/null
touch "$flag"
return 0
}

View File

@ -1,6 +1,6 @@
#!/bin/sh
# /etc/uci-defaults/99-expand-overlay
# Stage 1: Resize partition table to fill unallocated eMMC space.
# Stage 1: Resize p3 to 3GB, create p4 for Docker data.
# Auto-removed by uci-defaults after first run.
FLAG_FILE="/etc/expand-overlay.done"
@ -11,9 +11,19 @@ FLAG_FILE="/etc/expand-overlay.done"
ROOT_DEV=$(mount | grep ' / ' | awk '{print $1}' | sed 's/p[0-9]*$//')
[ "$ROOT_DEV" != "/dev/mmcblk2" ] && exit 0
# Save backup, resize partition 3 to fill remaining space
# Save backup of original partition table
sfdisk -d /dev/mmcblk2 > /etc/sfdisk.bak 2>/dev/null
echo ",+" | sfdisk -N 3 /dev/mmcblk2 2>/dev/null
# Step 1: Resize partition 3 to exactly 3GB (3072 MiB)
# instead of expanding to fill the entire disk
echo ",3072M" | sfdisk -N 3 /dev/mmcblk2 2>/dev/null
# Step 2: Create partition 4 using the remaining space
# sfdisk -N 4 with ",+" = start after p3, fill to end
echo ",+" | sfdisk -N 4 /dev/mmcblk2 2>/dev/null
# Step 3: Write RESET marker on p4 so stage 2 knows to format it
echo "RESET000" | dd of=/dev/mmcblk2p4 bs=512 count=1 conv=notrunc,sync 2>/dev/null
touch "$FLAG_FILE"
exit 0