i think this is old setup and not working with new firmware. please update!
What's Flashfs-boot anyway
Flash-boot is the preferred method of saving configuration options between reboots.
The router has 4 Mb flash memory in which it stores its firmware. Flash is a non-volatile memory which, unlike ordinary RAM, does not lose its content when electrical power is no longer applied. The firmware is stored in flash on a squashfs partition which is read-only during normal operation. In adition to the squashfs- there is also a 64Kb flashfs partition stored in the flash memory. Using a simple tool the user can manage its configuration files in this partition.
Why not keep using the old BootCmd's
Flashfs-boot configuration provides the same functionality, is more powerfull, flexible and generally a better solution. Also the newer firmwares will stop using BootCmd's in the near future.
Background information
The idea is as follows: once you've made the changes to the ramfs system (/usr/local/ now also mapped to ramfs and it's strongly advised to put all your customizations in the directories below this point), you need to launch special command to store modified files permanently in the flash. During the next boot wl500g will extract these files for you. So, you can store whatever you need just like in real non-volatile file system. Consider using /usr/local/etc for files which is normally resides in /etc, /usr/local/init for "ASUS style" init scripts and /usr/local/sbin for executables files/scripts (it's now added to the default PATH).
Booting
Once the kernel is loaded it starts with /linuxrc boot script which is in fact acts like initrd init. This script checks for boot_dev device specified in the nvram for USB drive with root file system. If ext2 file system is recognized in the specified USB drive and it contains /sbin/init and /initrd directory then linuxrc execs init from this drive (just like linuxrc in initrds does). Otherwise flashed /sbin/init is being execed.
/sbin/init launches and reads the /etc/inittab file. This file specifies /init/boot as init script.
/init/boot in turn performs the following:
mounts procfs and ramfs and copies /ramfs to content to newely created ramfs
compares boot_local nvram variable content with current version number (now stored in the file named .version) and if they matches, then extracts "local" pseudo file system from flash. This measure was taken to prevent data prepared for one firmware to run after the firmware upgrade. You need to explicitly enable boot_local in this case (see below).
If /usr/local/init/pre-boot exists and is executable, then this file is launched.
If /usr/local/init/functions exists and is executables, then this file is launched, otherwise default startup script /init/functions script is launched just like in stock ASUS firmwares.
Once startup is finished /usr/local/init/post-boot script is executed, if it's executable.
/usr/local/etc/hosts is copied by rc.dnsmasq script to the bottom of the /etc/hosts file (obsoletes nvram etc_hosts).
/usr/local/etc/ethers is copied by rc.dnsmasq script to the bottom of the /etc/ethers file.
WARNING: Incorrect files can prevent your WL-500g from booting!
Double check your changes before committing. If your WL-500g failes to boot; flash it with 1.7.5.6-5 firmware (which does not utilize boot_local) and execute these commands:
nvram set boot_local
nvram commit
After that you can reflash your WL-500g back to the latest firmware and boot normal.
Saving your changes
Custom firmware contains script called flashfs (/sbin/flashfs). It's specifically designed for manipulating persistent files. This script should be launched with one of the following arguments:
status - displays current boot_local status
enable - enables boot_local
disable - disables boot_local
clear - deletes persistent files from your flash
load - (re)loads files from the flash
list - lists files stored in the flash
commit - commit persistent files to the flash.
save - prepares files from the file system to be committed to the flash.The contents of /usr/local/ is stored by default. You can specify other files to be stored by specifying them in the special file named /usr/local/.files (you need to create this file if it does not exist). Lines, which start with # are ignored in this file.
So, if you want to store your /etc/smb.conf, /etc/passwd and /etc/group then file should look like this:
/etc/smb.conf
/etc/passwd
/etc/groupNote 1: Do not try to store files which are read-only. In such case the boot-up script could fail leaving your WL-500g in an unpredictable state. When specifying entire directories be sure that directory you pointing to is not symlink (i.e. use /mnt/ramfs/local instead of /usr/local).
Note 2: Before committing the changes check the /tmp/flash.tar.gz file size. It should not exceed 65536 bytes (this is a flash space limitation). It's also a good idea to copy this file to your local PC as backup measure
Migrating BootCmd's to Flashfs-boot
So you're getting interested and want to use Flashfs-boot yourself? Migrating is a pretty simple process, but if you don't feel confident you can do this please don't. This is an advanced topic, you need to be absolutely sure what you are doing.
First of all: use a custom firmware from Oleg: v1.7.5.9 CR1 and up. Later official firmware from Asus will use this method by default.
The basic actions
This basic use of flashfs-boot is sufficient for most applications.
So, the idea is pretty simple: copy /init/functions script to /usr/local/init/ and do whatever you like with it. In fact firmware checks for /usr/local/init/functions existence and launch it instead of default /init/functions.
The commands looks like this:
mkdir -p /usr/local/init
cp /init/functions /usr/local/init/
flashfs save
flashfs commit
flashfs enable
Completely altering boot process
This is an even more advanced topic. The idea is to use kernel 2.4 mount bind option to replace the /init with /usr/local/init. To do this you will probably need to utilize /usr/local/init/pre-boot script. This will allow to do the things, which change some of the internal things, like a firewall.refresh which is called watchdog by ASUS and the path is hardcoded.
The initialization commands should look like this:
mkdir -p /usr/local/init
cp /init/* /usr/local/init/
echo "mount -o bind /usr/local/init /init" > /usr/local/init/pre-boot
chmod +x /usr/local/init/pre-boot
flashfs save
flashfs commit
flashfs enable
Re-enabling flashfs load after the firmware upgrade
Once you've upgraded/downgraded your firmware you could notice, that /usr/local becomes empty on boot. Don't worry, everything is here, but was not loaded to prevent errors.
If you feel it's ok to re-enable it, then just type the following:
flashfs enable
After that you need to reboot for changes to take effect.
Customizing the boot process
Now comes the fun part. Once the boot process has been altered you can use it to customize your router. A number of scripts in the /usr/local/init directory can be used for this purpose:
pre-boot
post-boot
post-firewall
Note 1: When migrating the BootCmd's these scripts don't exist yet. So you have to create them using the vi editor. The scripts also need to be executable, you can accomplish this by executing the chmod command like this:
chmod +x /usr/local/init/post-boot
Note 2: VI, however small and powerful, is a difficult editor at first. Try to find a decent manual on vi somewhere. The Linux Installation and Getting Started Guide is very useful for this and much more.
pre-boot
This script is executed before the functions script is executed and won't be used in most circumstances.
post-boot
- This is one of the most useful scripts. You can add your own commands here. Below is an example of a post-boot scipt
# lauch dropbear ssh daemon
/init/rc.sshd -C# mount other usb partitions
# launch samba daemons
/usr/sbin/nmbd -D
/usr/sbin/smbd -D# remount rootfs if booted from the usb drive
mount -o remount,rw,noatime /dev/scsi/host0/# launch giFT daemon
/mnt/usbfs/giftd.sh# launch a webserver on port 9005
busybox_httpd -p 9005 -h /mnt/usbfs/wwwroot
post-firewall
This script is called from within the firewall script and lets you add custom rules to the firewall. This scripts receives all the args passed to the original firewall script, i.e. $1/$2 are WAN_IF/WAN_IP, $3/$4 are LAN_IF/LAN_IP, $5/$6 are $DMZ_IF/$DMZ_IP.
Below is an example of a post-firewall script:
#enable wondershaper (QoS)
/init/wshaper start "$1" 1000 500#block certain hosts (doesn't work for me though)
#iptables -A INPUT -s 204.1.226.224 -j DROP
#iptables -A INPUT -s 204.1.226.225 -j DROP# allow ssh clients from WAN to connect to port 22
iptables -A INPUT -p tcp --dport 22 --syn -j ACCEPT# allow webserver requests to port 9000 (busybox_httpd)
iptables -A INPUT -p tcp --dport 9000 --syn -j ACCEPT
I think in the 1.8.x.x releases this is changed a bit. because of the drop at the end. Use something like an Insert instead of an Add to prevent the new rules to come after the drop so as an example for SSH
iptables -I INPUT 3 -p tcp --dport 22 --syn -j ACCEPT
