1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
Dismiss Notice

Welcome To SNBForums

SNBForums is a community for anyone who wants to learn about or discuss the latest in wireless routers, network storage and the ins and outs of building and maintaining a small network.

If you'd like to post a question, simply register and have at it!

While you're at it, please check out SmallNetBuilder for product reviews and our famous Router Charts, Ranker and plenty more!

Router reboot cause deletion of root folder

Discussion in 'Asuswrt-Merlin' started by mr_radar, Oct 9, 2019.

  1. mr_radar

    mr_radar New Around Here

    Joined:
    Jul 19, 2019
    Messages:
    7
    Hi,

    I noticed a strange behaviour of my router (ASUS RT-AC86U). When I reboot the router all the files I installed in /tmp/home/root are getting deleted...

    This is a very very strange behaviour...

    I dot not understand why the files in the root folder are not persistent. It is even worse it does not make sense to me ? Am I missing something specific to that type of device ?

    I will really appreciate your answers :)

    Cheers,

    PS : ASUS RT-AC86U, FW 384.11_2
    FYI, I created this ZSH version adapted for Asus router, you can read more about it here :
    https://www.snbforums.com/threads/install-oh-my-zsh-on-asus-routers.57662/
     
  2. dave14305

    dave14305 Part of the Furniture

    Joined:
    May 19, 2018
    Messages:
    2,949
    Location:
    USA
    /tmp/home/root is RAM-based. Expected behavior. Only /jffs or a USB will survive a reboot.
     
  3. mr_radar

    mr_radar New Around Here

    Joined:
    Jul 19, 2019
    Messages:
    7
    Ok, now I understand the loss of my files. It makes sense. Thank you dave14305.

    Questions :
    - Is there a way to keep my files in the root folder permanently (I have my ZSH config there)
    - Why is the unix asus firmware built that way ? I don't see the point...

    Thanks :)
     
  4. ColinTaylor

    ColinTaylor Part of the Furniture

    Joined:
    Mar 31, 2014
    Messages:
    11,679
    Location:
    UK
    You could probably create a startup script that copied your files from a non-volatile location (like /jffs) to the appropriate directory.
    https://github.com/RMerl/asuswrt-merlin/wiki/User-scripts

    Because it's not Unix, it's a network appliance with an embedded operating system built around a Linux kernel. It's not designed to be a desktop or server system that people log into. The only reason you're able to create persistent scripts on it is because Merlin modified the code to do something it was never designed to do.
     
    martinr likes this.
  5. Ronald Schwerer

    Ronald Schwerer Senior Member

    Joined:
    Jan 8, 2017
    Messages:
    459
    Keep the file(s) you want to persist in a subdirectory of /jffs. Then in your startup script, create symbolic links in /home/root that point back to the actual files.
    I do this to retain my /home/root/.ssh directory (public and private keys). This is better than copying the files each time since it will also persist any modifications.
     
    ColinTaylor likes this.
  6. Ronald Schwerer

    Ronald Schwerer Senior Member

    Joined:
    Jan 8, 2017
    Messages:
    459
    No, I am running stock ASUS firmware. Not as versatile as Merlin, but it still allows running basic sh scripts for housekeeping.
     
  7. cmkelley

    cmkelley Very Senior Member

    Joined:
    Aug 11, 2015
    Messages:
    1,161
    Location:
    Greater Los Angeles Area, California, USizicstania
    If you're posting here and using zsh I assume you are using Asuswrt-Merlin with a usb drive and have entware installed.

    My solution is to have the following in jffs/scripts/post-mount:
    Code:
    rm -rf /tmp/home/root
    ln -s /opt/root /tmp/home/root
    
    and so all of root is persistent, including my shell history. :)
     
  8. ColinTaylor

    ColinTaylor Part of the Furniture

    Joined:
    Mar 31, 2014
    Messages:
    11,679
    Location:
    UK
    My point was that Asus' firmware is not designed for users to log in and run their own scripts like they would on a desktop operating system. They are expected to use the GUI. That is why if you do SSH into it the environment is different from a typical Linux distro.
     
  9. dosborne

    dosborne Very Senior Member

    Joined:
    May 11, 2019
    Messages:
    575
    Location:
    /dev/null
    On any Linux based O/S, never count on /tmp files being persistent through a reboot. It is the whole premise behind having a temporary directory.

    Anything you want to persist should be configured to use another location, or worst case, some good ideas already posted.
     
  10. mr_radar

    mr_radar New Around Here

    Joined:
    Jul 19, 2019
    Messages:
    7
    Now I do understand what is going on and how to "fix" my problem.

    I was actually thinking of using the ln command (link).

    I am going to try and tell you what fits more considering my situation (ZSH+Oh-My-ZSH).

    Thank you all of you for quick and quality replies :)
     
  11. Turgut Kalfaoglu

    Turgut Kalfaoglu Occasional Visitor

    Joined:
    Apr 17, 2020
    Messages:
    46

    I would love to do this, but I have stock and no /jffs/scripts folder altogether.. Do you have any idea in which file this needs to go for stock? Many thanks.
     
  12. XIII

    XIII Very Senior Member

    Joined:
    Feb 27, 2014
    Messages:
    1,111
    Somebody told me to use this in /jffs/scripts/postmount:

    Code:
    [ -d "$1/home/root" ] && mount -o bind $1/home/root /home/root
    ln -nsf /home/root /home/$(nvram get http_username)
    Of course this requires Asuswrt-Merlin as well...
     
    Turgut Kalfaoglu likes this.
  13. Turgut Kalfaoglu

    Turgut Kalfaoglu Occasional Visitor

    Joined:
    Apr 17, 2020
    Messages:
    46
    Merlin install was a breeze - thank you for suggesting it.. And it does solve lots of the script problems.
     
  14. underdose

    underdose Regular Contributor

    Joined:
    Dec 13, 2017
    Messages:
    73
    Location:
    Istanbul
    Can you share the step-by-step instructions to overcome SSH login issue after adding that piece of code to post-mount? Asking for a noob friend of mine? :D
     
  15. Turgut Kalfaoglu

    Turgut Kalfaoglu Occasional Visitor

    Joined:
    Apr 17, 2020
    Messages:
    46
    Sorry what's the SSH login issue? You mean passwordless logins?
     
  16. underdose

    underdose Regular Contributor

    Joined:
    Dec 13, 2017
    Messages:
    73
    Location:
    Istanbul
    After adding that code to post-mount, I am not able to login to router via SSH, regardless of how I login (keys or username/password). It throws me out with the error "Permission denied (publickey)".
     
  17. Turgut Kalfaoglu

    Turgut Kalfaoglu Occasional Visitor

    Joined:
    Apr 17, 2020
    Messages:
    46
    I did the other piece of code.
    #! /bin/sh
    /bin/rm -Rf /tmp/home/root
    /bin/ln -s /tmp/mnt/2TBEXTERNAL/root /tmp/home/root

    That works for me, of course ensure that your drive name is replaced from above..
    I suggest you do a factory reset. Not being able to login is really crippling..
     
  18. XIII

    XIII Very Senior Member

    Joined:
    Feb 27, 2014
    Messages:
    1,111
    I also suffered from this when ownership/permissions were not right for files in /root.

    I fixed it back then by doing this:
    Code:
    chown -R admin /root/
    chmod -R go-rwx /root/
     
    underdose likes this.
  19. Turgut Kalfaoglu

    Turgut Kalfaoglu Occasional Visitor

    Joined:
    Apr 17, 2020
    Messages:
    46
    "admin" needs to be the name you gave to the router when you were first configuring it..
    If you chose "turgut" as the admin user (and you should :D) then it needs to be like this..
    # ls -ld /root
    lrwxrwxrwx 1 turgut root 13 Apr 5 18:55 root -> tmp/home/root
    # ls -l /tmp/home
    drwxrwxrwx 1 turgut root 25 Apr 19 18:10 root

    therefore it would need to be
    chown -R turgut:root /root
    chown -R turgut:root /tmp/home/root

    ...in that case.
     
    Last edited: Apr 20, 2020