Difference between revisions of "Entware Installation on DD-WRT"
m |
|||
(2 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
This is a quick bullet list of steps to install Entware on DD-WRT | ls This is a quick bullet list of steps to install Entware on DD-WRT | ||
===History=== | ===History=== | ||
Line 8: | Line 8: | ||
===Hardware=== | ===Hardware=== | ||
Hardware: Buffalo WZR-600DHP with 128 MB of RAM, 32 MB of non-volatile Flash Memory, gigabit switch, and a USB port with a MIPS based CPU and Atheros Wireless Chipset | My Hardware: Buffalo WZR-600DHP with 128 MB of RAM, 32 MB of non-volatile Flash Memory, gigabit switch, and a USB port with a MIPS based CPU and Atheros Wireless Chipset and a Linksys WRT3200ACM with an unbelievable amount of RAM, NVRAM, a 2 core CPU, etc. (yup, quite a range there) | ||
These installation instructions should work for any hardware that can be flashed with DD-WRT and has a USB Port. | These installation instructions should work for any hardware that can be flashed with DD-WRT and has a USB Port. | ||
Line 88: | Line 88: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
=== What about Virtual RAM (AKA, Swap, PageFile, etc.)? === | ===What about Virtual RAM (AKA, Swap, PageFile, etc.)?=== | ||
There's usually a limited amount of RAM available in a small router, so if you're using it for any intense stuff like OpenVPN and SOCKS, it will use the RAM up fast. If it gets used up the router generally just reboots, and the cycle starts again. | There's usually a limited amount of RAM available in a small router, so if you're using it for any intense stuff like OpenVPN and SOCKS, it will use the RAM up fast. If it gets used up the router generally just reboots, and the cycle starts again. | ||
Latest revision as of 12:22, 22 September 2020
ls This is a quick bullet list of steps to install Entware on DD-WRT
History
Entware's origins can be traced back to Optware and the Linksys NSLU2 NAS
Introduction
I've seen a bunch of different tutorials on installing Entware, many quite good. The intent of this guide is to provide a quick step by step set of instructions. It is assumed that readers are experienced users as granular detailed instructions are not provided (but you can Google them if you don't know how to do it.
Hardware
My Hardware: Buffalo WZR-600DHP with 128 MB of RAM, 32 MB of non-volatile Flash Memory, gigabit switch, and a USB port with a MIPS based CPU and Atheros Wireless Chipset and a Linksys WRT3200ACM with an unbelievable amount of RAM, NVRAM, a 2 core CPU, etc. (yup, quite a range there)
These installation instructions should work for any hardware that can be flashed with DD-WRT and has a USB Port.
Instructions
- Flash the router with DD-WRT firmware (see, I wasn't kidding about not providing granular instructions), make sure it has internet access and that you have command line access via telnet or SSH.
- Plug in a USB Flash Drive or USB mechanical disk drive or SSD. I prefer a Flash Drive. I also prefer formatting the drive with two primary partitions, a small one for the Entware OS and a large one for general file storage. Formatting with NTFS means that the drive can be plugged into a Windows computer to retrieve anything stored there (Windows has no built in method of reading EXT2 partitions). The other smaller partition I prefer to format as an EXT2 partition. It's simple, fast, and EXT3 doesn't provide any advantages in this instance. The Entware partition can be small, but I like to think about future expansion so on a large disk or flash drive I allocate 8 GB to it. And remember, you can't partition and format with any built in DD-WRT commands. Most websites that note that end the conversation there, which I find depressing as there is no satisfactory conclusion. I discovered several tutorials about a minimal size version of Entware that can be installed on a JFFS partition (if your router supports that) which will then in turn allow you to download the tools needed to partition and format. Still looking for where I found it as of the writing of this, but haven't located it. Try a Google search with: entware minimal install jffs.
Special Note in regards to the above bullet point: Make sure Entware is installed on an EXT2 partition. Installing it on an NTFS partition doesn't allow things to work correctly (mount points, etc.)
- To make things easier, make sure the stock DD-WRT firmware has the drive mounted as /opt via the GUI interface. Quick Tip: If you do as I do with the multiple partition setup, put the EXT2 partition first and the NTFS partition last. The reason is that DD-WRT only mounts the first partition via the GUI interface. This is important, which is why I wrote it twice.
- Download the Entware installer (use WGET or share out the /opt directory to a Windows computer and copy it there) from their repository for the hardware your router is based on (look for a file named "generic.sh" in a sub-directory named "installer": http://bin.entware.net/
- Change the permissions on the installation script file: chmod 777 generic.sh (you could set it something to less permissive, but typing 777 is faster and the script can be deleted after Entware Installation)
- Run the script: ./generic.sh (it should download all of the necessary files and install it in the /opt directory (which is your disk or flash drive). Be patient as it might take a couple of minutes, depending on your router's CPU speed, to unpack everything and install it.
- And now it works. NOT! One of the final output lines of the installation script says something like "Congratulations...", but before that is are a couple of lines about changing or adding to the $PATH variable. If you check the $PATH variable after installation it will show that the "/opt paths" where Entware is installed are in the path. But there's a problem. They're at the end of the path which means any binaries or programs that are included with the DD-WRT firmware will be used before the Entware versions. The result is that stuff just doesn't work from the command line properly. Even changing the $PATH variable with: export PATH=/opt/bin:/opt/sbin:/opt/usr/sbin:/opt/usr/bin will not help the situation after a reboot. Simply setting the $PATH variable in a startup script via the GUI won't help either in terms of issuing Entware commands at the command line. WTF!? It has to do with the "profile" variable (DD-WRT default path: /etc/profile).
- Solution for the above mentioned problem? Create a file in the /opt Directory named ModifiedProfile (or any other name you want) using VI (and copy and paste the below code) or copy an existing script file, then edit the contents (erase original contents and paste the below code) and save it. I share the /opt directory, access it via Windows, and edit it with TextPad. But do NOT create a script file via a Windows share (see Other Thoughts below), because it won't work with BASH.
export PATH=/opt/bin:/opt/sbin:/opt/usr/sbin:/opt/usr/bin:/bin:/usr/bin:/sbin:/usr/sbin:/jffs/sbin:/jffs/bin:/jffs/usr/sbin:/jffs/usr/bin:/mmc/sbin:/mmc/bin:/mmc/usr/sbin:/mmc/usr/bin
export LD_LIBRARY_PATH=/lib:/usr/lib:/jffs/lib:/jffs/usr/lib:/jffs/usr/local/lib:/mmc/lib:/mmc/usr/lib:/opt/lib:/opt/usr/lib
export PS1='\u@\h:\w\$ '
reboot() {
for f in /opt/etc/init.d/S*
do
[ -x "$f" ] && "$f" stop
done
echo "#!/bin/sh" > /tmp/.rc_shutdown
echo "$(nvram get rc_shutdown)" >> /tmp/.rc_shutdown
if [ -f /tmp/.rc_shutdown ]; then
chmod +x /tmp/.rc_shutdown
/tmp/.rc_shutdown
fi
/sbin/reboot
}
service() {
[ -f "/opt/etc/init.d/$1" ] || {
echo "Typing the SERVICE command with no additional parameters displays a list of available services;"
ls "/opt/etc/init.d"
return 1
}
/opt/etc/init.d/$@
}
The above script does three things. The top several lines set environment variables. The reboot and service subroutines can be used as commands at the command prompt. The reboot subroutine gracefully shuts down any Entware services and the Service subroutine controls services installed by Entware
- Next, save the following as a StartUp Script
mount -o bind /opt/ModifiedProfile /etc/profile
sleep 1
/opt/etc/init.d/rc.unslung start
I know I said I wouldn't explain things, but it needs to be said for the above short script. The mount command effectively replaces the DD-WRT version of the profile file (this is the BASH login script for users). The rc.unslung start command is what the Entware installation script said to add to the Startup Script. RC.UNSLUNG starts all the installed services for Entware.
BusyBox
- The first useful item to install is an updated version of BusyBox (Google it). Use the below commandsOne thing to keep in mind is that when a user logs in, the DD-WRT version of BusyBox is what starts things off, so it will report a different version than what Entware installs and is actively running. Just type: busybox That will display the version of BusyBox currently running.
opkg update opkg install busybox
OPKG Note
Unlike yum, the OPKG command doesn't seem to allow one to install packages by using a wildcard. For instance, if one wanted to install all the PERL packages, this won't work: opkg install perl* But someone wrote this cool little script;
opkg list | grep WhatEverNamePackagesBeginWith| awk '{print $1}' | xargs opkg install
Other Really Useful Basic Command Additions
Sometimes it's nice to type DIR instead of using the LS command, so install coreutils-dir. For an enhanced version of lsmod, kmod. For a text editor that makes way more sense than VI, nano. And for an enhanced version of TOP that's essentially equivalent to a text version of Task Manager in Windows, htop.
opkg install coreutils-dir
opkg install kmod
opkg install nano
opkg install htop
Remember, DD-WRT is designed to fit into limited storage space on routers. The key word here is 'limited'. But with a USB Drive, space isn't so much of an issue, so why not install the full version of all utilities that come with BusyBox and DD-WRT?
opkg list | grep coreutils- | awk '{print $1}' | xargs opkg install
What about Virtual RAM (AKA, Swap, PageFile, etc.)?
There's usually a limited amount of RAM available in a small router, so if you're using it for any intense stuff like OpenVPN and SOCKS, it will use the RAM up fast. If it gets used up the router generally just reboots, and the cycle starts again.
The starting point for creating a swap file is the following command which creates a file filled with "zeros" that is 64K (65536 bytes) big, 1024 bytes at a time;
dd if=/dev/zero of=/tmp/mnt/sda_part2/SwapFile bs=1024 count=65536
Next, install the necessary software;
opkg install swap-utils
The following command "formats" / prepares the RAW / Blank file as a swap file with the label SwapFile and the 'swap program' recommends the permissions be changed too;
mkswap /tmp/mnt/sda_part2/SwapFile --label SwapFile
chmod 600 /tmp/mnt/sda_part2/SwapFile
And finally, add the following command to your Startup Script (use the swapoff command if you want to turn the swap file off);
/tmp/mnt/sda_part2/sbin/swapon /tmp/mnt/sda_part2/SwapFile
All of the above paths are the ones in my environment, adjust them to suit yours.
To check the swap file, HTOP displays used / available swap file space. Oh, and don't be misled by HTOP indicating the swap file is "OK" (oh kay). It's actually displaying 0K (zero kay). So if you see OK displayed by HTOP, the swap file isn't working.
Note, this creates a swap file, not a swap partition. There are other tutorials on that (Google it). In terms of speed, I haven't read anything about there being an advantage to one or the other on a flash drive. On a mechanical disk drive, if a swap partition is created at the beginning / inner part of the disk, it will perform faster (although there are some arguments that point out the middle of the disk is the best compromise). However, more than likely speed will be limited by the USB bus, flash, or disk drive speed.
OpenWRT Choice
Of course you could always install OpenWRT instead of DD-WRT and none of the above is necessary. But that opens a whole new can of worms with different problems. For instance, installing the latest (as of 1.2020) version of OpenWRT on a Linksys WRT3200ACM router, which is at the very top end of DD-WRT / OpenWRT hardware, there is no facility within the GUI as it is initially installed to mount, share, or do anything with a USB or eSATA drive. All of that functionality, which has to be added to OpenWRT via a command line is available from DD-WRT right out of the box. Once you know what you're doing, both firmware choices are equally configurable, in an equally easy fashion, in their own unique ways, each with their own advantages and disadvantages. Apples and Oranges. Your choice.
Other Thoughts
If you're like me and working from Windows and also like to take advantage of all those nice little GUI perks like network file sharing (SAMBA in the linux) world, there's one thing (well, lots, but just pointing out one here) to watch out for. Do not create a script file in Windows via a shared network directory on the router and expect it to run as a bash login script. It won't work. Also there are differences in text files including 'carriage return / line feed' in Windows and just 'line feed' in Linux among several others that will prevent the Linux OS from "reading" the script file properly, so don't edit in notepad. Once the file is created in Linux (or copied from another Linux OS) editors like TextPad work great.
To create a zero byte file with DD-WRT's built in VI command, do the following: type vi WhatEverNameOfFile to start the editor, within VI type :x (that's a colon followed by an x), then press enter. That file can be edited via a shared network directory with a program like TextPad.
Even though it never seems to be explicitly stated, NVRAM and JFFS sizes are determined by the hardware's capabilities and set in the firmware. Both NVRAM (where startup scripts and commands are stored) and JFFS content are stored on the flash chips inside the router. But what if I don't want to use JFFS and want to increase available NVRAM. I haven't found a way to decrease the amount of flash memory allocated or reserved for to / for JFFS (even if it isn't utilized) and reallocate it to NVRAM. Both are stored on the flash chips in the router, so this is completely valid thought from a technical perspective. However, because the size of each storage area seems to be hard coded in the firmware (which I sort of confirmed by researching and finding anecdotal comments that implied these limits are set in firmware, but nothing explicit), one is SOL if one wants to change the settings. For my WZR-600DHP router, there is 64 KB of NVRAM and just under 20 MB of JFFS storage space available. 64K of storage is all of the RAM my Commodore 64K had. It seemed like so much then, and thinking about it now, they really made efficient use of that small amount of RAM (large in those days). Ah, the good 'ole days, but I digress.
Another small item to watch out for (at least on the firmware version of my router) is the way the GUI displays information about the mounted drives. If there is more than one partition on a drive, by default DD-WRT will only mount one of them (the first one). But the way the GUI displays the information is a bit misleading. It shows the information about both partitions, then notes the mount point (/mnt, /opt, etc.) at the end. This might lead one to believe the second, third or whatever last partition listed is the one mounted. Nope. It's the first one that's mounted. No line breaks or listing the mounted partition directly after the displayed information about that specific partition, there's nothing to indicate the last partition isn't the one mounted.