istoreos/package/diy/expand-overlay/files/expand-overlay.init
xiexiaobao 30354fe40e 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.
2026-06-27 15:29:33 +08:00

60 lines
1.6 KiB
Bash

#!/bin/sh /etc/rc.common
# /etc/init.d/expand-overlay
# 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"
local p4flag="/etc/data-partition.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
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
return 0
}