OpenWrt Forum Archive

Topic: extroot using ram drive with the backup&restore option over NFS share

The content of this topic has been archived on 27 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

Introduction

If you have a router without a USB port, just like my Netgear Wnr2000v1, it is likely that with more intense usage of your router, you will need more disk space. This can be achieved by creating a ram drive and using it as your new storage space. With this option, you can install and test new packages beyond your flash drive’s capacity to see how they work, without changing your original setup. Whenever you reboot your router you will go back to your former state. The ability of saving your ram drive and restoring it back to your router is also given to you as an option.


How does it work

The script simply creates a drive in the memory. This drive could be a ‘tmpfs’ or ‘zram’ . The zram drive basically compresses the data with the average 2:1 compression ratio. That means you will consume less memory for the drive. The cost is a little bit slower CPU because of the compression activity.

Then, it creates an ‘overlayfs’ and mount it as the new root. The new overlayfs based on the combined /rom (squashfs) and /overlay (jffs2) directories as the lowerdir and the ram drive as the upperdir. The lowerdir is read only, so your previous data is protected.

After the new root (extroot) process, the script restarts the network and gets ready for your enjoyment.

If the swap option over nfs share is selected, the script will make it ready for you, too.


Prerequisites


  • The latest Openwrt/Lede firmware with the kernel 4+

  • kmod-fs-nfs and nfsutils packages for  the backup option

  • swap-utils package for the  swap option

  • kmod-fs-ext4, e2fsprogs, kmod-zram packages for the zram drive option



Installation

Download link: https://drive.google.com/open?id=0B7XbZ … mJNcHBva28

Download the provided ‘ram-root.tar.gz’ file and extract it in the  / directory. After the extraction you should have a new directory in /etc named ‘ram-root’. You may need to enter ‘chmod +x /etc/ram-root/ram-root.sh’ command to make it executable.

Install the prerequisites considering your available flash drive space and config options. The script will check all of them whether they are installed and will do it automatically if not.

You should additionally make some changes in the ‘config’ file according to your needs before running the script.


How to use

/etc/ram-root/ram-root.sh or
/etc/init.d/ram-root start
Run the first command from your console to start the ram-root process for the first time. The script will copy itself to /etc/init.d. So, you can use the second command after the  first run.

/etc/init.d/ram-root stop
This is the command to stop the process and reboot the router to its previous state. If backup option is selected, a backup will be done before rebooting.

/etc/init.d/ram-root backup
If you want to keep your new ram-root settings, it is hopefully possible to make a backup on a ‘nfs’ share. The nfs server could be anywhere reachable by your router. If you select the backup option in the ‘config’ file, the script will make the backup for the first installation automatically. You can also backup any time you want by initiating the command from your console.

/etc/init.d/ram-root reset
If you need to reset your ram drive backup, enter  this command. The command will bypass your backup file and do a fresh start.


Notes

You can use your Luci startup option later to start and stop it. You can even enable the autorun option to boot your router through the ram drive, if you make sure that everything is working quite nicely.

The ram drive size should be entered accordingly. Start with a small amount and install your extra packages by checking the available size each time before the installation. If you are running out of space, simply increase the ram drive size in the  ‘config’ file and restart your router. Keeping the ram drive size just right, no more than required for your packages, helps the router to use the ram efficiently.

The previous state of the router is mounted under /old-root. You can simply switch to that directory and make changes.

Thanks

(Last edited by faruktezcan on 14 May 2017, 08:17)

very usefull, it's stability more than extroof on usb!

UPDATE :

The changes with this updated version are:

1- There is no kernel restriction now. It runs with older kernels, too.
2- A new config option CHROOT is added. You can find the info in the config file.
3- ZIP archive option is added.
4- New coloured console prompt.

Download link: https://drive.google.com/open?id=0B7XbZ … jcyRGNnLXM

(Last edited by faruktezcan on 15 Jun 2017, 07:27)

The discussion might have continued from here.