Skip to content

Instantly share code, notes, and snippets.

@monosoul
Created July 3, 2026 00:50
Show Gist options
  • Select an option

  • Save monosoul/1bd487677eb0461c840e81de8f459797 to your computer and use it in GitHub Desktop.

Select an option

Save monosoul/1bd487677eb0461c840e81de8f459797 to your computer and use it in GitHub Desktop.
Script for automated extroot restoration after upgrade on OpenWRT 25.12
# Save as /etc/uci-defaults/90-extroot-restore
# then put it into /etc/sysupgrade.conf
UUID="$(uci -q get fstab.extroot.uuid)"
DIR="$(uci -q get fstab.extroot.target)"
DEV="$(block info | sed -n -e "/${UUID}/s/:.*$//p")"
if [ -n "${UUID}" ] \
&& [ -n "${DEV}" ] \
&& [ ! -e /etc/extroot-restore ] \
&& ! grep -q -e "^${DEV}[[:space:]]" /proc/mounts \
&& lock -n /var/lock/extroot-restore
then
mkdir -p /mnt
if touch /etc/extroot-restore \
&& grep -q -e "[[:space:]]${DIR}[[:space:]]" /etc/mtab \
&& mount "${DEV}" /mnt
then
BAK="$(mktemp -d -p /mnt -t bak.XXXXXX)"
mv -f /mnt/etc /mnt/upper "${BAK}" 2>/dev/null
cp -f -a "${DIR}"/. /mnt
umount "${DEV}"
fi
lock -u /var/lock/extroot-restore
reboot
fi
exit 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment