Initial Commit

Start new branch for development on new 64bit x75 platfom.
This commit is contained in:
Cameron Thompson
2024-07-07 20:15:59 -04:00
parent 88d300303c
commit bfd4b31fea
83 changed files with 599 additions and 0 deletions

22
Belowx65Toolkit/LICENSE Normal file
View File

@@ -0,0 +1,22 @@
MIT License with Additional Stipulations
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
1. A clear and visible attribution to the original author (you) must be provided in an obvious place in any product, documentation, or interface where the software is utilized. This attribution should include your name and a reference to the original source repository.
2. The Software, or any modified version of it, must not be sold or charged for. However, selling physical products that include the Software is permitted, provided that a clear and visible attribution to the original author (you) is included in an obvious place in the product or accompanying documentation.
3. Any modifications made to the Software must be made available upon request by any party. This includes providing access to the modified source code, along with any accompanying documentation necessary for understanding the modifications.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

158
Belowx65Toolkit/README.md Normal file
View File

@@ -0,0 +1,158 @@
# RGMII Toolkit
Software deployment Toolkit for Quectel RM5xxx series 5G modems utilizing an m.2 to RJ45 adapter (RGMII)
Current Branch: **Development**
Please PR to this branch instead of main :)
Fork development, and PR development to development :)
#### [JUMP TO HOW TO USE](#how-to-use)
**Currently:** This will allow you to install or if already installed, update, remove, or modify:
- Simple Admin: A simple web interface for managing your Quectel m.2 modem through it's gateway address
- It will install socat-at-bridge: sets up ttyOUT and ttyOUT2 for AT commands. You'll be able to use the `atcmd` command as well for an interactive at command session from adb, ssh, or ttyd
- It will install simplefirewall: A simple firewall that blocks definable incoming ports and a TTL mangle option/modifier. As of now only the TTL is controllable through Simple Admin. You can edit port block options and TTL from the 3rd option in the toolkit
- Tailscale: A magic VPN for accessing Simple Admin, SSH, and ttyd on the go. The Toolkit installs the Tailscale client directly to the modem and allows you to login and configure other settings. Head over to tailscale.com to sign up for a free account and learn more.
- Schedule a Daily Reboot at a specified time
- A fix for certain modems that don't start in CFUN=1 mode
- Entware/OPKG: A package installer/manager/repo
- Run `opkg help` to see how to use it
- These packages are installable: https://bin.entware.net/armv7sf-k3.2/Packages.html
- TTYd: A shell session right from your browser
- Currently this uses port 443 but SSL/TLS is not in use (http only for now)
- Entware/OPKG is required so it will install it if it isn't installed
- This will replace the stock Quectel login and passwd binaries with ones from entware
**My goal** is for this to also include any new useful scripts or software for this modem and others that support RGMII mode.
## Screenshots
![Home Page](https://github.com/iamromulan/quectel-rgmii-configuration-notes/blob/main/images/iamromulansimpleindex.png?raw=true)
![AT Commands](https://github.com/iamromulan/quectel-rgmii-configuration-notes/blob/main/images/iamromulanatcommands.png?raw=true)
![TTL](https://github.com/iamromulan/quectel-rgmii-configuration-notes/blob/main/images/iamromulansimpleTTL.png?raw=true)
![Toolkit](https://github.com/iamromulan/quectel-rgmii-configuration-notes/blob/main/images/iamromulantoolkit.png?raw=true)
# Devleopment Branch: the below commands will download the beta/work in progress toolkit
## How to Use
**To run the Toolkit:**
- Open ADB & Fastboot++ covered in [Using ADB](https://github.com/iamromulan/quectel-rgmii-configuration-notes?tab=readme-ov-file#unlocking-and-using-adb) or just use adb
- Make sure your modem is connected by USB to your computer
- Run `adb devices` to make sure your modem is detected by adb
- Run `adb shell ping 8.8.8.8` to make sure the shell can access the internet. If you get an error, make sure the modem is connected to a cellular network and make sure `AT+QMAPWAC=1` as covered in the troubleshooting section: [I Can't get internet access from the Ethernet port (Common)](https://github.com/iamromulan/quectel-rgmii-configuration-notes/tree/main?tab=readme-ov-file#i-cant-get-internet-access-from-the-ethernet-port-common)
- If you don't get an error you should be getting replies back endlessly, press `CTRL-C` to stop it.
- Simply Copy/Paste this into your Command Prompt/Shell
```bash
adb shell "cd /tmp && wget -O RMxxx_rgmii_toolkit.sh https://raw.githubusercontent.com/iamromulan/quectel-rgmii-toolkit/development/RMxxx_rgmii_toolkit.sh && chmod +x RMxxx_rgmii_toolkit.sh && ./RMxxx_rgmii_toolkit.sh" && cd /
```
**Or, if you want to stay in the modems shell when you are done**
```
adb shell
```
Then run
```
cd /tmp && wget -O RMxxx_rgmii_toolkit.sh https://raw.githubusercontent.com/iamromulan/quectel-rgmii-toolkit/development/RMxxx_rgmii_toolkit.sh && chmod +x RMxxx_rgmii_toolkit.sh && ./RMxxx_rgmii_toolkit.sh && cd /
```
**You should see:**
![Toolkit](https://github.com/iamromulan/quectel-rgmii-configuration-notes/blob/main/images/iamromulantoolkit.png?raw=true)
## Tailscale Installation and Config
> :warning: Your modem must already be connected to the internet for this to install
### Installation:
Open up the toolkit main menu and **press 4** to enter the Tailscale menu
![Toolkit](https://github.com/iamromulan/quectel-rgmii-configuration-notes/blob/main/images/tailscalemenu.png?raw=true)
**Press 1, wait for it to install. This is a very large file for the system so give it some time.**
**Once done and it says Tailscale installed successfully press 2/enter to configure it.**
![Toolkit](https://github.com/iamromulan/quectel-rgmii-configuration-notes/blob/main/images/tailscaleconfig.png?raw=true)
If you want to, enable the Tailscale Web UI on port 8088 for configuration from the browser later by **pressing 1/enter**.
To do it in the toolkit:
First time connecting you'll be given a link to login with
- Press 3 to just connect only.
- Press 4 to connect and enable SSH access (remote command line) over tailscale.
- Press 5 to reconnect with SSH off while connected with SSH on
- Press 6 to disconnect
- Press 7 to Logout
That's it! From another device running tailscale you should be able to access your modem through the IP assigned to it by your tailnet. To access SSH from another device on the tailnet, open a terminal/command prompt and type
tailscale ssh root@(IP or Hostname)
IP or Hostname being the IP or hostname assigned to it in your tailnet
- Note that your SSH client must be able to give you a link to sign in with upon connecting. That's how the session is authorized. Works fine in Windows CMD or on Android use JuiceSSH.
## Advanced/Beta
### Entware/OPKG installation
It isn't perfect yet so it goes here under Advanced/Beta for now.
Here's what you gotta know about going into it:
- After installing, the `opkg` command will work
- You can run `opkg list` to see a list of installable packages, or head over to https://bin.entware.net/armv7sf-k3.2/Packages.html
- Everything opkg does is installed to /opt
- `/opt` is actually located at `/usrdata/opt` to save space but is
mounted at `/opt`
- Anything `opkg` installs will not be available in the system path by
default but you can get around this either:
#### Temporarily:
Run this at the start of each adb shell or SSH shell session
export PATH=/opt/bin:/opt/sbin:$PATH
#### Permanently:
Symbolic linking each binary installed by the package to `/bin` and `/sbin` from `/opt/bin` and `/opt/sbin`
For example, if you were to install zerotier:
opkg install zerotier
ln -sf /opt/bin/zerotier-one /bin
ln -sf /opt/bin/zerotier-cli /bin
ln -sf /opt/bin/zerotier-idtool /bin
Now you can run those 3 binaries from the shell anytime since they are linked in a place already part of the system path.
I plan to create a watchdog service for /opt/bin and /opt/sbin that will automaticly link new packages to /bin or /sbin later on in order to combat this.
### TTYd installation
It isn't perfect yet so it goes here under Advanced/Beta for now.
Here's what you gotta know about going into it:
- This listens on port 443 for http requests (no SSL/TLS yet)
- This will automaticly install entware and patch the login and passwd binaries with ones from entware
- It will ask you to set a password for the `root` user account
- TTYd doesn't seem to be too mobile friendly for now but I optimized it the best i could for now so it is at least usable through a smartphone browser. Hopefully the startup script can be improved even more later.
## Acknowledgements
### GitHub Users/Individuals:
Thank You to:
[Nate Carlson](https://github.com/natecarlson) for the Original Telnet Deamon/socat bridge usage and the Original RGMII Notes
[aesthernr](https://github.com/aesthernr) for creating the Original Simple Admin
[rbflurry](https://github.com/rbflurry/) for inital Simple Admin fixes
[dr-dolomite](https://github.com/dr-dolomite) for some major stat page improvements and this repos first approved external PR!
[tarunVreddy](https://github.com/tarunVreddy) for helping with the SA band aggregation parse
### Existing projects:
Simpleadmin heavily uses the AT Command Parsing Scripts (Basically a copy with new changes and tweaks) of Dairyman's Rooter Source https://github.com/ofmodemsandmen/ROOterSource2203
Tailscale was obtained through Tailscale's static build page. Since these modems have a 32-bit ARM processor on-board I used the arm package. https://pkgs.tailscale.com/stable/#static
Entware/opkg was obtained through [Entware's wiki](https://github.com/Entware/Entware/wiki/Alternative-install-vs-standard) and the installer heavily modified by [iamromulan](https://github.com/iamromulan) for use with Quectel modems
TTYd was obtained from the [TTYd Project](https://github.com/tsl0922/ttyd)

View File

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 15 KiB

308
RM55x_rcPCIe_toolkit.sh Normal file
View File

@@ -0,0 +1,308 @@
#!/bin/sh
#WORK IN PROGRESS
# Define toolkit paths
GITUSER="iamromulan"
GITTREE="development-RM551"
GITMAINTREE="main"
GITDEVTREE="development"
TMP_DIR="/tmp"
USRDATA_DIR="/data"
SOCAT_AT_DIR="/data/socat-at-bridge"
SOCAT_AT_SYSD_DIR="/data/socat-at-bridge/systemd_units"
SIMPLE_ADMIN_DIR="/data/simpleadmin"
SIMPLE_FIREWALL_DIR="/data/simplefirewall"
SIMPLE_FIREWALL_SCRIPT="$SIMPLE_FIREWALL_DIR/simplefirewall.sh"
SIMPLE_FIREWALL_SYSTEMD_DIR="$SIMPLE_FIREWALL_DIR/systemd"
# AT Command Script Variables and Functions
DEVICE_FILE="/dev/smd7"
TIMEOUT=4 # Set a timeout for the response
# Function to remount file system as read-write
remount_rw() {
mount -o remount,rw /
}
# Function to remount file system as read-only
remount_ro() {
mount -o remount,ro /
}
# Basic AT commands without socat bridge for fast responce commands only
start_listening() {
cat "$DEVICE_FILE" > /tmp/device_readout &
CAT_PID=$!
}
send_at_command() {
echo -e "\e[1;31mThis only works for basic quick responding commands!\e[0m" # Red
echo -e "\e[1;36mType 'install' to simply type atcmd in shell from now on\e[0m"
echo -e "\e[1;36mThe installed version is much better than this portable version\e[0m"
echo -e "\e[1;32mEnter AT command (or type 'exit' to quit): \e[0m"
read at_command
if [ "$at_command" = "exit" ]; then
return 1
fi
if [ "$at_command" = "install" ]; then
install_update_at_socat
echo -e "\e[1;32mInstalled. Type atcmd from adb shell or ssh to start an AT Command session\e[0m"
return 1
fi
echo -e "${at_command}\r" > "$DEVICE_FILE"
}
wait_for_response() {
local start_time=$(date +%s)
local current_time
local elapsed_time
echo -e "\e[1;32mCommand sent, waiting for response...\e[0m"
while true; do
if grep -qe "OK" -e "ERROR" /tmp/device_readout; then
echo -e "\e[1;32mResponse received:\e[0m"
cat /tmp/device_readout
return 0
fi
current_time=$(date +%s)
elapsed_time=$((current_time - start_time))
if [ "$elapsed_time" -ge "$TIMEOUT" ]; then
echo -e "\e[1;31mError: Response timed out.\e[0m" # Red
echo -e "\e[1;32mIf the responce takes longer than a second or 2 to respond this will not work\e[0m" # Green
echo -e "\e[1;36mType install to install the better version of this that will work.\e[0m" # Cyan
return 1
fi
sleep 1
done
}
cleanup() {
kill "$CAT_PID"
wait "$CAT_PID" 2>/dev/null
rm -f /tmp/device_readout
}
send_at_commands() {
if [ -c "$DEVICE_FILE" ]; then
while true; do
start_listening
send_at_command
if [ $? -eq 1 ]; then
cleanup
break
fi
wait_for_response
cleanup
done
else
echo -e "\e[1;31mError: Device $DEVICE_FILE does not exist!\e[0m"
fi
}
basic_55x_setup() {
#To be built out soon
echo -e "\e[1;31mComing soon.\e[0m"
}
# Function for Tailscale Submenu
tailscale_menu() {
while true; do
echo -e "\e[1;32mTailscale Menu\e[0m"
echo -e "\e[1;32m1) Install/Update Tailscale\e[0m"
echo -e "\e[1;36m2) Configure Tailscale\e[0m"
echo -e "\e[1;31m3) Return to Main Menu\e[0m"
read -p "Enter your choice: " tailscale_choice
case $tailscale_choice in
1) install_update_tailscale;;
2) configure_tailscale;;
3) break;;
*) echo "Invalid option";;
esac
done
}
# Function to install, update, or remove Tailscale
install_update_tailscale() {
echo -e "\e[1;31m2) Installing tailscale from opkg\e[0m"
opkg install tailscale
echo -e "\e[1;32m Tailscale has been updated/installed.\e[0m"
echo -e "\e[1;31m Tailscale is not up to date!.\e[0m"
# Add logic here later for an up-to-date installation
echo -e "\e[1;32m Replace the tailscale and tailscaled binaries with the new ones and run tailscale update.\e[0m"
}
# Function to Configure Tailscale
configure_tailscale() {
while true; do
echo "Configure Tailscale"
echo -e "\e[38;5;40m1) Enable Tailscale Web UI at http://192.168.225.1:8088 (Gateway on port 8088)\e[0m" # Green
echo -e "\e[38;5;196m2) Disable Tailscale Web UI\e[0m" # Red
echo -e "\e[38;5;27m3) Connect to Tailnet\e[0m" # Brown
echo -e "\e[38;5;87m4) Connect to Tailnet with SSH ON\e[0m" # Light cyan
echo -e "\e[38;5;105m5) Reconnect to Tailnet with SSH OFF\e[0m" # Light magenta
echo -e "\e[38;5;172m6) Disconnect from Tailnet (reconnects at reboot)\e[0m" # Light yellow
echo -e "\e[1;31m7) Logout from tailscale account\e[0m"
echo -e "\e[38;5;27m8) Return to Tailscale Menu\e[0m"
read -p "Enter your choice: " config_choice
case $config_choice in
1)
echo -e "\e[38;5;196mNot for the 551 yet\e[0m" # Red
;;
2)
echo -e "\e[38;5;196mNot for the 551 yet\e[0m" # Red
;;
3) tailscale up --accept-dns=false --reset;;
4) tailscale up --ssh --accept-dns=false --reset;;
5) tailscale up --accept-dns=false --reset;;
6) tailscale down;;
7) tailscale logout;;
8) break;;
*) echo "Invalid option";;
esac
done
}
# Main menu
while true; do
echo " .%+: "
echo " .*@@@-. "
echo " :@@@@- "
echo " @@@@#. "
echo " -@@@@#. "
echo " :. %@@@@: -# "
echo " .+- #@@@@%.+@- "
echo " .#- . +@@@@# #@- "
echo " -@*@*@% @@@@@::@@= "
echo ".+%@@@@@@@@@%=. =@@@@# #@@- .. "
echo " .@@@@@: :@@@@@ =@@@..%= "
echo " -::@-.+. @@@@@.=@@@- =@- "
echo " .@- .@@@@@:.@@@* @@. "
echo " .%- -@@@@@:=@@@@ @@# "
echo " .#- .%@@@@@@#. +@@@@@.#@@@@ @@@."
echo " .*- .@@@@@@@@@@=. @@@@@@ @@@@@ @@@:"
echo " :. .%@@@@@@@@@@@%. .@@@@@+:@@@@@ @@@-"
echo " -@@@@@@@@@@@@@@@..@@@@@@.-@@@@@ .@@@-"
echo " -@@@@@@@@@@%. .@@@@@@. @@@@@+ =@@@="
echo " =@@@@@@@@* .@@@@@@. @@@@@@..@@@@-"
echo " #@@@@@@@@-*@@@@@%..@@@@@@+ #@@@@-"
echo " @@@@@@:.-@@@@@@. @@@@@@= %@@@@@."
echo " .@@@@. *@@@@@@- .+@@@@@@-.@@@@@@+ "
echo " %@@. =@@@@@*. +@@@@@@%.-@@@@@@% "
echo " .@@ .@@@@@= :@@@@@@@@..@@@@@@@= "
echo " =@.+@@@@@. -@@@@@@@*.:@@@@@@@*. "
echo " %.*@@@@= .@@@@@@@-.:@@@@@@@+. "
echo " ..@@@@= .@@@@@@: #@@@@@@@: "
echo " .@@@@ +@@@@..%@@@@@+. "
echo " .@@@. @@@@.:@@@@+. "
echo " @@@. @@@. @@@* .@. "
echo " :@@@ %@@..@@#. *@ "
echo " -*: .@@* :@@. @@. -..@@ "
echo " =@@@@@@.*@- :@% @* =@:=@# "
echo " .@@@-+@@@@:%@..%- ...@%:@@: "
echo " .@@. @@-%@: .%@@*@@%. "
echo " :@@ :+ *@ *@@#*@@@. "
echo " =@@@.@@@@ "
echo " .*@@@:=@@@@: "
echo " .@@@@:.@@@@@: "
echo " .@@@@#.-@@@@@. "
echo " #@@@@: =@@@@@- "
echo " .@@@@@..@@@@@@* "
echo " -@@@@@. @@@@@@#. "
echo " -@@@@@ @@@@@@% "
echo " @@@@@. #@@@@@@. "
echo " :@@@@# =@@@@@@% "
echo " @@@@@: @@@@@@@: "
echo " *@@@@ @@@@@@@. "
echo " .@@@@ @@@@@@@ "
echo " #@@@. @@@@@@* "
echo " @@@# @@@@@@@ "
echo " .@@+=@@@@@@. "
echo " *@@@@@@ "
echo " :@@@@@= "
echo " .@@@@@@. "
echo " :@@@@@*. "
echo " .=@@@@@- "
echo " :+##+. "
echo -e "\e[92m"
echo "Welcome to iamromulan's rcPCIe Toolkit script for Quectel RM55x Series modems!"
echo "Visit https://github.com/iamromulan for more!"
echo -e "\e[0m"
echo -e "\e[91mThis is a test version of the toolit for the new RM550/551 modems\e[0m" # Light Red
echo "Select an option:"
echo -e "\e[0m"
echo -e "\e[96m1) Send AT Commands\e[0m" # Cyan
echo -e "\e[92m2) First time setup/run me after a flash!\e[0m" # Green
echo -e "\e[94m3) Set root password\e[0m" # Light Blue
echo -e "\e[94m4) Tailscale Management\e[0m" # Light Blue
echo -e "\e[92m5) Install Speedtest.net CLI app (speedtest command)\e[0m" # Light Green
echo -e "\e[93m6) Exit\e[0m" # Yellow (repeated color for exit option)
read -p "Enter your choice: " choice
case $choice in
1)
send_at_commands
;;
2)
basic_55x_setup
;;
98)
# Blank
;;
3)
set_root_passwd
;;
97)
# Blank
;;
96)
# Blank
;;
4)
tailscale_menu
;;
95)
# Blank
;;
94)
# Blank
;;
93)
# Blank
;;
5)
echo -e "\e[1;32mInstalling Speedtest.net CLI (speedtest command)\e[0m"
# Add Logic to confirm we are overlayed over the larger /data
cd /usr/bin
wget https://install.speedtest.net/app/cli/ookla-speedtest-1.2.0-linux-aarch64.tgz
tar -xzf ookla-speedtest-1.2.0-linux-aarch64.tgz
rm ookla-speedtest-1.2.0-linux-aarch64.tgz
rm speedtest.md
cd /
echo -e "\e[1;32mSpeedtest CLI (speedtest command) installed!!\e[0m"
echo -e "\e[1;32mTry running the command 'speedtest'\e[0m"
echo -e "\e[1;32mNote that it will not work unless you login to the root account first\e[0m"
echo -e "\e[1;32mNormaly only an issue in adb, ttyd and ssh you are forced to login\e[0m"
echo -e "\e[1;32mIf in adb just type login and then try to run the speedtest command\e[0m"
;;
92)
# Blank
;;
91)
# Blank
;;
6)
echo -e "\e[1;32mGoodbye!\e[0m"
break
;;
*)
echo -e "\e[1;31mInvalid option\e[0m"
;;
esac
done

111
init.d/mount-fix Normal file
View File

@@ -0,0 +1,111 @@
#!/bin/sh /etc/rc.common
START=03
start() {
# Log to tmp
rm /tmp/mount-fix.log
/bin/touch /tmp/mount-fix.log
/bin/echo "Begin mount fix process to make a usable userspace" >> /tmp/mount-fix.log
# Forcefully unmount /etc
/bin/echo "Unmounting the tiny overlay at /etc" >> /tmp/mount-fix.log
/bin/umount -lf /etc >> /tmp/mount-fix.log
# Remount root filesystem as read-write
/bin/echo "Remounting / as read-write" >> /tmp/mount-fix.log
/bin/mount -o remount,rw / >> /tmp/mount-fix.log
# 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 needs merged." >> /tmp/mount-fix.log
/bin/echo "Looking for evidence that this has already happened..." >> /tmp/mount-fix.log
if [ ! -f /overlay/etc-upper/merged.done ]; then
/bin/echo "/overlay/etc-upper/merged.done not found, merging /overlay/etc-upper/* to /etc/" >> /tmp/mount-fix.log
cp -rf /overlay/etc-upper/* /etc/ >> /tmp/mount-fix.log
/bin/touch /overlay/etc-upper/merged.done >> /tmp/mount-fix.log
else
/bin/echo "/overlay/etc-upper/merged.done found, skipping merge" >> /tmp/mount-fix.log
fi
# Unmount /overlay
/bin/echo "Unmounting the no longer needed /overlay" >> /tmp/mount-fix.log
/bin/umount /overlay >> /tmp/mount-fix.log
# Check if /etc/opkg.conf has a line containing "option overlay_root /overlay" and remove it if it exists
/bin/echo "Lets be sure your opkg config isn't using the old overlay" >> /tmp/mount-fix.log
if grep -q "option overlay_root /overlay" /etc/opkg.conf; then
/bin/echo "Removing 'option overlay_root /overlay' from /etc/opkg.conf" >> /tmp/mount-fix.log
sed -i '/option overlay_root \/overlay/d' /etc/opkg.conf >> /tmp/mount-fix.log
else
/bin/echo "'option overlay_root /overlay' not found in /etc/opkg.conf, no changes made" >> /tmp/mount-fix.log
fi
# Ensure necessary directories exist for overlay and pivot_root
/bin/echo "Creating new overlay system" >> /tmp/mount-fix.log
if [ ! -d /data/rootfs ]; then
mkdir -p /data/rootfs
fi
if [ ! -d /data/rootfs-workdir ]; then
mkdir -p /data/rootfs-workdir
fi
if [ ! -d /rootfs ]; then
mkdir -p /rootfs
fi
# Mount the new overlay filesystem
/bin/mount -t overlay overlay -o lowerdir=/,upperdir=/data/rootfs,workdir=/data/rootfs-workdir /rootfs >> /tmp/mount-fix.log
# Create the real_rootfs directory in the new root
if [ ! -d /rootfs/real_rootfs ]; then
mkdir -p /rootfs/real_rootfs
fi
# Pivot root to the new root
/bin/echo "Pivoting Root / to /rootfs; Be back soon!!" >> /tmp/mount-fix.log
/bin/pivot_root /rootfs /rootfs/real_rootfs >> /tmp/mount-fix.log
# Move the mounted filesystems to the new locations
/bin/mount --move /real_rootfs/sys /sys >> /tmp/mount-fix.log
/bin/mount --move /real_rootfs/proc /proc >> /tmp/mount-fix.log
/bin/mount --move /real_rootfs/tmp /tmp >> /tmp/mount-fix.log
/bin/mount --move /real_rootfs/dev /dev >> /tmp/mount-fix.log
/bin/mount --move /real_rootfs/firmware /firmware >> /tmp/mount-fix.log
/bin/mount --move /real_rootfs/persist /persist >> /tmp/mount-fix.log
/bin/mount --move /real_rootfs/cache /cache >> /tmp/mount-fix.log
/bin/mount --move /real_rootfs/data /data >> /tmp/mount-fix.log
# 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
/bin/mount -o remount,ro /real_rootfs >> /tmp/mount-fix.log
/bin/echo "Overlay and pivot_root setup completed" >> /tmp/mount-fix.log
}
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
# Move the mounted filesystems back to the original locations
/bin/mount --move /sys /real_rootfs/sys >> /tmp/mount-fix.log
/bin/mount --move /proc /real_rootfs/proc >> /tmp/mount-fix.log
/bin/mount --move /tmp /real_rootfs/tmp >> /tmp/mount-fix.log
/bin/mount --move /dev /real_rootfs/dev >> /tmp/mount-fix.log
/bin/mount --move /firmware /real_rootfs/firmware >> /tmp/mount-fix.log
/bin/mount --move /persist /real_rootfs/persist >> /tmp/mount-fix.log
/bin/mount --move /cache /real_rootfs/cache >> /tmp/mount-fix.log
/bin/mount --move /data /real_rootfs/data >> /tmp/mount-fix.log
# Pivot root back to the original root
/bin/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
}
restart() {
/bin/echo "This script should only be executed once at boot"
/bin/echo "Use Stop to undo the pivot"
}