base-files: add option to make /var persistent
authorStijn Tintel <stijn@linux-ipv6.be>
Mon, 25 Feb 2019 13:05:07 +0000 (15:05 +0200)
committerStijn Tintel <stijn@linux-ipv6.be>
Sun, 22 Aug 2021 15:07:51 +0000 (18:07 +0300)
In OpenWrt, /var is symlinked to /tmp by default. This is done to reduce
the amount of writes to the flash chip, which often have not the
greatest durability. As a result, things like DHCP or UPnP lease files,
are not persistent across reboots.

Since OpenWrt can run on devices with more durable storage, it makes
sense to have an option for a persistent /var. Add an option to make
/var persistent. When enabled, /var will no longer be symlinked to /tmp,
but /var/run will be symlink to /tmp/run, as it should contains only
files that should not be kept during reboot. The option is off by
default, to maintain the current behaviour.

Signed-off-by: Stijn Tintel <stijn@linux-ipv6.be>
config/Config-images.in
package/base-files/Makefile

index 4a7f08824bd7b9c0ced50fa10282c8575cf5286a..92720fb84d506650267228ac631b474525aa93cb 100644 (file)
@@ -303,4 +303,12 @@ menu "Target Images"
                  it will be mounted by PARTUUID which makes the kernel find the
                  appropriate disk automatically.
 
                  it will be mounted by PARTUUID which makes the kernel find the
                  appropriate disk automatically.
 
+       config TARGET_ROOTFS_PERSIST_VAR
+               bool "Make /var persistent"
+               default n
+               help
+                 Do not symlink /var to /tmp, so that its content will persist
+                 across reboots. When enabled, /var/run will still be linked
+                 to /tmp/run.
+
 endmenu
 endmenu
index d67f551b9c5513181b8e2a9db8d83830b59c61fb..6da3df2b4ea775bb420d00c8955818c5a393360b 100644 (file)
@@ -181,8 +181,13 @@ define Package/base-files/install
        mkdir -p $(1)/www
        mkdir -p $(1)/root
        $(LN) /proc/mounts $(1)/etc/mtab
        mkdir -p $(1)/www
        mkdir -p $(1)/root
        $(LN) /proc/mounts $(1)/etc/mtab
+ifeq ($(CONFIG_TARGET_ROOTFS_PERSIST_VAR),n)
        rm -f $(1)/var
        $(LN) tmp $(1)/var
        rm -f $(1)/var
        $(LN) tmp $(1)/var
+else
+       mkdir -p $(1)/var
+       $(LN) /tmp/run $(1)/var/run
+endif
        mkdir -p $(1)/etc
        $(LN) /tmp/resolv.conf /tmp/TZ /tmp/localtime $(1)/etc/
 
        mkdir -p $(1)/etc
        $(LN) /tmp/resolv.conf /tmp/TZ /tmp/localtime $(1)/etc/