In other posts I talked about booting my OpenWRT routers off an external USB stick. In this post I’ll describe how to make the /var directory tree persistent across reboots.
On a standard OpenWRT system, /var is a link to /tmp. This simplifies setup, but it means that /var gets wiped out on each reboot, because /tmp is a tmpfs (in-memory). Why do I care? Well, when you reboot you lose:
- The package lists downloaded by opkg update
- DHCP leases that OpenWRT handed out
- Web pages that polipo, a caching proxy, has already loaded
- System-specific Bluetooth configuration, especially paired devices
And I care about all of these. Also, the tmpfs is kind of small, which makes web caching harder.
Unfortunately, the assumption that /var is /tmp has leaked into a number of places, so you’ll need to fix those. Start with the USB Storage howto to setup your external filesystem, and with my pivotroot scripts as well. Make these changes when you’re booted off internal flash – don’t make them to your live filesystem.
I’ll assume your external USB stick is mounted on /mnt.
- Undo the link.
cd /mnt; rm var; mkdir -p var/etc - Fix the bootup scripts. Exceprts are below, but you need to fix references in etc/init.d/syslog and etc/init.d/boot on your USB stick
diffs for etc/init.d/boot:
--- /etc/init.d/boot Sun May 10 21:09:45 2009
+++ boot Sat Jan 1 00:08:59 2000
@@ -38,10 +38,14 @@
config_load system
config_foreach system_config system
- mkdir -p /var/run
- mkdir -p /var/log
- mkdir -p /var/lock
- mkdir -p /var/state
+ mkdir -p /tmp/run
+ [ ! -f /var/run ] && ln -s /tmp/run /var
+ mkdir -p /tmp/log
+ [ ! -f /var/log ] && ln -s /tmp/log /var
+ mkdir -p /tmp/lock
+ [ ! -f /var/lock ] && ln -s /tmp/lock /var
+ mkdir -p /tmp/state
+ [ ! -f /var/state ] && ln -s /tmp/state /var
mkdir -p /tmp/.uci
chmod 0700 /tmp/.uci
touch /var/log/wtmp
diffs for etc/init.d/syslog:
--- /etc/init.d/syslog Fri Jun 12 08:16:26 2009
+++ syslog Sat Jan 1 00:09:22 2000
@@ -11,7 +11,7 @@
local cfg="$1"
local type file size ipaddr port IPCALC_CMD SYSLOG_CMD
local DEFAULT_type="circular"
- local DEFAULT_file="/var/log/messages"
+ local DEFAULT_file="/tmp/log/messages"
local DEFAULT_size=16
local DEFAULT_ipaddr=""
local DEFAULT_port=514