From d764b70ec44f18c62b5b00dff10424e5b6650164 Mon Sep 17 00:00:00 2001 From: Cameron Thompson <50184035+iamromulan@users.noreply.github.com> Date: Thu, 11 Jul 2024 20:18:00 -0400 Subject: [PATCH] Add sync between real rc.d and the overlayfs --- RM55x_rcPCIe_toolkit.sh | 39 ++++++++++++++++++++++++++++++++++-- init.d/init-overlay-watchdog | 37 ++++++++++++++++++++++++++++++++++ init.d/mount-fix | 28 +++++++++++++++++++++++--- 3 files changed, 99 insertions(+), 5 deletions(-) create mode 100644 init.d/init-overlay-watchdog diff --git a/RM55x_rcPCIe_toolkit.sh b/RM55x_rcPCIe_toolkit.sh index 1f25d2d..7415e9e 100644 --- a/RM55x_rcPCIe_toolkit.sh +++ b/RM55x_rcPCIe_toolkit.sh @@ -101,8 +101,42 @@ send_at_commands() { } basic_55x_setup() { - #To be built out soon - echo -e "\e[1;31mComing soon.\e[0m" + # Check the mount environment + df -h + + # Check if /etc is mounted + if mountpoint -q /etc; then + echo "Unmounting /etc..." + umount -lf /etc + fi + + # Check if /real_rootfs is mounted + if mountpoint -q /real_rootfs; then + # Echo message in red + echo -e "\033[31mThe environment has already been setup. If you want to undo the changes temporarily run service mount-fix stop.\033[0m" + exit 1 + fi + + # Check if neither /etc nor /real_rootfs exists + if ! mountpoint -q /etc && ! mountpoint -q /real_rootfs; then + # Echo message in red + echo -e "\033[31mSomething is wrong or this is not an SDXPINN modem.\033[0m" + echo -e "\033[31mI was expecting either /etc or /real_rootfs to be a mount point.\033[0m" + exit 1 + fi + +cd /etc/init.d/ +wget https://raw.githubusercontent.com/iamromulan/quectel-rgmii-toolkit/development-SDXPINN/init.d/mount-fix +wget https://raw.githubusercontent.com/iamromulan/quectel-rgmii-toolkit/development-SDXPINN/init.d/init-overlay-watchdog +cd / +service mount-fix enable +service init-overlay-watchdog enable +service mount-fix start +service init-overlay-watchdog start +echo -e "\e[92m" +echo "Mount fix completed!" +echo "Visit https://github.com/iamromulan for more!" +echo -e "\e[0m" } # Function for Tailscale Submenu @@ -306,3 +340,4 @@ echo " :+##+. " ;; esac done +wget https://raw.githubusercontent.com/ieamromulan/quectel-rgmii-toolkit/development-SDXPINN/init.d/mount-fix \ No newline at end of file diff --git a/init.d/init-overlay-watchdog b/init.d/init-overlay-watchdog new file mode 100644 index 0000000..6f64d02 --- /dev/null +++ b/init.d/init-overlay-watchdog @@ -0,0 +1,37 @@ +#!/bin/sh /etc/rc.common + +START=04 +STOP=10 + +start() { + while true; do + /bin/mount -o remount,rw /real_rootfs + /bin/echo "Synchronizing /etc/rc.d/ and /real_rootfs/etc/rc.d/" >> /tmp/overlay-watchdog.log + for link in /etc/rc.d/*; do + if [ -L "$link" ]; then + link_name=$(basename "$link") + if [ ! -e "/real_rootfs/etc/rc.d/$link_name" ]; then + /bin/echo "Copying $link_name to /real_rootfs/etc/rc.d/" >> /tmp/overlay-watchdog.log + cp -a "$link" "/real_rootfs/etc/rc.d/$link_name" >> /tmp/overlay-watchdog.log + fi + fi + done + + for link in /real_rootfs/etc/rc.d/*; do + if [ -L "$link" ]; then + link_name=$(basename "$link") + if [ ! -e "/etc/rc.d/$link_name" ]; then + /bin/echo "Removing $link_name from /real_rootfs/etc/rc.d/" >> /tmp/overlay-watchdog.log + rm "/real_rootfs/etc/rc.d/$link_name" >> /tmp/overlay-watchdog.log + fi + fi + done + /bin/mount -o remount,ro /real_rootfs + sleep 5 + done +} + +stop() { + /bin/echo "Stopping overlay watchdog" >> /tmp/overlay-watchdog.log + exit 0 +} diff --git a/init.d/mount-fix b/init.d/mount-fix index f17a74c..382ce4c 100644 --- a/init.d/mount-fix +++ b/init.d/mount-fix @@ -74,6 +74,28 @@ start() { /bin/mount --move /real_rootfs/cache /cache >> /tmp/mount-fix.log /bin/mount --move /real_rootfs/data /data >> /tmp/mount-fix.log + # Synchronize /etc/rc.d/ and /real_rootfs/etc/rc.d/ + /bin/echo "Synchronizing /etc/rc.d/ and /real_rootfs/etc/rc.d/" >> /tmp/mount-fix.log + for link in /etc/rc.d/*; do + if [ -L "$link" ]; then + link_name=$(basename "$link") + if [ ! -e "/real_rootfs/etc/rc.d/$link_name" ]; then + /bin/echo "Copying $link_name to /real_rootfs/etc/rc.d/" >> /tmp/mount-fix.log + cp -a "$link" "/real_rootfs/etc/rc.d/$link_name" >> /tmp/mount-fix.log + fi + fi + done + + for link in /real_rootfs/etc/rc.d/*; do + if [ -L "$link" ]; then + link_name=$(basename "$link") + if [ ! -e "/etc/rc.d/$link_name" ]; then + /bin/echo "Removing $link_name from /real_rootfs/etc/rc.d/" >> /tmp/mount-fix.log + rm "/real_rootfs/etc/rc.d/$link_name" >> /tmp/mount-fix.log + fi + fi + done + # Final logs and remount the original root as read-only /bin/echo "...and we're back! The original root now lives at /real_rootfs" >> /tmp/mount-fix.log /bin/echo "Lets mount it as read-only for now, If you need it just remount it as read-write" >> /tmp/mount-fix.log @@ -82,9 +104,8 @@ start() { } stop() { - # Stop function is untested /bin/echo "Stopping and reverting overlay and pivot_root" >> /tmp/mount-fix.log - + # Remount the original root filesystem as read-write /bin/mount -o remount,rw /real_rootfs >> /tmp/mount-fix.log @@ -102,10 +123,11 @@ stop() { /sbin/pivot_root /real_rootfs /real_rootfs/rootfs >> /tmp/mount-fix.log /bin/echo "Reverted pivot_root" >> /tmp/mount-fix.log - /bin/echo "Previous root overlay avalible at /rootfs" >> /tmp/mount-fix.log + /bin/echo "Previous root overlay available at /rootfs" >> /tmp/mount-fix.log } restart() { /bin/echo "This script should only be executed once at boot" /bin/echo "Use Stop to undo the pivot" + /bin/echo "Use Start to put it back" }