mount-fix Test

First test with new firmware with updated mount-fix package
This commit is contained in:
Cameron Thompson
2025-01-10 00:29:13 -05:00
parent 47c1ea44ad
commit 0c6194e00c
16 changed files with 144 additions and 77 deletions

2
ipk-source/sdxpinn-mount-fix/CONTROL/control Normal file → Executable file
View File

@@ -1,5 +1,5 @@
Package: sdxpinn-mount-fix Package: sdxpinn-mount-fix
Version: 1.2.0-NOT-READY Version: 1.2.0
Architecture: aarch64_cortex-a53 Architecture: aarch64_cortex-a53
Maintainer: Cameron Thompson iamromulan@github.com Maintainer: Cameron Thompson iamromulan@github.com
Description: Creates a usable mount space and overlay for SDXPINN modems. Dependencies bundled: libinotifytools and inotifywait Description: Creates a usable mount space and overlay for SDXPINN modems. Dependencies bundled: libinotifytools and inotifywait

0
ipk-source/sdxpinn-mount-fix/CONTROL/postinst Normal file → Executable file
View File

0
ipk-source/sdxpinn-mount-fix/CONTROL/prerm Normal file → Executable file
View File

0
ipk-source/sdxpinn-mount-fix/build-ipk Normal file → Executable file
View File

View File

View File

177
ipk-source/sdxpinn-mount-fix/root/etc/init.d/mount-fix Normal file → Executable file
View File

@@ -98,27 +98,8 @@ handle_old_firmware() {
/bin/mount --move /real_rootfs/cache /cache /bin/mount --move /real_rootfs/cache /cache
/bin/mount --move /real_rootfs/data /data /bin/mount --move /real_rootfs/data /data
# Synchronize /etc/rc.d/ and /real_rootfs/etc/rc.d/ # Synchronize between /etc/rc.d and /real_rootfs/etc/rc.d
/bin/echo "Synchronizing /etc/rc.d/ and /real_rootfs/etc/rc.d/" synchronize_rc_d "/etc/rc.d" "/real_rootfs/etc/rc.d"
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/"
cp -a "$link" "/real_rootfs/etc/rc.d/$link_name"
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/"
rm "/real_rootfs/etc/rc.d/$link_name"
fi
fi
done
# Final logs and remount the original root as read-only # Final logs and remount the original root as read-only
/bin/echo "...and we're back! The original root now lives at /real_rootfs" /bin/echo "...and we're back! The original root now lives at /real_rootfs"
@@ -142,7 +123,7 @@ handle_new_firmware() {
/bin/mount -o remount,rw / /bin/mount -o remount,rw /
# Begin layer merge checks # Begin layer merge checks
# Layer 1 # Layer 1 to 2
# Check if /overlay/etc-upper/merged.done exists # Check if /overlay/etc-upper/merged.done exists
/bin/echo "First time this is ran the stuff you have been putting in the old overlay and /usrdata/etc needs merged." /bin/echo "First time this is ran the stuff you have been putting in the old overlay and /usrdata/etc needs merged."
/bin/echo "Looking for evidence that this has already happened..." /bin/echo "Looking for evidence that this has already happened..."
@@ -153,7 +134,7 @@ handle_new_firmware() {
else else
/bin/echo "/usrdata/overlay-work/etc-upper/merged.done found, skipping merge" /bin/echo "/usrdata/overlay-work/etc-upper/merged.done found, skipping merge"
fi fi
# Layer 2 # Layer 2 to 3
# Check if /usrdata/etc/merged.done exists # Check if /usrdata/etc/merged.done exists
/bin/echo "First time this is ran the stuff you have been putting in /usrdata/etc and /etc needs merged." /bin/echo "First time this is ran the stuff you have been putting in /usrdata/etc and /etc needs merged."
/bin/echo "Looking for evidence that this has already happened..." /bin/echo "Looking for evidence that this has already happened..."
@@ -174,27 +155,21 @@ handle_new_firmware() {
else else
/bin/echo "'option overlay_root /overlay' not found in /etc/opkg.conf, no changes made" /bin/echo "'option overlay_root /overlay' not found in /etc/opkg.conf, no changes made"
fi fi
# #
# #
# Continue Working from here.... #
# #
# #
# #
#
# Ensure necessary directories exist for overlay and pivot_root # Ensure necessary directories exist for overlay and pivot_root
/bin/echo "Creating new overlay system" /bin/echo "Creating new overlay system"
if [ ! -d /data/rootfs ]; then if [ ! -d /usrdata/rootfs ]; then
mkdir -p /data/rootfs mkdir -p /usrata/rootfs
fi fi
if [ ! -d /data/rootfs-workdir ]; then if [ ! -d /usrdata/rootfs-workdir ]; then
mkdir -p /data/rootfs-workdir mkdir -p /usrdata/rootfs-workdir
fi fi
if [ ! -d /rootfs ]; then if [ ! -d /rootfs ]; then
mkdir -p /rootfs mkdir -p /rootfs
fi fi
# Mount the new overlay filesystem # Mount the new overlay filesystem
/bin/mount -t overlay overlay -o lowerdir=/,upperdir=/data/rootfs,workdir=/data/rootfs-workdir /rootfs /bin/mount -t overlay overlay -o lowerdir=/,upperdir=/usrdata/rootfs,workdir=/usrdata/rootfs-workdir /rootfs
# Create the real_rootfs directory in the new root # Create the real_rootfs directory in the new root
if [ ! -d /rootfs/real_rootfs ]; then if [ ! -d /rootfs/real_rootfs ]; then
@@ -211,31 +186,18 @@ handle_new_firmware() {
/bin/mount --move /real_rootfs/tmp /tmp /bin/mount --move /real_rootfs/tmp /tmp
/bin/mount --move /real_rootfs/dev /dev /bin/mount --move /real_rootfs/dev /dev
/bin/mount --move /real_rootfs/firmware /firmware /bin/mount --move /real_rootfs/firmware /firmware
/bin/mount --move /real_rootfs/persist /persist /bin/mount --move /real_rootfs/usrdata /usrdata
/bin/mount --move /real_rootfs/cache /cache
/bin/mount --move /real_rootfs/data /data /bin/mount --move /real_rootfs/data /data
/bin/mount --move /real_rootfs/cache /cache
/bin/mount --move /real_rootfs/systemrw /systemrw
/bin/mount --move /real_rootfs/persist /persist
# Synchronize /etc/rc.d/ and /real_rootfs/etc/rc.d/
/bin/echo "Synchronizing /etc/rc.d/ and /real_rootfs/etc/rc.d/"
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/"
cp -a "$link" "/real_rootfs/etc/rc.d/$link_name"
fi
fi
done
for link in /real_rootfs/etc/rc.d/*; do # Synchronize between /etc/rc.d and /real_rootfs/etc/rc.d
if [ -L "$link" ]; then synchronize_rc_d "/etc/rc.d" "/real_rootfs/etc/rc.d"
link_name=$(basename "$link")
if [ ! -e "/etc/rc.d/$link_name" ]; then # Synchronize between /etc/rc.d and /usrdata/etc/rc.d
/bin/echo "Removing $link_name from /real_rootfs/etc/rc.d/" synchronize_rc_d "/etc/rc.d" "/usrdata/etc/rc.d"
rm "/real_rootfs/etc/rc.d/$link_name"
fi
fi
done
# Final logs and remount the original root as read-only # Final logs and remount the original root as read-only
/bin/echo "...and we're back! The original root now lives at /real_rootfs" /bin/echo "...and we're back! The original root now lives at /real_rootfs"
@@ -246,12 +208,56 @@ handle_new_firmware() {
} }
stop() { synchronize_rc_d() {
# Redirect all output (stdout and stderr) to the log file local source_dir="$1"
exec >>"$LOG_FILE" 2>&1 local target_dir="$2"
/bin/echo "Synchronizing $source_dir with $target_dir"
for link in "$source_dir"/*; do
if [ -L "$link" ]; then
link_name=$(basename "$link")
if [ ! -e "$target_dir/$link_name" ]; then
/bin/echo "Copying $link_name to $target_dir"
cp -a "$link" "$target_dir/$link_name"
fi
fi
done
for link in "$target_dir"/*; do
if [ -L "$link" ]; then
link_name=$(basename "$link")
if [ ! -e "$source_dir/$link_name" ]; then
/bin/echo "Removing $link_name from $target_dir"
rm "$target_dir/$link_name"
fi
fi
done
} }
stop_handle_old_firmware() { stop() {
# Initialize log
rm -f "$LOG_FILE" >/dev/null 2>&1
touch "$LOG_FILE"
# Redirect all output (stdout and stderr) to the log file
exec >>"$LOG_FILE" 2>&1
# Check if /real_rootfs exists
if [ ! -d "/real_rootfs" ]; then
echo "Error: /real_rootfs does not exist. Cannot proceed with stop." >> "$LOG_FILE"
return 1
fi
# Determine firmware version based on mounts
if [ -d "/usrdata" ] && [ -d "/systemrw" ]; then
echo "New firmware scenario detected (with /usrdata and /systemrw)." >> "$LOG_FILE"
stop_handle_new_firmware
else
echo "Old firmware scenario detected (without /usrdata and /systemrw)." >> "$LOG_FILE"
stop_handle_old_firmware
fi
}
stop_handle_new_firmware() {
# Redirect all output (stdout and stderr) to the log file # Redirect all output (stdout and stderr) to the log file
exec >>"$LOG_FILE" 2>&1 exec >>"$LOG_FILE" 2>&1
/bin/echo "Stopping and reverting overlay and pivot_root" /bin/echo "Stopping and reverting overlay and pivot_root"
@@ -265,15 +271,52 @@ stop_handle_old_firmware() {
/bin/mount --move /tmp /real_rootfs/tmp /bin/mount --move /tmp /real_rootfs/tmp
/bin/mount --move /dev /real_rootfs/dev /bin/mount --move /dev /real_rootfs/dev
/bin/mount --move /firmware /real_rootfs/firmware /bin/mount --move /firmware /real_rootfs/firmware
/bin/mount --move /persist /real_rootfs/persist /bin/mount --move /usrdata /real_rootfs/usrdata
/bin/mount --move /cache /real_rootfs/cache
/bin/mount --move /data /real_rootfs/data /bin/mount --move /data /real_rootfs/data
/bin/mount --move /cache /real_rootfs/cache
/bin/mount --move /systemrw /real_rootfs/systemrw
/bin/mount --move /persist /real_rootfs/persist
# Pivot root back to the original root # Pivot root back to the original root
/sbin/pivot_root /real_rootfs /real_rootfs/rootfs /sbin/pivot_root /real_rootfs /real_rootfs/rootfs
/bin/echo "Reverted pivot_root" /bin/echo "Reverted pivot_root"
/bin/echo "Previous root overlay available at /rootfs"
# Unmount /rootfs overlay
/bin/umount -lf /rootfs >/dev/null 2>&1
# Mount layer 2 /etc back
/bin/mount -t ubifs -o rw,relatime,bulk_read,assert=read-only,ubi=2,vol=0 /dev/ubi2_0 /etc
# Mount layer 3 /etc back
/bin/mount -t overlay overlay -o lowerdir=/etc,upperdir=/usrdata/overlay-work/etc-upper,workdir=/usrdata/overlay-work/.etc-work /etc
df -h
echo -e "\e[31m / is read-write right now. Be careful\e[0m"
echo -e "\e[31m Reboot or run mount -o remount,ro / \e[0m"
}
stop_handle_old_firmware() {
# Redirect all output (stdout and stderr) to the log file
exec >>"$LOG_FILE" 2>&1
/bin/echo "Stopping and reverting overlay and pivot_root"
# Remount the original root filesystem as read-write
/bin/mount -o remount,rw /real_rootfs
# Move the mounted filesystems back to the original locations
/bin/mount --move /sys /real_rootfs/sys
/bin/mount --move /proc /real_rootfs/proc
/bin/mount --move /tmp /real_rootfs/tmp
/bin/mount --move /dev /real_rootfs/dev
/bin/mount --move /firmware /real_rootfs/firmware
/bin/mount --move /persist /real_rootfs/persist
/bin/mount --move /cache /real_rootfs/cache
/bin/mount --move /data /real_rootfs/data
# Pivot root back to the original root
/sbin/pivot_root /real_rootfs /real_rootfs/rootfs
/bin/echo "Reverted pivot_root"
# Unmount /rootfs overlay # Unmount /rootfs overlay
/bin/umount -lf /rootfs >/dev/null 2>&1 /bin/umount -lf /rootfs >/dev/null 2>&1
@@ -282,15 +325,11 @@ stop_handle_old_firmware() {
mount -t ubifs /dev/ubi0_3 /overlay mount -t ubifs /dev/ubi0_3 /overlay
# Mount the old overlay filesystem back for etc # Mount the old overlay filesystem back for etc
/bin/mount -t overlay overlay -o lowerdir=/etc,upperdir=/overlay/etc-upper,workdir=/overlay/.etc-work /etc /bin/mount -t overlay overlay -o lowerdir=/etc,upperdir=/overlay/etc-upper,workdir=/overlay/.etc-work /etc
echo -e "\e[31m / is read-write right now. Be careful\e[0m" echo -e "\e[31m / is read-write right now. Be careful\e[0m"
echo -e "\e[31m Reboot or run mount -o remount,ro / \e[0m" echo -e "\e[31m Reboot or run mount -o remount,ro / \e[0m"
} }
stop_handle_new_firmware() {
# Redirect all output (stdout and stderr) to the log file
exec >>"$LOG_FILE" 2>&1
} }
restart() { restart() {

0
ipk-source/sdxpinn-mount-fix/root/usr/bin/inotifywait Normal file → Executable file
View File

View File

View File

@@ -2,30 +2,57 @@
# Paths to monitor and synchronize # Paths to monitor and synchronize
WATCH_DIR="/etc/rc.d" WATCH_DIR="/etc/rc.d"
TARGET_DIR="/real_rootfs/etc/rc.d" TARGET_DIR1="/real_rootfs/etc/rc.d"
TARGET_DIR2="/usrdata/etc/rc.d"
# Function to synchronize init scripts # Function to synchronize init scripts
synchronize_init_scripts() { synchronize_init_scripts() {
# Ensure /real_rootfs is writable for updates
mount -o remount,rw /real_rootfs mount -o remount,rw /real_rootfs
# Copy new or updated symlinks from WATCH_DIR to TARGET_DIR
# Synchronize with TARGET_DIR1
echo "Synchronizing $WATCH_DIR with $TARGET_DIR1..."
for link in "$WATCH_DIR"/*; do for link in "$WATCH_DIR"/*; do
if [ -L "$link" ]; then if [ -L "$link" ]; then
link_name=$(basename "$link") link_name=$(basename "$link")
if [ ! -e "$TARGET_DIR/$link_name" ] || [ "$link" -nt "$TARGET_DIR/$link_name" ]; then if [ ! -e "$TARGET_DIR1/$link_name" ] || [ "$link" -nt "$TARGET_DIR1/$link_name" ]; then
cp -af "$link" "$TARGET_DIR/$link_name" cp -af "$link" "$TARGET_DIR1/$link_name"
fi fi
fi fi
done done
# Remove symlinks in TARGET_DIR that no longer exist in WATCH_DIR for link in "$TARGET_DIR1"/*; do
for link in "$TARGET_DIR"/*; do
if [ -L "$link" ]; then if [ -L "$link" ]; then
link_name=$(basename "$link") link_name=$(basename "$link")
if [ ! -e "$WATCH_DIR/$link_name" ]; then if [ ! -e "$WATCH_DIR/$link_name" ]; then
rm -f "$TARGET_DIR/$link_name" rm -f "$TARGET_DIR1/$link_name"
fi fi
fi fi
done done
# Synchronize with TARGET_DIR2 if /usrdata exists
if [ -d "/usrdata" ]; then
echo "Synchronizing $WATCH_DIR with $TARGET_DIR2..."
for link in "$WATCH_DIR"/*; do
if [ -L "$link" ]; then
link_name=$(basename "$link")
if [ ! -e "$TARGET_DIR2/$link_name" ] || [ "$link" -nt "$TARGET_DIR2/$link_name" ]; then
cp -af "$link" "$TARGET_DIR2/$link_name"
fi
fi
done
for link in "$TARGET_DIR2"/*; do
if [ -L "$link" ]; then
link_name=$(basename "$link")
if [ ! -e "$WATCH_DIR/$link_name" ]; then
rm -f "$TARGET_DIR2/$link_name"
fi
fi
done
fi
# Restore /real_rootfs to read-only
mount -o remount,ro /real_rootfs mount -o remount,ro /real_rootfs
} }
@@ -37,3 +64,4 @@ while true; do
inotifywait -e create,delete,modify,move "$WATCH_DIR" inotifywait -e create,delete,modify,move "$WATCH_DIR"
synchronize_init_scripts synchronize_init_scripts
done done