What's new
  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

overwrite /jffs/bin: how to restore

gatorback

Senior Member
RTAC68U Firmware Version:384.7_2

It was 2AM and I had no business doing anything that late at night. I tried to mv a file and ended up mv-ing it to /jffs/bin instead of /jffs/bin/myfile. I am in shock that I did this.

To be clear: I no longer have access to to the files in what was the /jffs/bin directory. / jffs/bin is now a text file . I am concerned that if this router loses power, it will be bricked. What can be done to recover the files? I am pretty sure they are still there as I have not overwritten that area of memory (jffs).

The offending command is
Code:
mv loggerreset /jffs/bin

Commands prior /after the offending instruction;

Code:
bob@RT-AC68U-4C09:/jffs# vi loggerreset
bob@RT-AC68U-4C09:/jffs# chmod +x logger reset
chmod: logger: No such file or directory
chmod: reset: No such file or directory
bob@RT-AC68U-4C09:/jffs# chmod +x loggerreset
bob@RT-AC68U-4C09:/jffs# loggerreset
-sh: loggerreset: not found
bob@RT-AC68U-4C09:/jffs# mv loggerreset /jffs/bin/
mv: can't rename 'loggerreset': Not a directory
bob@RT-AC68U-4C09:/jffs# mv loggerreset /jffs/bin
bob@RT-AC68U-4C09:/jffs# which loggerreset
bob@RT-AC68U-4C09:/jffs# loggerreset
-sh: loggerreset: not found
bob@RT-AC68U-4C09:/jffs# which loggerreset
bob@RT-AC68U-4C09:/jffs# ls /jffs/bin
/jffs/bin
bob@RT-AC68U-4C09:/jffs# ls -l /jffs/bin
-rwxrwxrwx    1 bob    root           554 Nov 30 01:24 /jffs/bin
/


Command shows that /jffs/bin now a text file (yikes!)

Code:
bob@RT-AC68U-4C09:/jffs# cat /jffs/bin
#!/bin/zsh

echo "Checking for running mqtt_logger.sh and mosquitto_sub processes:"
pgrep -f "mqtt_logger.sh|mosquitto_sub"
echo " "

echo "Killing the processes:"
pgrep -f "mqtt_logger.sh|mosquitto_sub" | xargs kill

echo "Verifying processes are terminated:"
pgrep -f "mqtt_logger.sh|mosquitto_sub"

echo "Running mqttcheck:"
mqttcheck

echo " "
read -q "?Press any key to proceed with starting mqtt_logger.sh..."

echo " "
echo "Starting mqtt_logger.sh in the background:"
sh /jffs/scripts/mqtt_logger.sh &

echo "Running final mqttcheck:"
mqttcheck
 
Last edited:
Let's start with the idea that you are on 380.58, which is 9 years old. Or maybe 384.7_2, which is 7 years old.
 
Last edited:
Let's start with the idea that you are on 380.58, which is 9 years old.
Wow! Missed that. Couldn't see the siggie on my phone.
@gatorback time to update, reset, and rebuild 😉
 
How did you achieve that?

For most Unix systems moving file myfile to folder /jffs/bin results in a file /jffs/bin/myfile.
I am little puzzled by what I see in the log, resulting in said question.
 
I am little puzzled by what I see in the log, resulting in said question.
The log information you added to your original post indicates that the /jffs/bin/ directory didn't exist in the first place.

The first move error message is slightly different that expected suggesting you're not using the router's standard shell.
 
The first move error message is slightly different that expected suggesting you're not using the router's standard shell.
The Shebang in the script suggests zsh.

I use that shell, also on my router, but I don’t think it would cause this.

Can maybe test later today.
 
I tested this on my router (GT-AX6000 with Asuswrt-Merlin 3006.102.6):
  1. Created the folder /jffs/bin
  2. Created the file test.sh
  3. mv test.sh /jffs/bin
Result: a file /jffs/bin/test.sh

I'm running zsh 5.9 (aarch64-openwrt-linux-gnu) from Entware.
 
/jffs/bin/ isn’t a standard directory in the router’s PATH, so unless you’ve added it, the router shouldn’t be brickable.
Anything is 'Brickable' .... If you use a large enough 'Brick', applied the correct number of times !!! 😁:eek:;)
 
I've had a few instances in the past where a brief power blip has resulted in a complete loss of everything in /jffs. In no case did it brick the router, but it did take a while to figure out what was lost and how to restore it. As a result of that, I run a script that does a backup of /jffs to a .tar file once a month. The last time, I was able to completely restore things and get back up and running within just a few minutes with no loss of function. Backup would be similarly useful for an unintended overwrite of any part. Code snippet below ('dot' at the end of the tar command is intended):

Bash:
    day=$(date +"%d")
    longdate=$(date +"%Y%m%d%H%M")
    if [[ $day -eq 1 ]]; then
        cd /jffs
        tar -cv -f /tmp/mnt/$admin_usb/Config/Logs/jffs_backup/$longdate-backup_jffs.tar .
        fi
 
I've had a few instances in the past where a brief power blip has resulted in a complete loss of everything in /jffs. In no case did it brick the router, but it did take a while to figure out what was lost and how to restore it. As a result of that, I run a script that does a backup of /jffs to a .tar file once a month. The last time, I was able to completely restore things and get back up and running within just a few minutes with no loss of function. Backup would be similarly useful for an unintended overwrite of any part. Code snippet below ('dot' at the end of the tar command is intended):

Bash:
    day=$(date +"%d")
    longdate=$(date +"%Y%m%d%H%M")
    if [[ $day -eq 1 ]]; then
        cd /jffs
        tar -cv -f /tmp/mnt/$admin_usb/Config/Logs/jffs_backup/$longdate-backup_jffs.tar .
        fi
Or, as you're running Merlin firmware, you could install BACKUPMON and let that take care of it all. Especially valuable as it also backs up your nvram and attached storage. Full rebuild from a factory reset would take less than 10 minutes.
 
Or, as you're running Merlin firmware, you could install BACKUPMON and let that take care of it all. Especially valuable as it also backs up your nvram and attached storage. Full rebuild from a factory reset would take less than 10 minutes.

Agree. I do the nvram backup as well at the same time. Didn't include that part here. It's part of a script that runs every 3 hours to take care of that, copy system logs and do several other housekeeping things.
 
Or, as you're running Merlin firmware, you could install BACKUPMON and let that take care of it all. Especially valuable as it also backs up your nvram and attached storage. Full rebuild from a factory reset would take less than 10 minutes.
As well as providing a full restore capability, you can also still restore whatever you want, quickly, by accessing the .tar.gz files in the backup made by BACKUPMON.

If you store the BACKUPMON backups on a share that is on-line you can use 'winscp' to browse the backup files and 'automagically' open them in something like 'winrar' and copy selected files directly to the folders of your choice.

i.e. You don't need to know 'tar' commands etc !!!

Its just like using 'windoze explorer' !!!

example.png
 

Similar threads

Latest threads

Support SNBForums w/ Amazon

If you'd like to support SNBForums, just use this link and buy anything on Amazon. Thanks!

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!

Members online

Back
Top