If you have a router without a USB port, it is very likely that with more intense usage of your router, you will need more disk space.
You may want to test new software or config options without changing your original setup.
These 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. As soon as you reboot your router you will go back to your former state. The ability of saving your ram drive in a NFS share and restoring it back to your router is also given to you as an option.
Additionally, you can use your NFS share as your external drive without using any (z)ram drive.
How it works
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.
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 successful ram-root process, the router gets ready for your enjoyment.
If the swap file option over nfs share is selected, the script will make it ready for you, too.
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
Download the provided ‘ram-root.tar.gz’ file and extract it in the / directory: 'tar -C / -vzxf ram-root.tar.gz'
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
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.
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.
If you want to keep your new ram-root settings, it is hopefully possible to make a backup in 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.
If you need to reset your ram drive backup, enter this command. The command will bypass your backup file and do a fresh start.
You can enable the autorun option by entering '/etc/init.d/ram-root enable' to boot your router through the ram drive, if you make sure that everything works 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.
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 colored console prompt.