Add sync between real rc.d and the overlayfs

This commit is contained in:
Cameron Thompson
2024-07-11 20:18:00 -04:00
parent b027378c9d
commit d764b70ec4
3 changed files with 99 additions and 5 deletions

View File

@@ -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

View File

@@ -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
}

View File

@@ -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"
}